I am having a bit hard time understanding the following JS:
const store = new Vuex.Store({
state: {
todos: [
{ id: 1, text: '...', done: true },
{ id: 2, text: '...', done: false }
]
},
getters: {
// ...
getTodoById: (state) => (id) => {
return state.todos.find(todo => todo.id === id)
}
}
})
store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }
These two code snippets are taken from official Vuex Documentation on Method Style Access for Getters.
Now what I dont understand is, how those the second part of code output the value in the comment? Maybe I miss-understood JS functions?
I believe the output would be:
(id) => {
return state.todos.find(todo => todo.id === id)
}
So actually the second functions that is being returned, because in the call that they used, I do not see two '()()'
nor do I understand from where does the function receive the 'state'
variable.
I would kindly like to ask for an explanation, whether I miss-understood something in JS, or is this something Vuex specific?