Composer source

Abstracts a pattern of DOM events, emitting more useful, higher-level events.

Specializes Target

The Composer helps to keep event normalization and calculation out of specific Components and in a reusable place. For example, the TranslateComposer handles listening to different mouse and touch events that represent dragging, and emits common translate events with helpful information about the move.

Specific composersshould specialize this Composer class and implement the load and unload methods to attach and remove their event listeners. Subclasses can also implement frame if they need access to their component's draw cycle.

Properties

acceptsActiveTarget :boolean source

Whether or not this target can accept user focus and become the activeTarget This matches up with the document.activeElement property purpose-wise; Events from components that should be dispatched as logically occurring at the point of user focus should be dispatched at the activeTarget

By default a target does not accept this responsibility.

Inherited From:
Default Value:
  • false

component :Component source

The Montage Component this Composer is attached to. Each composer is attached to a single component. By default, most composer will listen to DOM events on this component's element. This is also the component whose draw cycle is affected by needsFrame and frame.

Default Value:
  • null

element :Element source

The DOM element where the composer will listen for events. If no element is specified then the composer will use the element associated with its component property.

Subclasses may want to set their element to something other than the component's element during load for certain event patterns. One common pattern is to set element to window to listen for events anywhere on the page.

Default Value:
  • null

isActiveTarget :boolean <readonly> source

Whether or not this is the activeTarget

This is a getter and is not bindable. Bind to defaultEventManager.activeTarget == this.

Inherited From:

lazyLoad source

This property controls when the component will call this composer's load method, which is where the composer adds its event listeners:

  • If false, the component will call load during the next draw cycle after the composer is added to it.
  • If true, the component will call load after its prepareForActivationEvents.

Delaying the creation of event listeners can improve performance.

Default Value:
  • false

needsFrame :boolean source

This property should be set to 'true' when the composer wants to have its frame() method executed during the next draw cycle. Setting this property to 'true' will cause Montage to schedule a new draw cycle if one has not already been scheduled.

Default Value:
  • false

nextTarget :Component source

Which target to distribute an event after this when distributing events throughout a graph of targets.

Inherited From:

Methods

addEventListener(type, listener, useCapture) source

Adds an event listener to the object.

Parameters:
Name Type Description
type string

The event type to listen for.

listener object | function

The listener object or function.

useCapture boolean

Specifies whether to listen for the event during the bubble or capture phases.

Inherited From:

didBecomeActiveTarget() source

Called after to this target became the activeTarget

Inherited From:

dispatchEvent(event) source

Dispatches the specified event with this target as the event's proximal target

Parameters:
Name Type Description
event Event

The event object to dispatch

Inherited From:

dispatchEventNamed(type, canBubble, cancelable, detail) source

Creates and dispatches an event with the specified properties with this target as the event's proximal target

Parameters:
Name Type Description
type string

The type of the event to dispatch

canBubble boolean

Whether or not the event can bubble

cancelable boolean

Whether or not the event can be cancelled

detail Object

The optional detail object of the event

Inherited From:

frame(timestamp) source

This method will be invoked by the framework at the beginning of a draw cycle. This is where a composer may implement its update logic if it needs to respond to draws by its component.

Parameters:
Name Type Description
timestamp Date

The time that the draw cycle started

load() source

The component calls load on its composers when they should initialize themselves. Exactly when this happens is controlled by the composer's lazyLoad property.

Subclasses should override load with their DOM initialization. Most composers attach DOM event listeners to this.element in load.

removeEventListener(type, listener, useCapture) source

Removes an event listener from the object.

Parameters:
Name Type Description
type string

The event type.

listener object | function

The listener object or function.

useCapture boolean

The phase of the event listener.

Inherited From:

surrendersActiveTarget(newTarget) → {boolean} source

Ask this target to surrender its activeTarget status.

Parameters:
Name Type Description
newTarget Target

the Target that is about to become the activeTarget

Inherited From:
Returns: boolean

Whether or not to surrender activeTarget status

unload() source

The component will call unload when the composer is removed from the component or the component is removed.

Subclasses should override unload to do any necessary cleanup, such as removing event listeners.

willBecomeActiveTarget(oldTarget) source

Called prior to this target becoming the activeTarget

Parameters:
Name Type Description
oldTarget Target

the current activeTarget

Inherited From:

Generated from v0.14.14

Need help?

Can't find what you are looking for? Please contact us, we're more than happy to help answer your questions.