Model classes are now EventEmitters
Model classes are now EventEmitter instances which emit service events when received (technically, EventEmitter methods are mixed onto each Model class). All FeathersJS events are supported. Oh, and one more thing: it works with feathers-rest
(you won't receive socket events, but you can listen for when instances are created in other parts of the app.)
Here’s an example of how to use it in a component:
export default {
created() {
this.$FeathersVuex.api.Todo.on(‘created’, this.handleTodoCreated)
},
destroyed() {
this.$FeathersVuex.api.Todo.off(‘created’, this.handleTodoCreated)
},
methods: {
handleTodoCreated(todo) {
console.log(todo)
}
}
}
Since they have all of the EventEmitter methods, Model classes can be used as a data-layer Event Bus. You can even use custom methods:
const { Todo } = this.$FeathersVuex.api
Todo.on('custom-event', data => {
console.log(data) // { test: true }
})
Todo.emit('custom-event', { test: true })
See code changes in this commit: 5224d5d