Skip to content
/ hier Public

tree keeping track of what is on the page

License

Notifications You must be signed in to change notification settings

pavelsof/hier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hier

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.

api

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, expects func(path, elem, params), called before the node constructor is invoked;
  • post-init, expects func(path, elem, view), called after the node constructor is invoked;
  • pre-empty, expects func(path, elem, view), called when the node is being removed but before its children are;
  • pre-remove, expects func(path, elem, view), called when the node is being removed after its children are;
  • post-remove, expects func(path), called after the node is removed.

hier.off(hook) removes the previously hooked function.

hier.show() returns string representation of the tree.

licence

MIT

About

tree keeping track of what is on the page

Resources

License

Stars

Watchers

Forks

Packages

No packages published