Events
If you're using React, you don't need to read this part.
If you're not using React and you want to create an adapter to your view/component system, you should read this.
Change events
Change events are used to to propagate a render on the view/component tree. They are triggered after an action call.
const startGame = createAction(game => game.update({ started: true }), [Game]);
Game.emitter.changed(() => console.log('Game entries changed !'));
Player.emitter.changed(() => console.log('Player entries changed !'));
startGame(Game.objects.get());
// Game entries changed !
// Player entries changed !
All models defined in the actions will propagate a change event after the action has been called.
Funnels
To receive only one event after an action call, a funnel should be created.
import { createChangesFunnelEmitter } from 'dispersive/emitter';
const funnel = createChangesFunnelEmitter([Game, Player];
const game = Game.objects.get();
funnel.changed(() => console.log('Game or Player entries changed !'));
startGame(game);
// Game or Player entries changed !