Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
Sintaxis del creador de acciones de Redux
function addTodoWithDispatch(text) { const action = { type: ADD_TODO, text } dispatch(action) }

http://redux.js.org/docs/basics/Actions.html#action-creators

Vi el código anterior de la documentación de redux. Lo que no entiendo es el text en la action . No parece un objeto JavaScript válido o una sintaxis de matriz. ¿Es una nueva sintaxis de ES6? Gracias.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Es solo una nueva sintaxis ES6 , que simplifica la creación de propiedades en la sintaxis literal

En definitiva, si el nombre es el mismo que el inmueble, solo tienes que escribirlo una vez

Así que esto sería exactamente lo mismo :)

 function addTodoWithDispatch(text) { const action = { type: ADD_TODO, text: text } dispatch(action) }
over 4 years ago · Santiago Trujillo Report

0

En el código anterior

 function addTodoWithDispatch(text) { const action = { type: ADD_TODO, text } dispatch(action) }

aquí text es un ejemplo de notación abreviada literal de objeto. ES6 le brinda un atajo para definir propiedades en un objeto cuyo valor es igual a otra variable con la misma clave.

Como se ha dicho, esto es solo una forma abreviada de escribir

 const action = { type: ADD_TODO, text: text } dispatch(action)

Echa un vistazo a este blog

over 4 years ago · Santiago Trujillo Report

0

Si mira la página siguiente en el documento http://redux.js.org/docs/basics/Reducers.html

 function todoApp(state = initialState, action) { switch (action.type) { case SET_VISIBILITY_FILTER: return Object.assign({}, state, { visibilityFilter: action.filter }) case ADD_TODO: return Object.assign({}, state, { todos: [ ...state.todos, { text: action.text, completed: false } ] }) case TOGGLE_TODO: return Object.assign({}, state, { todos: state.todos.map((todo, index) => { if(index === action.index) { return Object.assign({}, todo, { completed: !todo.completed }) } return todo }) }) default: return state } }

Está esperando el texto del nombre de la propiedad. Como mencionó @Icepickle, es un formato válido, pero también puede cambiar al siguiente formato:

 function addTodoWithDispatch(text) { const action = { type: ADD_TODO, text:text } dispatch(action) }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!