Closed barata0 closed 4 years ago
@barata0 are you saying you want to selectively use created
or updated
methods, and not listen to others?
Oh. never mind, I get what you're saying. We would probably leave enableEvents
as a boolean and add an events
option. Rather than allowing a boolean OR a function, we'd probably just go with a function.
events: {
created: item => item.isWorthKeeping,
updated: () => false,
patched: item => item.hasPatchedAttribute && item.isWorthKeeping,
removed: item => item // The default value
}
Actually, I feel like it would be better to call it enabledEvents
.
I like it. Feel free to make a PR to the typescript branch.
Shouldn't be better to call eventsFilter for the functions? Is there is no function defined it assumes true.
So you can enable and disable the vuex update events at all with the current option enableEvents and can implement a filter through
eventsFilter: {
created: item => item.isWorthKeeping,
updated: () => false,
patched: item => item.hasPatchedAttribute && item.isWorthKeeping,
}
In the example the delete method is not implemented so it will delete any instance that exists on vuex store after receiving the event.
I'll try to make a PR on this.
handleEvents: {
created (data, { model, models }) {
// perform some side effects if you want, then
// You want the record added to the store?
return true
// You don't want the record added to the store?
return false
}
}
If we want the record removed from the store, we can use the model
arg and manually do model.removeFromStore(id)
. I don't think Model.removeFromStore()
exists, yet, so I'll need to create it.
Actually remove
should definitely remove the item from the store if it returns true. So that will be different than the rest. I now see what you were talking about.
This has been released in feathers-vuex@3.1.0
. Thanks @barata0 for the great idea!
Read more about it in the docs: https://vuex.feathersjs.com/service-plugin.html#service-events
Awesome!
Hi,
Feathers server has the option to filter channels dynamically. FeathersVuex should have this option too, instead of forcing the api to persist the filter rules and the client to "ask" for those events, the client could discard the undesired events.
what about allow the
enableEvents
prop receive a boolean or a map?The function returns a boolean indicating dinamically if the client want to store that record locally.