Skip to content
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

Weird / destructive behaviour using mapActions service find between components #21

Closed
dortamiguel opened this issue Jun 9, 2017 · 6 comments

Comments

@dortamiguel
Copy link

dortamiguel commented Jun 9, 2017

I'm having a weird behaviour using find, this is how I'm using it:

I'm using feather-vuex 0.4.2, I also tried 0.3.1 and I get the same result.

First component

On the first component I do a find without a query, it returns all the results and store them on vuex.

methods: {
	...mapActions('profiles', { findProfiles: 'find' }),

	fetch() {
		this.findProfiles({})
	},
},

created() {
	this.fetch()
},

Screenshot of Vuex state after find:
screen shot 2017-06-09 at 10 40 13

Second component

Now I do a get and after it the results fetched with the find are still in the store. Everything is fine here.

methods: {
	...mapActions('profiles', { getProfile: 'get' }),

	fetch() {
		this.getProfile(this.user.profile)
	},
},

created() {
	this.fetch()
},

screen shot 2017-06-09 at 11 06 24

Third component

Now I do other find but with a custom query, I just want to find an element, the query works fine but it destroy the results of the first find :(

methods: {
	...mapActions('profiles', { findProfile: 'find' }),

	fetch() {
		this.findProfile({
			query: { slug: this.$route.params.slug },
		})
	},
},

created() {
	this.fetch()
},

screen shot 2017-06-09 at 11 10 29

Is this a bug or the expected behaviour? I'm missing something?

@victorm95
Copy link

This is the expected behavior, the store relfect the result of the actions, if your action only get 1 object your store will have 1 object.
You can use the getter, but the getters only search in the store, not in the server. So you can use the action find without query for get all the objects and then use the getter find with query for filter the result.
Or use feathers directly, that way the store doesn't change.

You can see how combine the action and getter in the feathers chat vuex.

Sorry for my English.

@dortamiguel
Copy link
Author

dortamiguel commented Jun 12, 2017

Okey, but if I already downloaded some info and I know that I don't need to fetch it again from the server why I have to do it again?

Whit the correct query to the store I can have always just the data that I need and use vuex as a database with just the info that I need on the front.

Even this "database" can be cached on the client.

@victorm95
Copy link

Yeah, if you know that the action find was call before, just use the getters.
But if you need paginate the results you have to use the actions.

@marshallswain
Copy link
Member

Sorry, I've been gone for a few days. This behavior could be expected with the 0.4 version of the plugin, but previous versions do not handle any removing of records, as far as I remember. Each query to find should be completely independent, and their results should only add to the store. @ellipticaldoor have you been able to set some breakpoints to see where the results are getting removed in the 0.3 version? I would think that downgrading would have fixed the issue.

@dortamiguel
Copy link
Author

I tried again version 0.3.0 and 0.3.1 and now all the data persists :D

Probably I didn't removed correctly the 0.4.2.

I still have to learn how to use breakpoints...

@marshallswain
Copy link
Member

Thanks for reporting back. It will take me some time to figure out a solution.

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

3 participants