Panzer
version 0.3.13 by Bemi Faison
A comprehensive node-tree solution, for smart data.*
DESCRIPTION
Panzer is a JavaScript class factory that implements tree parsing, traversal and monitoring. Panzer separates node behavior, structure, and navigation concerns, so you can design classes that do just what you need.
The procedural consumption of "structure" allows data to inform your code's execution, for easier coding. As well, Panzer provides nodal meta-data, like parent-child relationships, depth, child order, etc. - which can be used to solve various problem domains.
The purpose and function of your Panzer is given by it's packages - modules of code that access and extend classes. The package architecture allows several treatments of an instance, with fewer resource collisions and greater interoperability than traditional plug-in schemes.
* Read The Cathedral and the Bazaar, to understand why "Smart data structures and dumb code works a lot better than the other way around."
INSTALL
Web Browsers
Use a <SCRIPT>
tag to reference panzer.min.js, as you would any external JavaScript file. The "Panzer" namespace will be added to the global scope.
Node.js
npm install panzer
if you're using npmcomponent install bemson/panzer
if you're using componentbower install panzer
if you're using Bower
Dependencies
Panzer requires genData v3.1.0. (The minified file includes this dependency.)
USAGE
First, create a Panzer class.
var BasicTree = Panzer;
In order to access and extend Panzer's functionality, we need to define a package. (Otherwise, our instances won't do much.) Let's register a new package by name.
var myPkgDef = BasicTree;
The returned value is the package-definition, a function with special members that hook into our class. Many hooks are available, but we'll prototype an instance method now.
myPkgDefproxy { var // get the corresponding package-instance tree = // alias the tank that controls our tree's "pointer" tank = treetank // reference the current node currentNode = treenodestankcurrentIndex // reference a sibling or child node, if available nextNode = treenodescurrentNodenextIndex || currentNodefirstChildIndex; // if there is a nextNode and we've successfully navigated to it... if nextNode && tank // return the value of (what is now) the current node return nextNodevalue; // (otherwise) flag that no node is next return false;};
Though simple enough, there is a lot going on in our method. Nevertheless, we can now "walk" the left-branch of any data structure.
var myTree = hello: 'world' nodeValue lefties = ;while nodeValue = myTree lefties;//// lefties[0] -> {hello: 'world'}// lefties[1] -> 'world'//
Understanding the package api is key to getting the most from your class. However, in lieu of full documentation, please see the test suite for greater insight. Thanks for your patience!
FILES
- src/ - Directory containing the source code
- test/ - Mocha test suite
- README.md - This readme file
- LICENSE - The legal terms and conditions under which this software may be used
- panzer.min.js - The Panzer platform, including dependencies, minified for browser environments
Source files minified with both UglifyJS and Yahoo! Compressor.
LICENSE
Panzer is available under the terms of the MIT-License.
Copyright 2014, Bemi Faison