Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added dependenciesFor(event) to the API. Elaborated more about the AP…

…I in the README. Version bumped to 0.2.0.
  • Loading branch information...
commit dd9605e735749d76445710ec69301bd6836f0308 1 parent 427136c
@bnoguchi authored
Showing with 26 additions and 1 deletion.
  1. +13 −0 README.md
  2. +4 −0 dependency_promise.js
  3. +1 −1  package.json
  4. +8 −0 test.js
View
13 README.md
@@ -96,9 +96,22 @@ will behave in the same way, too. And so on and so forth.
## API
- `dependsOn(event, children)`
+ Sets up the dependency relationship between `this` and the `children` Array
+ based around the `event` string. Each member of `children` must also have
+ dependency-promise mixed in
- `trigger(event[, args..])`
+ Triggers the event with name `event`. You can optionally pass in
+ variable-length arguments. Triggering the event will do 2 things.
+ First, it will fire any callbacks for the `event`, passing any
+ arguments that may also have been passed to `trigger(...)`
+ Second, it will notify `this`'s parents that `this` has been triggered.
- `isTriggered(event)`
+ Returns true/false, specifying whether `this` has had `event` triggered.
- `on(event, callback, scope)`
+ Associates a `callback` and `scope` to be invoked when `this` triggers
+ said `event`.
+- `dependenciesFor(event)`
+ Returns the Array of dependencies (children) for the given `event`.
## Tests
To run tests:
View
4 dependency_promise.js
@@ -66,5 +66,9 @@ var dependencyPromise = module.exports = {
this.events[event].callbacks.push([fn, scope]);
}
return this;
+ },
+ dependenciesFor: function (event) {
+ if (!this.events || !this.events[event]) return [];
+ return this.events[event].children || [];
}
};
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "dependency-promise",
"description": "Add the Deferrable Pattern to Your Dependency Graphs",
- "version": "0.1.0",
+ "version": "0.2.0",
"keywords": [ "node", "dependencies", "promise", "deferrable" ],
"homepage": "https://github.com/bnoguchi/dependency-promise/",
"repository": {
View
8 test.js
@@ -144,5 +144,13 @@ module.exports = {
mama.dependsOn('loaded', [kid]);
kid.trigger('loaded');
counter.should.equal(3);
+ },
+
+ 'a parent should be able to get its dependencies': function () {
+ var parent = new Node()
+ , childOne = new Node()
+ , childTwo = new Node();
+ parent.dependsOn('loaded', [childOne, childTwo]);
+ parent.dependenciesFor('loaded').should.eql([childOne, childTwo]);
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.