Comparing version 0.9.6 to 0.9.7
@@ -39,4 +39,4 @@ var _ = require("./_"); | ||
* | ||
* // Unsubscribe all children. | ||
* linear.children = []; | ||
* // Unsubscribe all subscribers. | ||
* linear.subscribers = []; | ||
* ``` | ||
@@ -76,3 +76,3 @@ * @example | ||
self.children = []; | ||
self.subscribers = []; | ||
@@ -91,12 +91,12 @@ executor && executor(emit); | ||
/** | ||
* The parent observable of this. | ||
* The publisher observable of this. | ||
* @type {Observable} | ||
*/ | ||
parent: null, | ||
publisher: null, | ||
/** | ||
* All the children subscribed this observable. | ||
* All the subscribers subscribed this observable. | ||
* @type {Array} | ||
*/ | ||
children: null, | ||
subscribers: null, | ||
@@ -115,4 +115,4 @@ /** | ||
child.parent = self; | ||
self.children.push(child); | ||
child.publisher = self; | ||
self.subscribers.push(child); | ||
@@ -126,4 +126,4 @@ return child; | ||
unsubscribe: function () { | ||
var parent = this.parent; | ||
parent && parent.children.splice(parent.children.indexOf(this), 1); | ||
var publisher = this.publisher; | ||
publisher && publisher.subscribers.splice(publisher.subscribers.indexOf(this), 1); | ||
} | ||
@@ -135,5 +135,5 @@ | ||
return self.emit = function (val) { | ||
var i = 0, len = self.children.length, child; | ||
var i = 0, len = self.subscribers.length, child; | ||
while (i < len) { | ||
child = self.children[i++]; | ||
child = self.subscribers[i++]; | ||
_.Promise.resolve(val).then( | ||
@@ -158,2 +158,3 @@ child._onEmit, | ||
* Merge multiple observables into one. | ||
* @version_added 0.9.6 | ||
* @param {Iterable} iterable | ||
@@ -217,1 +218,27 @@ * @return {Observable} | ||
}; | ||
var nodes; | ||
function getNodes (node, isAll) { | ||
if (!isAll && node.subscribers.length === 0) | ||
return nodes.push(node); | ||
node.subscribers.forEach(function (node) { | ||
if (isAll) nodes.push(node); | ||
getNodes(node, isAll); | ||
}); | ||
} | ||
/** | ||
* Subscribe a tree via a root observable. | ||
* @version_added 0.9.7 | ||
* @param {Observable} root | ||
* @param {Boolean} isAll Whether to subscribe the whole tree or just the leaves. | ||
* By default only leaves are subscribed. | ||
* @return {Observable} | ||
*/ | ||
Observable.tree = function (root, isAll) { | ||
nodes = []; | ||
getNodes(root, isAll); | ||
return Observable.all(nodes); | ||
}; |
/* | ||
Yaku v0.9.6 | ||
Yaku v0.9.7 | ||
(c) 2015 Yad Smood. http://ysmood.org | ||
@@ -4,0 +4,0 @@ License MIT |
{ | ||
"name": "yaku", | ||
"version": "0.9.6", | ||
"version": "0.9.7", | ||
"description": "A light-weight ES6 Promises/A+ implementation that doesn't hurt.", | ||
@@ -5,0 +5,0 @@ "main": "lib/yaku.js", |
@@ -812,4 +812,4 @@ <a href="http://promisesaplus.com/"> | ||
// Unsubscribe all children. | ||
linear.children = []; | ||
// Unsubscribe all subscribers. | ||
linear.subscribers = []; | ||
``` | ||
@@ -855,11 +855,11 @@ | ||
- ### **[parent](src/Observable.js?source#L92)** | ||
- ### **[publisher](src/Observable.js?source#L92)** | ||
The parent observable of this. | ||
The publisher observable of this. | ||
- **<u>type</u>**: { _Observable_ } | ||
- ### **[children](src/Observable.js?source#L98)** | ||
- ### **[subscribers](src/Observable.js?source#L98)** | ||
All the children subscribed this observable. | ||
All the subscribers subscribed this observable. | ||
@@ -882,6 +882,10 @@ - **<u>type</u>**: { _Array_ } | ||
- ### **[Observable.all(iterable)](src/Observable.js?source#L175)** | ||
- ### **[Observable.all(iterable)](src/Observable.js?source#L176)** | ||
Merge multiple observables into one. | ||
- **<u>version_added</u>**: | ||
0.9.6 | ||
- **<u>param</u>**: `iterable` { _Iterable_ } | ||
@@ -913,6 +917,23 @@ | ||
- ### **[Observable.tree(root, isAll)](src/Observable.js?source#L232)** | ||
Subscribe a tree via a root observable. | ||
- **<u>version_added</u>**: | ||
0.9.7 | ||
- **<u>param</u>**: `root` { _Observable_ } | ||
- **<u>param</u>**: `isAll` { _Boolean_ } | ||
Whether to subscribe the whole tree or just the leaves. | ||
By default only leaves are subscribed. | ||
- **<u>return</u>**: { _Observable_ } | ||
# Unit Test | ||
@@ -919,0 +940,0 @@ |
75269
1425
971
148669