Skip to content

Does Vuex work with new Map(), as in key/value map lists? #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Sarke opened this issue Nov 3, 2016 · 3 comments
Closed

Does Vuex work with new Map(), as in key/value map lists? #439

Sarke opened this issue Nov 3, 2016 · 3 comments

Comments

@Sarke
Copy link

Sarke commented Nov 3, 2016

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

My state for a module looks like this:

const state = {
	loaded: false,
	items: new Map(),
}

I'm having some issues when updating an item in the list through a mutation, that it doesn't propagate through to the Vue component. In the component I have:

computed: {
	item() {
		return this.$store.state.module.items.get(this.pk)
	},
},

Am I using this wrong, or does Vuex not support Map()? If it's not supported, where would be a good place to put a load(pk) method?

@simplesmiler
Copy link
Member

simplesmiler commented Nov 3, 2016

Hi, thanks for your interest in the project.

The problem is twofold:

  1. Vue reactivity system does not (yet) support Map, Set and their weak counterparts. There's a discussion on the topic: Support more collection data types in v-for vue#2410
  2. Store data should be serializable, and there is no standard way to serialize Map and Set into JSON.

@Yamakaky
Copy link
Contributor

Is there a way to use Map and Set with vue/vuex and some boilerplate, or is it just not supported at all?

@raghuvarbisht
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants