Class: Loop

capsula.Loop()

Loop is a specific public property of a capsule. It is a representation of a child element in a hierarchical structure of elements (e.x. widgets). In other words, it represents a child in a parent-child relationship.

Loops always go along with hooks; they are complementary concepts.

Constructor

new Loop()

Creates new loop as a property of the capsule that represents the current context of execution.
Since:
  • 0.1.0
Source:
Throws:
Type
Error

Methods

add(…var_args)

Ties this loop acting as a parent in the current context of execution to the given loops. It is assumed that this loop belongs to the capsule that represents the current context of execution; otherwise it throws error. The function accepts both comma separated list of loops and an array of loops.
Parameters:
Name Type Attributes Description
var_args module:capsula.Loop <repeatable>
loops to tie this parent loop to (an array of loops also accepted)
Since:
  • 0.1.0
Source:
Throws:
Type
Error

addAt(at, …var_args)

Ties this loop acting as a parent in the current context of execution to the given loops according to the given at index. It is assumed that this loop belongs to the capsule that represents the current context of execution; otherwise it throws error. The function accepts both comma separated list of loops and an array of loops.
Parameters:
Name Type Attributes Description
at number the index to use when tying this parent loop to the given loops
var_args module:capsula.Loop <repeatable>
loops to tie this parent loop to (an array of loops also accepted)
Since:
  • 0.1.0
Source:
Throws:
Type
Error

clear()

Unties this loop acting as a parent in the current context of execution from all the loops it is tied to. It is assumed that this loop belongs to the capsule that represents the current context of execution; otherwise it throws error.
Since:
  • 0.1.0
Source:
Throws:
Type
Error

disclose(opt_nameopt) → {module:capsula.Loop}

Creates a new loop for the capsule that represents the current context of execution (with the given name, if provided). Then, ties that newly created loop to this loop. Returns the newly created loop.

In other words, it discloses (publishes) this loop to the interface of the capsule that represents the current context of execution.

Assumes this loop belongs to a part capsule of the capsule that represents the current context of execution. Otherwise it throws error.

Parameters:
Name Type Attributes Description
opt_name string <optional>
the name of the newly created loop
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
the newly created loop
Type
module:capsula.Loop

getChildren() → {Array.<module:capsula.Loop>}

Returns an array of loops this loop is tied to acting as a parent in the current context of execution; or an empty array if it is not tied to any loop. It is assumed that this loop belongs to the capsule that represents the current context of execution; otherwise it throws error.
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
an array of loops this loop is tied to acting as the current context of execution; or an empty array
Type
Array.<module:capsula.Loop>

getFQName(opt_sepopt) → {string}

Returns the fully qualified name of this loop, using the given separator if provided (if not, the :: is used by default).

The fully qualified name comprises the name of this loop, the name of the owner capsule of this loop, the name of its owner, and so on all the way up the capsule hierarchy.

Parameters:
Name Type Attributes Description
opt_sep string <optional>
the separator to use to separate names in the returned fully qualified name
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
the fully qualified name of this loop
Type
string

getId() → {number}

Returns the id of this loop.
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
the id of this loop
Type
number

getName() → {string}

Returns the name of this loop.
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
the name of this loop
Type
string

getOwner() → {module:capsula.Capsule}

Returns the owner capsule of this loop.
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
the owner capsule of this loop
Type
module:capsula.Capsule

getParent() → {module:capsula.Hook|module:capsula.Loop}

Returns the parent hook or loop this loop is tied to; or null if it is not tied to a parent hook or loop in the current context of execution.

Assumes this loop belongs to a part capsule of the capsule that represents the current context of execution. Otherwise it throws error.

Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
the parent hook or loop this loop is tied to (in the current context of execution)
Type
module:capsula.Hook | module:capsula.Loop

isParentOf(…var_args) → {boolean}

Checks whether this loop acting as a parent in the current context of execution is tied to all the given loops. It is assumed that this loop belongs to the capsule that represents the current context of execution; otherwise it throws error. The function accepts both comma separated list of loops and an array of loops.
Parameters:
Name Type Attributes Description
var_args module:capsula.Loop <repeatable>
loops to check (an array of loops also accepted)
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
whether this parent loop is tied to all the given loops (in the current context of execution)
Type
boolean

isPublic() → {boolean}

Returns whether this loop belongs to the capsule which is the current context of execution.

In other words, returns whether this.getOwner() === current context of execution.

Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
whether this loop belongs to the capsule which is the current context of execution
Type
boolean

remove(…var_args)

Unties this loop acting as a parent in the current context of execution from the given loops. It is assumed that this loop belongs to the capsule that represents the current context of execution; otherwise it throws error. The function accepts both comma separated list of loops and an array of loops.
Parameters:
Name Type Attributes Description
var_args module:capsula.Loop <repeatable>
loops to untie this parent loop from (an array of loops also accepted)
Since:
  • 0.1.0
Source:
Throws:
Type
Error

renderInto(el)

Renders this loop (i.e. the DOM element this loop represents) into the given DOM element.

Parameters:
Name Type Description
el Element the DOM element into which to render this loop
Since:
  • 0.1.0
Source:
Throws:
Type
Error

set(…var_args)

First, unties this loop acting as a parent in the current context of execution from all the loops it is tied to and then ties this loop to the given loops. It is assumed that this loop belongs to the capsule that represents the current context of execution; otherwise it throws error. The function accepts both comma separated list of loops and an array of loops.
Parameters:
Name Type Attributes Description
var_args module:capsula.Loop <repeatable>
loops to re-tie this parent loop to (an array of loops also accepted)
Since:
  • 0.1.0
Source:
Throws:
Type
Error

setClass(cls)

Sets a class to this loop. When a class is set to a loop, each element represented by this loop's subtree would be flagged by this class. To understand how this flagging works setDefaultElementHandlers should be consulted.
Parameters:
Name Type Description
cls string the class to set to this loop
Source:
See:
Throws:
Type
Error

setEventHandlers(onHook, offHook)

Sets onHook and offHook callbacks to be called each time the path of this loop is completed or broken.

onHook and offHook callbacks are always called with respect to a path that changed: when a path of this loop gets completed onHook function is called; when completed path of this loop is broken (fragmented) offHook is called.

The callbacks are called in the context of the owner capsule of this loop; reference "this" in callbacks points again to the owner of this loop.

Parameters:
Name Type Description
onHook function callback function to be called each time a path of this loop gets completed
offHook function callback function to be called each time a complete path of this loop gets broken (fragmented)
Since:
  • 0.1.0
Source:
Throws:
Type
Error

setName(name)

Sets a new name to this loop. New name can later be used to obtain a reference to this loop from its owner capsule using getLoop.
Parameters:
Name Type Description
name string a new name of this loop
Since:
  • 0.1.0
Source:
Throws:
Type
Error

setParent(parent)

Ties this loop to the given parent hook or loop in the current context of execution.

Assumes this loop belongs to a part capsule of the capsule that represents the current context of execution. Otherwise it throws error.

Parameters:
Name Type Description
parent module:capsula.Hook | module:capsula.Loop a parent hook or loop to tie this loop to
Since:
  • 0.1.0
Source:
Throws:
Type
Error

tie(var_args)

Ties this loop to the given parent hook or loop or the given child loops in the current context of execution. The function accepts loops in an array as well.
Parameters:
Name Type Description
var_args module:capsula.Hook | module:capsula.Loop | Array.<module:capsula.Loop> hook, loop, or an array of loops to tie this loop to
Since:
  • 0.1.0
Source:
Throws:
Type
Error