Skip to content

Getters that only update when values have changed #83

Open
@Vic-Dev

Description

@Vic-Dev

Currently, if I set a getter for the route name and then use that getter in a computed value in a component, it will be updated whenever the route changes even if the route name property is the same. Eg, for the getter:

currentRouteName: state => state.route.name

Then in a component:

computed: {
    ...mapGetters({
      currentRouteName: 'currentRouteName'
    }),
    routeName() {
      return this.currentRouteName
    }

The reason this is an issue, is that I have a searchbar component I'm dynamically hooking up to a different search store (using vuex-connect) depending on the route name, which triggers the searchbar to be mounted. Currently it is re-mounted whenever the route changes (eg, adding a query param) even though the route name string has not changed. I could fix this by using a watcher and only updating the searchbar when the currentRouteName to is different from the from, but that means that everywhere I want to use this getter I have to use the watcher to check the difference when it seems like it should only reactively update when it actually gets a different string.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions