Comparing version 1.1.1 to 1.2.0
1.2.0 / 2016-10-08 | ||
================== | ||
* feat(tree): implement Iterable interface | ||
1.1.1 / 2016-10-03 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -31,2 +31,12 @@ 'use strict' | ||
/** | ||
* Implement the iterator interface to allow iterating the files in this | ||
* tree topologically. | ||
* | ||
* TODO: allow configuring the iteration order (ie: turn topological off) | ||
*/ | ||
[Symbol.iterator] () { | ||
return this.getFiles({ topological: true }).values() | ||
} | ||
/** | ||
* Checks to see if the given file ID exists in the tree. | ||
@@ -33,0 +43,0 @@ * |
{ | ||
"name": "mako-tree", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"main": "./lib/tree", | ||
@@ -5,0 +5,0 @@ "description": "The build tree structure used internally by mako", |
@@ -33,2 +33,16 @@ # mako-tree | ||
### Tree[@@iterable]() | ||
This class implements the `Iterable` interface, which iterates the files in the tree in topological | ||
order. (see `Tree#getFiles()` for more information) | ||
```js | ||
for (const file of tree) { | ||
// iterate files in topological order | ||
} | ||
``` | ||
This sugar allows you to treat the tree itself as an iterable, which can be useful in interacting | ||
with other APIs. | ||
### Tree#hasFile(file) | ||
@@ -35,0 +49,0 @@ |
@@ -25,2 +25,32 @@ /* eslint-env mocha */ | ||
describe('@@iterator()', function () { | ||
// index.html <- index.js <- shared.js | ||
// <- index.css <- shared.css | ||
let tree = new Tree() | ||
let html = tree.addFile('index.html') | ||
let js = tree.addFile('index.js') | ||
let sharedJS = tree.addFile('shared.js') | ||
let css = tree.addFile('index.css') | ||
let sharedCSS = tree.addFile('shared.css') | ||
tree.addDependency(html, js) | ||
tree.addDependency(html, css) | ||
tree.addDependency(js, sharedJS) | ||
tree.addDependency(css, sharedCSS) | ||
it('should implement the iterator interface', function () { | ||
let count = 0 | ||
for (const file of tree) { | ||
count += 1 | ||
assert.instanceOf(file, File) | ||
} | ||
assert.equal(count, 5) | ||
}) | ||
it('should sort the items topologically', function () { | ||
let files = [] | ||
for (const file of tree) files.push(file) | ||
assert.deepEqual(files, [ sharedJS, sharedCSS, js, css, html ]) | ||
}) | ||
}) | ||
describe('#hasFile(id)', function () { | ||
@@ -27,0 +57,0 @@ let tree = new Tree() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71245
1552
254