SyntheticEvent Class
yui3/src/event/js/synthetic.js:207
Parent Module: event
Available since 3.1.0
<p>Wrapper class for the integration of new events into the YUI event infrastructure. Don't instantiate this object directly, use <code>Y.Event.define(type, config)</code>. See that method for details.</p>
<p>Properties that MAY or SHOULD be specified in the configuration are noted below and in the description of <code>Y.Event.define</code>.</p>
Constructor
SyntheticEvent
-
cfg
Parameters:
-
cfg
ObjectImplementation pieces and configuration
Index
Methods
Properties
Methods
_deleteSub
-
sub
Alternate <code>_delete()</code> method for the CustomEvent object created to manage SyntheticEvent subscriptions.
Parameters:
-
sub
Subscriptionthe subscription to clean up
_detach
-
args
Removes the subscription(s) from the internal subscription dispatch mechanism. See <code>SyntheticEvent._deleteSub</code>.
Parameters:
-
args
ArrayThe arguments passed to <code>node.detach(...)</code>
_init
()
protected
Construction logic for the event.
_on
-
args
-
delegate
Sets up the boilerplate for detaching the event and facilitating the execution of subscriber callbacks.
Parameters:
-
args
Arrayarray of arguments passed to <code>Y.on(...)</code> or <code>Y.delegate(...)</code>
-
delegate
Booleantrue if called from <code>Y.delegate(...)</code>
Returns:
the detach handle for this subscription
_subscribe
-
node
-
method
-
args
-
extra
-
filter
Creates a new Notifier object for use by this event's <code>on(...)</code> or <code>delegate(...)</code> implementation and register the custom event proxy in the DOM system for cleanup.
Parameters:
-
node
Nodethe Node hosting the event
-
method
String"on" or "delegate"
-
args
Arraythe subscription arguments passed to either <code>Y.on(...)</code> or <code>Y.delegate(...)</code> after running through <code>processArgs(args)</code> to normalize the argument signature
-
extra
AnyExtra data parsed from <code>processArgs(args)</code>
-
filter
String | Functionthe selector string or function filter passed to <code>Y.delegate(...)</code> (not present when called from <code>Y.on(...)</code>)
Returns:
applyArgExtras
-
extra
-
sub
<p>Implementers MAY provide this method definition.</p>
<p>Implement this function if you want extra data extracted during processArgs to be propagated to subscriptions on a per-node basis. That is to say, if you call <code>Y.on('xyz', fn, xtra, 'div')</code> the data returned from processArgs will be shared across the subscription objects for all the divs. If you want each subscription to receive unique information, do that processing here.</p>
<p>The default implementation adds the data extracted by processArgs to the subscription object as <code>sub._extra</code>.</p>
Parameters:
-
extra
AnyAny extra data extracted from processArgs
-
sub
Subscriptionthe individual subscription
delegate
-
node
-
sub
-
notifier
-
filter
<p>Implementers SHOULD provide this method definition.</p>
<p>Implementation logic for subscriptions done via <code>node.delegate(type, fn, filter)</code> or <code>Y.delegate(type, fn, container, filter)</code>. Like with <code>on()</code> above, this function should monitor the environment for the event being fired, and trigger subscription execution by calling <code>notifier.fire(e)</code>.</p>
<p>This function receives a fourth argument, which is the filter used to identify which Node's are of interest to the subscription. The filter will be either a boolean function that accepts a target Node for each hierarchy level as the event bubbles, or a selector string. To translate selector strings into filter functions, use <code>Y.delegate.compileFilter(filter)</code>.</p>
Parameters:
-
node
Nodethe node the subscription is being applied to
-
sub
Subscriptionthe object to track this subscription
-
notifier
SyntheticEvent.Notifiercall notifier.fire(..) to trigger the execution of the subscribers
-
filter
String | FunctionSelector string or function that accepts an event object and returns null, a Node, or an array of Nodes matching the criteria for processing.
detach
-
node
-
sub
-
notifier
<p>Implementers SHOULD provide this method definition.</p>
<p>Implementation logic for detaching subscriptions done via <code>node.on(type, fn)</code>. This function should clean up any subscriptions made in the <code>on()</code> phase.</p>
Parameters:
-
node
Nodethe node the subscription was applied to
-
sub
Subscriptionthe object tracking this subscription
-
notifier
SyntheticEvent.Notifierthe Notifier used to trigger the execution of the subscribers
detachDelegate
-
node
-
sub
-
notifier
-
filter
<p>Implementers SHOULD provide this method definition.</p>
<p>Implementation logic for detaching subscriptions done via <code>node.delegate(type, fn, filter)</code> or <code>Y.delegate(type, fn, container, filter)</code>. This function should clean up any subscriptions made in the <code>delegate()</code> phase.</p>
Parameters:
-
node
Nodethe node the subscription was applied to
-
sub
Subscriptionthe object tracking this subscription
-
notifier
SyntheticEvent.Notifierthe Notifier used to trigger the execution of the subscribers
-
filter
String | FunctionSelector string or function that accepts an event object and returns null, a Node, or an array of Nodes matching the criteria for processing.
getRegistry
-
node
-
type
-
create
Returns the array of subscription handles for a node for the given event type. Passing true as the third argument will create a registry entry in the event system's DOM map to host the array if one doesn't yet exist.
Parameters:
-
node
Nodethe node
-
type
Stringthe event
-
create
Booleancreate a registration entry to host a new array if one doesn't exist.
Returns:
getSubs
-
node
-
args
-
filter
-
first
Returns the detach handles of subscriptions on a node that satisfy a search/filter function. By default, the filter used is the <code>subMatch</code> method.
Parameters:
-
node
Nodethe node hosting the event
-
args
Arraythe array of original subscription args passed to <code>Y.on(...)</code> (before <code>processArgs</code>
-
filter
Functionfunction used to identify a subscription for inclusion in the returned array
-
first
Booleanstop after the first match (used to check for duplicate subscriptions)
Returns:
detach handles for the matching subscriptions
on
-
node
-
sub
-
notifier
<p>Implementers SHOULD provide this method definition.</p>
Implementation logic for subscriptions done via <code>node.on(type, fn)</code> or <code>Y.on(type, fn, target)</code>. This function should set up the monitor(s) that will eventually fire the event. Typically this involves subscribing to at least one DOM event. It is recommended to store detach handles from any DOM subscriptions to make for easy cleanup in the <code>detach</code> method. Typically these handles are added to the <code>sub</code> object. Also for SyntheticEvents that leverage a single DOM subscription under the hood, it is recommended to pass the DOM event object to <code>notifier.fire(e)</code>. (The event name on the object will be updated).
Parameters:
-
node
Nodethe node the subscription is being applied to
-
sub
Subscriptionthe object to track this subscription
-
notifier
SyntheticEvent.Notifiercall notifier.fire(..) to trigger the execution of the subscribers
processArgs
-
args
-
delegate
<p>Implementers MAY provide this method definition.</p>
<p>Implement this function if the event supports a different subscription signature. This function is used by both <code>on()</code> and <code>delegate()</code>. The second parameter indicates that the event is being subscribed via <code>delegate()</code>.</p>
<p>Implementations must remove extra arguments from the args list before returning. The required args for <code>on()</code> subscriptions are</p> <pre><code>[type, callback, target, context, argN...]</code></pre>
<p>The required args for <code>delegate()</code> subscriptions are</p>
<pre><code>[type, callback, target, filter, context, argN...]</code></pre>
<p>The return value from this function will be stored on the subscription in the '_extra' property for reference elsewhere.</p>
Parameters:
-
args
Arrayparmeters passed to Y.on(..) or Y.delegate(..)
-
delegate
Booleantrue if the subscription is from Y.delegate
Returns:
subMatch
-
sub
-
args
<p>Implementers MAY override this to define what constitutes a "same" subscription. Override implementations should consider the lack of a comparator as a match, so calling <code>getSubs()</code> with no arguments will return all subs.</p>
<p>Compares a set of subscription arguments against a Subscription object to determine if they match. The default implementation compares the callback function against the second argument passed to <code>Y.on(...)</code> or <code>node.detach(...)</code> etc.</p>
Parameters:
-
sub
Subscriptionthe existing subscription
-
args
Arraythe calling arguments passed to <code>Y.on(...)</code> etc.
Returns:
true if the sub can be described by the args present
Properties
preventDups
Boolean
<p>Implementers MAY override this property.</p>
<p>Whether to prevent multiple subscriptions to this event that are classified as being the same. By default, this means the subscribed callback is the same function. See the <code>subMatch</code> method. Setting this to true will impact performance for high volume events.</p>
Default: false