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
eventargument.
Parameters
- event
{String|Object}:The event to dispatch. If a string is passed, it will be used as the
typeof the event that will be dispatched and dispatch matching @can.onKeyValue bindings:obs.dispatch("key")If
eventis an object, it MUST have atypeproperty. The If a string is passed, it will be used as thetypeof the event that will be dispatched and dispatch matching @can.onKeyValue bindings:obs.dispatch({type: "key"})The
eventobject 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.patchesvalue will be passed to the object's.constructor's@can.dispatchInstanceOnPatchesmethod.
- reasonLog
- args
{Array}:Additional arguments to pass to event handlers.
Returns
{Object}:
event The resulting event object.