Class: Hook

capsula.Hook()

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

Hooks always go along with loops; they are complementary concepts.

Constructor

new Hook()

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

addAt(at, …var_args)

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

clear()

Unties this hook acting as a parent in the current context of execution from all the hooks and loops it is tied to. It is assumed that this hook 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

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

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

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

Assumes this hook 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 hook
Since:
  • 0.1.0
Source:
Throws:
Type
Error
Returns:
the newly created hook
Type
module:capsula.Hook

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

Returns an array of hooks and loops this hook is tied to acting as a parent in the current context of execution; or an empty array if it is not tied to any hook or loop. It is assumed that this hook 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:
an array of hooks and loops this hook is tied to acting as a parent in the current context of execution; or an empty array
Type
Array.<(module:capsula.Hook|module:capsula.Loop)>

getFQName(opt_sepopt) → {string}

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

The fully qualified name comprises the name of this hook, the name of the owner capsule of this hook, 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 hook
Type
string

getId() → {number}

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

getName() → {string}

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

getOwner() → {module:capsula.Capsule}

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

getParent() → {module:capsula.Hook}

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

Assumes this hook belongs to 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 this hook is tied to (in the current context of execution)
Type
module:capsula.Hook

isParentOf(…var_args) → {boolean}

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

isPublic() → {boolean}

Returns whether this hook 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 hook belongs to the capsule which is the current context of execution
Type
boolean

remove(…var_args)

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

renderInto(el)

Renders this hook (i.e. the DOM elements it represents) into the given DOM element.

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

set(…var_args)

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

setClass(cls)

Sets a class to this hook. When a class is set to a hook, each element represented by this hook'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 hook
Source:
See:
Throws:
Type
Error

setEventHandlers(onHook, offHook)

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

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

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

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

setName(name)

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

setParent(parent)

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

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

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

tie(…var_args)

Ties this hook to the given hooks and loops in the current context of execution. Note that having multiple arguments makes sense only when this hook acts as a parent in the current context of execution i.e. when it belongs to a part capsule of the capsule that represents the current context of execution. The function accepts both comma separated list of hooks and loops and an array of hooks and loops.
Parameters:
Name Type Attributes Description
var_args module:capsula.Hook | module:capsula.Loop <repeatable>
hooks and loops to tie this hook to (an array of hooks and loops also accepted)
Since:
  • 0.1.0
Source:
Throws:
Type
Error