Closed mhsimkin closed 8 years ago
Ok so the basis for the event classes is similar to how the DOM has events as well as how the original Flash and Dart event dispatchers work.
Except for EventSimple, which doesn't require a string registry of events. It simply IS and event. And much like an Observer style object, can 'dispatch' a signal.
Example 1:
var es = new EventSimple();
ex.add((x,y,z)=>{/* some stuff */});
ex.add((x,y,z)=>{/* some stuff */});
/* time goes by */
ex.dispatch(x,y,z);
/* All done? */
ex.dispose();
Example 2:
const EVENT_A = "eventNameA", EVENT_B = "eventNameB";
var ed = new EventDispatcherBase();
ed.addEventListener(EVENT_A,()=>{/* do something */});
ed.addEventListener(EVENT_B,()=>{/* do something */});
/* time goes by */
ed.dispatch(EVENT_A);
ed.dispatch(EVENT_B);
/* All done? */
ed.dispose();
The obvious alternatives are Observable classes where you 'subscribe' and 'unsubscribe': https://github.com/electricessence/TypeScript.NET/tree/master/source/System/Observable
@mhsimkin: Lemme know if that answered your question.
Thank you. This is very helpful.
Can you please provide a sample on how to use the event classes? There are no tests in the repo that can provide a reference point.
Thanks
marc