intertalk v0.0.21
InterTalk
Table of Contents generated with DocToc
InterTalk
API
emit_on_event: ( element, event_name, note_name ) ->
(only in browser): given a DOMelement
, a DOMevent_name
and anote
name, when a matching event is triggered on the element, emit a note with$key: note_name
and$value: event
- when
emit_on_event
is called with the arguments( event_name, note_name )
then the event listener will be attached todocument
:IT.emit_on_event div_1, 'click', 'bar'
will be triggered when clicking on thediv_1
element only, butIT.emit_on_event 'click', 'bar'
will be triggered by any click anywhere within the browser document window.
- when
unsubscribe: ( listener ) ->
: unsubscribelistener
from all notifications.unsubscribe: ( $key, listener ) ->
: unsubscribelistener
from notifications matching$key
.
Is Done
- + allow to use
Map
(or other suitable replacement) instead ofWeakMap
whereSymbol
s are not allowed as keys (true for Firefox at least up to v124.0.1) - + fix some names:
- class
Async_events
(->Intertalk
?) - class
AE_Event
(->Note
) - instance
ae_event
(->note
?) - class
AE_Event_results
(->Results
) - datom key
ae_event-results
($results
)
- class
- + export singular instance of
Intertalk
, provide other names as properties (?) - + remove ability to discover suitably named note listeners on objects as it only leads to complications
- + reconstruct listener registration:
- in a
Map
(needed for symbol$key
s), storeWeakSet
s as values, - likewise, make
Intertalk#any_listeners
aWeakMap
- may later want to cache association between
$key
s andlistener
s to avoid to re-construct sets
- in a
- + implement
on_any()
or similar to catch all emittednote
s - + implement
off()
to unsubscribe a listener - + implement signature
off $key, listener
to unsubscribe a listener only from matching notes - + implement
on_unhandled()
or similar to catch allnote
s that were emitted but not listened to
To Do
- – event namespacing
- – in
emit_on_event()
, allow to transform / add attributes to outgoingnote
– implement
once()
for listeners that should only receive a singlenote
(this requires implementingoff()
) implement returning a 'command' instance that may contain the listener's results, if any, but also controls how to deal with the current note and whether or not to unsubscribe the listener. Alternatively, either (1) pass in a second argument (dubbedcontrol
orctrl
) that contains methods to unsubscribe, cancel &c, or (2) describe how to achieve this by using theintertalk
instance's methodsoff: () ->
: unsubscribe this listener from this$key
off_all: () ->
: unsubscribe this listener from all keys, includingany
and fallback subscriptions
– implement note cancellation / note rewrite