dispatch
Dispatch event and key binding handlers.
obj.dispatch(event, [args])
Dispatches registered addEventListener and @can.onKeyValue value binding handlers.
The following shows dispatching the property
event and
keyValue
handlers:
var mixinMapBindings = require("can-event-queue/map/map");
var obj = mixinMapBindings({});
obj.addEventListener("property", function(event, newVal){
event.type //-> "property"
newVal //-> 5
});
canReflect.onKeyValue("property", function(newVal){
newVal //-> 5
})
obj.dispatch("property", [5]);
NOTE: Event handlers have an additional
event
argument.
Parameters
- event
{String|Object}
:The event to dispatch. If a string is passed, it will be used as the
type
of the event that will be dispatched and dispatch matching @can.onKeyValue bindings:obs.dispatch("key")
If
event
is an object, it MUST have atype
property. The If a string is passed, it will be used as thetype
of the event that will be dispatched and dispatch matching @can.onKeyValue bindings:obs.dispatch({type: "key"})
The
event
object can also have the following properties and values:- reasonLog
{Array}
- The reason this event happened. This will be passed to enqueueByQueue for debugging purposes. - makeMeta
{function}
- Details about the handler being called. This will be passed to enqueueByQueue for debugging purposes. - patches
{Array<Patch>}
- The patch objects this event represents. The.patches
value will be passed to the object's.constructor
's@can.dispatchInstanceOnPatches
method.
- reasonLog
- args
{Array}
:Additional arguments to pass to event handlers.
Returns
{Object}
:
event The resulting event object.