Repetition source

A component that repeats its inner template for each value in some content.

Specializes Component

A component that manages copies of its inner template for each value in its content. The content is managed by a controller. The repetition will create a RangeController for the content if you provide a content property instead of a contentController.

Ensures that the document contains iterations in the same order as provided by the content controller.

The repetition provides the objectAtCurrentIteration and currentIteration properties that can be bound to by the contents of the repetition during the instantiation of the iteration.

The repetition strives to avoid moving iterations on, off, or around on the document, prefering to inject or retract iterations between ones that remain in their respective order, or even just rebind existing iterations to alternate content instead of injecting and retracting in the same position.

Properties

activeIterations :Array.<Iteration> source

The user may determine which iterations are active by setting or manipulating the content of the activeIterations array. At present, the repetition does not guarantee any particular order of appearance of the contained iterations.

application :Application source

Convenience to access the application object.

Inherited From:

childComponents :Array.<Component> <readonly> source

The child components of the component. This property is readonly and should never be changed.

Inherited From:

classList :Set source

The classList of the component's element, the purpose is to mimic the element's API but to also respects the draw cycle.

It can also be bound to by binding each class as a property. example to toggle the complete class:

"classList.has('complete')" : { "<-" : "@owner.isComplete"}
Inherited From:
Default Value:
  • null

content :Array.<Object> source

A getter and setter for the content of a repetition. If you set the content property of a repetition, it produces a range content controller for you. If you get the content property, it will reach into the content controller to give you its content.

The content represents the entire backing collection. The content controller may filter, sort, or otherwise manipulate the visible region of the content. The Iteration#index of each iteration corresponds to the position within the visible region of the controller.

contentController :RangeController source

A range controller or instance with the same interface ( iterations and selection properties, where each

<iteration has object and selected properties). The controller is responsible for managing which contents are visible, selected, and the order of their appearance.

currentIteration :Iteration source

The user may bind to the currentIteration when the repetition instantiates a new iteration. The template guarantees that child components can safely bind to the containing repetition.

At present, you cannot bind to a grandparent repetition's currentIteration, so it becomes the responsibility of the parent repetition to bind its parent repetition's currentIteration to a property of itself so its children can access their grandparent.

delegate :Object source

A delegate is an object that has helper methods specific to particular components. For example, a TextField may consult its deletate's shouldBeginEditing() method, or inform its delegate that it didBeginEditing(). Look for details on the documentation of individual components' delegate properties.

Inherited From:
Default Value:
  • null

element :DOMElement source

The element of the component as defined in the template.

{
   "component": {
       "properties": {
           "element": {"#": "dataMontageId"}
       }
   }
}

DOM arguments can be passed to the component as direct children of the element. By default the entire content of the element is considered the single DOM argument of the component. Multiple arguments can be given by assigning a data-arg attribute to each element that represents an argument.

<div data-montage-id="component">
    <h1 data-arg="title"></h1>
    <div data-arg="content">
        <span data-montage-id="text"></span>
    <div>
</div>

If the component has a template then this element is replaced by the element that is referenced in its template just before the component enters the document.

{
   "owner": {
       "properties": {
           "element": {"#": "dataMontageId"}
       }
   }
}

The component element has a component property that points back to the component. This property is specially useful to extrapolate the component tree from the DOM tree. It can also be used for debugging purposes, on the webkit inspector when an element is selected it's possible to find its component by using the $0.component command on the console.

The element of a component can only be assigned once, it's not possible to change it.

Inherited From:
Default Value:
  • null

eventManager :EventManager source

Convenience to access the defaultEventManager object.

Inherited From:

getTemplateArgumentElement source

TemplateArgumentProvider implementation

Inherited From:

isSelectionEnabled :boolean source

When selection is enabled, each element in an iteration responds to touch and click events such that the iteration is highlighted (with the "active" CSS class) when the user touches or clicks it, and toggles whether the corresponding content is selected.

Selection may be enabled and disabled at any time in the life cycle of the repetition. The repetition watches changes to this property.

All repetitions support selection, whether it is used or not. This property merely dictates whether the repetition handles gestures for selection.

iterations :Array.<Iteration> source

The repetition coordinates this array of repetition iterations. Each iteration tracks its corresponding content, whether it is selected, whether it is active, and what CSS classes are applied on each of its direct child nodes. This array appears in the order that the iterations will be drawn. There is one repetition iteration for each controller iteration. The repetition iterations have more responsibilities than the corresponding controller, but some of the properties are bound by the same names, like object and selected.

localizer :Localizer source

The localizer for this component

Inherited From:
Default Value:
  • null

needsDraw :boolean source

The purpose of this property is to trigger the adding of the component to the draw list. The draw list consists of all the components that will be drawn on the next draw cycle.

The draw cycle itself is triggered by the requestAnimationFrame API where available, otherwise a shim implemented with setTimeout is used.

When it happens, the draw cycle will call, in succession, and when they exist, the methods: willDraw, draw, and didDraw.

At the end of the draw cycle this property is set back to false.

Inherited From:
Default Value:
  • false

nextTarget :Target source

The next Target to consider in the event target chain

Currently, components themselves do not allow this chain to be broken; setting a component's nextTarget to a falsy value will cause nextTarget to resolve as the parentComponent.

To interrupt the propagation path a Target that accepts a falsy nextTarget needs to be set at a component's nextTarget.

Inherited From:

objectAtCurrentIteration :Object source

The user may bind the the currentIteration.object with this shorthand.

ownerComponent :Component source

The owner component is the owner of the template form which this component was instantiated.

Inherited From:
Default Value:
  • null

parentComponent :Component source

The parent component is the component that is found by walking up the DOM tree, starting at the component's element. Each component element has a component property that points back to the component object, this way it's possible to know which component an element represents.

This value is null for the RootComponent.

Inherited From:

rootComponent :RootComponent source

Convenience to access the rootComponent object.

Inherited From:

selectedIndexes :Array.<number> source

The repetition maintains an array of the indexes of every selected iteration. The user should not modify the array.

selectedIterations :Array.<Iteration> source

The repetition maintains an array of every visible, selected iteration, in the order of its appearance. The user should not modify the selected iterations array.

selection :Array.<Object> source

A collection of the selected content. It may be any ranged collection like Array or SortedSet. The user may get, set, or modify the selection directly. The selection property is bidirectionally bound to the selection of the content controller. Every repetition has a content controller, and will use a RangeController if not given one.

template :Template source

The template object of the component.

Inherited From:
Default Value:
  • null

templateObjects :Object source

This property is populated by the template. It is a map of all the instances present in the template's serialization keyed by their label.

Inherited From:
Default Value:
  • null

waitForLocalizerMessages :boolean source

Whether to wait for the localizer to load messages before drawing. Make sure to set the localizer before setting to true.

Inherited From:
Default Value:
  • false
Example
// require localizer
var defaultLocalizer = localizer.defaultLocalizer,
    _ = defaultLocalizer.localizeSync.bind(defaultLocalizer);

exports.Main = Component.specialize( {

    constructor: {
        value: function() {
            this.localizer = defaultLocalizer;
            this.waitForLocalizerMessages = true;
        }
    },

    // ...

    // no draw happens until the localizer's messages have been loaded
    enterDocument: {
        value: function(firstTime) {
            if (firstTime) {
                this._greeting = _("hello", "Hello {name}!");
            }
        }
    },
    draw: {
        value: function() {
            // this is for illustration only. This example is simple enough that
            // you should use a localizations binding
            this._element.textContent = this._greeting({name: this.name});
        }
    }
}

Methods

addComposer(composer) source

Adds the passed in composer to the component's composer list.

Parameters:
Name Type Description
composer Composer
Inherited From:

addComposerForElement(composer, element) source

Adds the passed in composer to the component's composer list and sets the element of the composer to the passed in element.

Parameters:
Name Type Description
composer Composer
element Element
Inherited From:

callDelegateMethod(name) source

This method calls the method named with the identifier prefix if it exists. Example: If the name parameter is "shouldDoSomething" and the caller's identifier is "bob", then this method will try and call "bobShouldDoSomething"

Parameters:
Name Type Description
name string
Inherited From:

clearAllComposers() source

A convenience method for removing all composers from a component. This method is responsible for calling unload on each composer before removing it.

Inherited From:

createActionEvent() source

Convenience to create a custom event named "action"

Inherited From:
Returns:

and event to dispatch upon interaction

didDraw() source

This method is part of the draw cycle and it provides the component an opportunity to query the DOM for any necessary calculations after drawing. If the execution of this method sets needsDraw to true on other components, those components will be added to the current draw cycle.

Components should not change the DOM during this phase of the draw cycle as it could force an unwanted reflow from the browser.

Inherited From:
See:

enterDocument(firstTime) source

This function is called when the component element is added to the document's DOM tree.

Parameters:
Name Type Description
firstTime boolean

true if it's the first time the component enters the document.

Inherited From:

equals(anObject) → {boolean} source

Returns true if two objects are equal, otherwise returns false.

Parameters:
Name Type Description
anObject Object

The object to compare for equality.

Inherited From:
Returns: boolean

Returns true if the calling object and anObject are identical and their uuid properties are also equal. Otherwise, returns false.

exitDocument() source

Lifecycle method called when this component is removed from the document's DOM tree.

Inherited From:

extractDomArgument(name) source

This function extracts a DOM argument that was in the element assigned to the component. The star (*) argument refers to the entire content of the element when no data-arg was given.

When a DOM argument is extracted from a Component it is no longer available

Parameters:
Name Type Description
name string

The name of the argument, or "*" for the entire content.

Inherited From:
Returns:

the element

prepareForActivationEvents() source

Called by the EventManager before dispatching a touchstart or mousedown.

The component can implement this method to add event listeners for these events before they are dispatched.

Inherited From:

removeComposer(composer) source

Removes the passed in composer from this component's composer list. It takes care of calling the composers unload method before removing it from the list.

Parameters:
Name Type Description
composer Composer
Inherited From:

scheduleComposer(composer) source

Adds the passed in composer to the list of composers which will have their frame method called during the next draw cycle. It causes a draw cycle to be scheduled iff one has not already been scheduled.

Parameters:
Name Type Description
composer Composer
Inherited From:

surrenderPointer(pointer, demandingComponent) → {boolean} source

Ask this component to surrender the specified pointer to the demandingComponent.

The component can decide whether or not it should do this given the pointer and demandingComponent involved.

Some components may decide not to surrender control ever, while others may do so in certain situations.

Returns true if the pointer was surrendered, false otherwise.

The demandingComponent is responsible for claiming the surrendered pointer if it desires.

Parameters:
Name Type Description
pointer string

The pointerIdentifier that the demanding component is asking this component to surrender

demandingComponent Object

The component that is asking this component to surrender the specified pointer

Inherited From:
Returns: boolean

true

willDraw() source

This method is part of the draw cycle and it provides the component an opportunity to query the DOM for any necessary calculations before drawing. If the execution of this method sets needsDraw to true on other components, those components will be added to the current draw cycle.

Components should not change the DOM during this phase of the draw cycle as it could force an unwanted reflow from the browser.

Inherited From:
See:

Generated from a4679af

comments powered by Disqus

More help?

Can't find what you are looking for? Get in touch, we're more than happy in helping answer your questions.