How do we distinguish firing events that bubble from those that don't (or can't)
matthew-andrews opened this issue · 2 comments
There are some events that can't bubble, eg:
- setup
- beforesetup
- initialize
- and so on
But custom fruit machine module events should bubble through the fruit machine structure by default.
The way this works is 0.3 is by passing in an object with a propagate
option set to either true
or false
.
this.fire('render', { propagate: false });
@wilsonpage and @samgiles prefer:
this.fire('buttonclick');
this.fireStatic('render');
As most use cases of fireStatic
are internal anyway.
I think I like:
this.emit('buttonclick');
this.publish('render'); // or fire('render'); is ok too
This keeps public functions of the FruitMachine API consistently single worded (perhaps fireStatic
doesn't need to be public?). However this has the disadvantage of requiring all existing use of fire
within our fruit to be change to be emit
's.
This issue can probably closed already because in balance fireStatic
/ fire
is probably the best option.
After much thought, I prefer the current version this.fire('render', { propagate: false });
. Purely because:
- It keeps the API simple i.e. One less method
- The decision on whether event propagation should occur is delegated to the event object (or at least imo, it should be)
- Seems more flexible
An aside: emit
to me seems more like a synonym of the proposed fireStatic
. Publish is something that goes to everything, and, for example 'light emitted is blocked by the first opaque thing it encounters', therefore emit
is more like fireStatic
, publish
more like fire
.
On reflection fireStatic
/fire
or the current implementation seem like the best.