Where to put parameterised mapGetters (in computed or methods of component)

Viewed 644

In vuex, I have this:

getByLessonId: state => _lessonId => {
  return state.entities.filter(e => e.lesson.id === _lessonId);
},

In component:

// using as a method...
...mapGetters("assignment", { getAssignmentsByLessonId: "getByLessonId" }),

Later in the code, since the mapping returns the function, I need to call it like this?

// load this lessons assignments...
this.assignments = this.getAssignmentsByLessonId()(this.id);

// this is what i started with
// this.$store.getters["assignment/getByLessonId"](this.id)

It works, just not sure if there is a better way to do this? Or should I put mapGetters in the computed properties of the component?

1 Answers

Better put mapGetters (as long as mapState) in a computed section of a component. This is a recommended way to use several getters or props of a state because you have one place only to control getters and props in a component.

Related