Code-Pop / watch-us-build-trello

271 stars 180 forks source link

best practice for passing arguments to state getter ? #15

Open hafdon opened 3 years ago

hafdon commented 3 years ago

I think these two syntaxes are equivalent, but is one of them best practice? (lesson code is at the bottom)

// getters
getTask: state =>(id) => {
    for (const column of state.board.columns) {
          for (const task of column.tasks) {
            if (task.id === id) {
              return task
            }
          }
      }
}

/src/store.js

  ...
  state: {
    board
  },
  getters: { // <-- Add a getter
    getTask (state) {
      return (id) => {
        for (const column of state.board.columns) {
          for (const task of column.tasks) {
            if (task.id === id) {
              return task
            }
          }
        }
      }
    }
  },
  mutations: {}
})