If you perceive your webapp as a directory tree, hier might be for you. It tries to handle the global state, letting you write Crockford-style constructors for your hierarchy nodes.
Plays well with the likes of crossroads and mustache.
hier.add(path, elem, func, params)
invokes func(elem, params)
and adds the
path to the tree. If elem
is a string, the right dom element will be
query-selected for you. Does nothing if the path has already been added with the
same primitive param. Returns the return of func
(also in the latter case).
hier.update(path, params)
invokes func(elem, params)
with the new params,
removing the path's descendants before that. Returns the return of func
.
hier.remove(path)
removes the path from the tree.
hier.has(path)
returns a boolean.
hier.reg(path, elem, func)
does not do anything except that it enables you to
do hier.add(path, params)
from then on.
hier.unreg(path)
and you cannot use the shorthand hier.add
any more.
hier.on(hook, func)
hooks func
to one of (view
is the output of the
constructor):
pre-init
, expectsfunc(path, elem, params)
, called before the node constructor is invoked;post-init
, expectsfunc(path, elem, view)
, called after the node constructor is invoked;pre-empty
, expectsfunc(path, elem, view)
, called when the node is being removed but before its children are;pre-remove
, expectsfunc(path, elem, view)
, called when the node is being removed after its children are;post-remove
, expectsfunc(path)
, called after the node is removed.
hier.off(hook)
removes the previously hooked function.
hier.show()
returns string representation of the tree.
MIT