slint browser:true, node:true, laxbreak:true
Defines a module. \nOptions:
name {String}
the name of the moduletag {String}
the tagName to use for the root elementclasses {Array}
a list of classes to add to the root elementtemplate {Function}
the template function to use when renderinghelpers {Array}
a list of helpers to apply to the moduleinitialize {Function}
custom logic to run when module instance createdsetup {Function}
custom logic to run when.setup()
is called (directly or indirectly)teardown {Function}
custom logic to unbind/undo anything setup introduced (called on.destroy()
and sometimes on.setup()
to avoid double binding events)destroy {Function}
logic to permanently destroy all references
shint browser:true, node:true
Module Dependencies
Exports
Module constructor \nOptions:
id {String}
a unique id to query bymodel {Object|Model}
the data with which to associate this moduletag {String}
tagName to use for the root elementclasses {Array}
list of classes to add to the root elementtemplate {Function}
a template to use for renderinghelpers {Array}
a list of helper function to use on this modulechildren {Object|Array}
list of child modules
Adds a child view(s) to another Module. \nOptions:
at
The child index at which to insertinject
Injects the child's view element into the parent'sslot
The slot at which to insert the child
Removes a child view from its current Module contexts and also from the DOM unless otherwise stated. \nOptions:
fromDOM
Whether the element should be removed from the DOM (defaulttrue
)
Example:
// The following are equal
// apple is removed from the
// the view structure and DOM
layout.remove(apple);
apple.remove();
// Apple is removed from the
// view structure, but not the DOM
layout.remove(apple, { el: false });
apple.remove({ el: false });
Returns a decendent module by id, or if called with no arguments, returns this view's id. \nExample:
myModule.id();
//=> 'my_view_id'
myModule.id('my_other_views_id');
//=> Module
Returns the first descendent Module with the passed module type. If called with no arguments the Module's own module type is returned. \nExample:
// Assuming 'myModule' has 3 descendent
// views with the module type 'apple'
myModule.modules('apple');
//=> Module
Returns a list of descendent Modules that match the module type given (Similar to Element.querySelectorAll();). \nExample:
// Assuming 'myModule' has 3 descendent
// views with the module type 'apple'
myModule.modules('apple');
//=> [ Module, Module, Module ]
Calls the passed function for each of the view's children. \nExample:
myModule.each(function(child) {
// Do stuff with each child view...
});
Templates the view, including
any descendent views returning
an html string. All data in the
views model is made accessible
to the template.
\nChild views are printed into the
parent template by id
. Alternatively
children can be iterated over a a list
and printed with {{{child}}}}
.
Example:
<div class="slot-1">{{{<slot>}}}</div>
<div class="slot-2">{{{<slot>}}}</div>
// or
{{#children}}
{{{child}}}
{{/children}}
Get the view's innerHTML
Renders the view and replaces
the view.el
with a freshly
rendered node.
\nFires a render
event on the view.
Sets up a view and all descendent
views.
\nSetup will be aborted if no view.el
is found. If a view is already setup,
teardown is run first to prevent a
view being setup twice.
Your custom setup()
method is called
Options:
shallow
Does not recurse whentrue
(defaultfalse
)
Tearsdown a view and all descendent
views that have been setup.
\nYour custom teardown
method is
called and a teardown
event is fired.
Options:
shallow
Does not recurse whentrue
(defaultfalse
)
Completely destroys a view. This means
a view is torn down, removed from it's
current layout context and removed
from the DOM.
\nYour custom destroy
method is
called and a destroy
event is fired.
NOTE: .remove()
is only run on the view
that .destroy()
is directly called on.
Options:
fromDOM
Whether the view should be removed from DOM (defaulttrue
)
Destroys all children. \nIs this needed?
Associate the view with an element. Provide events and lifecycle methods to fire when the element is newly associated.
Empties the destination element and appends the view into it.
Appends the view element into the destination element.
Inserts the view element before the given child of the destination element.
Returns a JSON represention of a FruitMachine Module. This can be generated serverside and passed into new FruitMachine(json) to inflate serverside rendered views.
Module Dependencies
Local vars
Registers a event listener.
Unregisters a event listener.
Fires an event on a view.