Skip to content

Commit

Permalink
Add installation and configuration instructions to project README.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaonuno committed Jul 7, 2013
1 parent 4abae81 commit ec22755
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
TreeModel
=========
# TreeModel

Manipulate and traverse tree-like structures in javascript.

http://jnuno.com/tree-model-js
For download, API and demos, please [visit tree-model-js website](http://jnuno.com/tree-model-js).

## Instalation

### Node
TreeModel is available as a npm module so you can install it with `npm install tree-model` and use it in your script:

```
var TreeModel = require('tree-model'),
tree = new TreeModel(),
root = tree.parse({name: 'a', children: [{name: 'b'}]});
```

### Browser
#### Using [requirejs](http://requirejs.org/)
```
<script src="path/to/require.js"></script>
<script>
require(["path/to/TreeModel"], function(TreeModel) {
var tree = new TreeModel(),
root = tree.parse({name: 'a', children: [{name: 'b'}]});
});
</script>
```
#### As a global variable
```
<script src="path/to/TreeModel.js"></script>
<script>
var tree = new TreeModel(),
root = tree.parse({name: 'a', children: [{name: 'b'}]});
</script>
```

## Configuration
You can pass the property name of the children array and a comparator function to be used by `parse` and by `addChild`:
```
var tree = new TreeModel({
// Default is 'children'
childrenPropertyName: 'dependencies',
modelComparatorFn: function (a, b) {
// Reverse order by name
return a.name < b.name;
}
});
```

0 comments on commit ec22755

Please sign in to comment.