Comparing version 0.8.0 to 0.9.1
@@ -15,3 +15,3 @@ // This file contains all the non-ES6-standard helpers based on promise. | ||
* Promise.resolve(0), | ||
* Promise.reject(1) | ||
* Promise.reject(new Error("ERR")) | ||
* ]) | ||
@@ -202,18 +202,24 @@ * .then((value) => { | ||
/** | ||
* Create a composable event source function. | ||
* Create a composable observable object. | ||
* Promise can't resolve multiple times, this function makes it possible, so | ||
* that you can easily map, filter and debounce events in a promise way. | ||
* that you can easily map, filter and even back pressure events in a promise way. | ||
* For real world example: [Double Click Demo](https://jsfiddle.net/ysmood/musds0sv/). | ||
* @version_added v0.7.2 | ||
* @param {Function} executor `(emit) ->` It's optional. | ||
* @return {Function} `(onEmit, onError) ->` The function's | ||
* members: | ||
* @return {Object} The observable object's members: | ||
* ```js | ||
* { | ||
* emit: (value) => { \/* ... *\/ }, | ||
* // It will create a new Observable, like promise. | ||
* subscribe: (onEmit, onError) => Observable, | ||
* | ||
* // Get current value from it. | ||
* value: Promise, | ||
* // Unsubscribe this. | ||
* unsubscribe: () => {}, | ||
* | ||
* // All the children spawned from current source. | ||
* // Emit a value | ||
* emit: (value) => {}, | ||
* | ||
* // The parent observable of this. | ||
* parent: Observable || null, | ||
* | ||
* // All the children subscribed this observable. | ||
* children: Array | ||
@@ -224,12 +230,10 @@ * } | ||
* ```js | ||
* var source = require("yaku/lib/source"); | ||
* var linear = source(); | ||
* var Observable = require("yaku/lib/Observable"); | ||
* var linear = new Observable(); | ||
* | ||
* var x = 0; | ||
* setInterval(() => { | ||
* linear.emit(x++); | ||
* }, 1000); | ||
* setInterval(linear.emit, 1000, x++); | ||
* | ||
* // Wait for a moment then emit the value. | ||
* var quad = linear(async x => { | ||
* var quad = linear.subscribe(async x => { | ||
* await sleep(2000); | ||
@@ -239,5 +243,5 @@ * return x * x; | ||
* | ||
* var another = linear(x => -x); | ||
* var another = linear.subscribe(x => -x); | ||
* | ||
* quad( | ||
* quad.subscribe( | ||
* value => { console.log(value); }, | ||
@@ -248,8 +252,8 @@ * reason => { console.error(reason); } | ||
* // Emit error | ||
* linear.emit(Promise.reject("reason")); | ||
* linear.emit(Promise.reject(new Error("reason"))); | ||
* | ||
* // Dispose a specific source. | ||
* linear.children.splice(linear.children.indexOf(quad)); | ||
* // Unsubscribe a observable. | ||
* quad.unsubscribe(); | ||
* | ||
* // Dispose all children. | ||
* // Unsubscribe all children. | ||
* linear.children = []; | ||
@@ -262,12 +266,12 @@ * ``` | ||
* | ||
* var keyup = source((emit) => { | ||
* var keyup = new Observable((emit) => { | ||
* document.querySelector('input').onkeyup = emit; | ||
* }); | ||
* | ||
* var keyupText = keyup(e => e.target.value); | ||
* var keyupText = keyup.subscribe(e => e.target.value); | ||
* | ||
* // Now we only get the input when the text length is greater than 3. | ||
* var keyupTextGT3 = keyupText(filter(text => text.length > 3)); | ||
* var keyupTextGT3 = keyupText.subscribe(filter(text => text.length > 3)); | ||
* | ||
* keyupTextGT3(v => console.log(v)); | ||
* keyupTextGT3.subscribe(v => console.log(v)); | ||
* ``` | ||
@@ -277,11 +281,13 @@ * @example | ||
* ```js | ||
* let one = source(emit => setInterval(emit, 100, 'one')); | ||
* let two = source(emit => setInterval(emit, 200, 'two')); | ||
* let merge = arr => arr.forEach(src => src(emit)); | ||
* let one = new Observable(emit => setInterval(emit, 100, 'one')); | ||
* let two = new Observable(emit => setInterval(emit, 200, 'two')); | ||
* let merge = list => new Observable( | ||
* (emit) => list.forEach(o => o.subscribe(emit)) | ||
* ); | ||
* | ||
* let three = merge([one, two]); | ||
* three(v => console.log(v)); | ||
* three.subscribe(v => console.log(v)); | ||
* ``` | ||
*/ | ||
source: require("./source"), | ||
Observable: require("./Observable"), | ||
@@ -288,0 +294,0 @@ /** |
/* | ||
Yaku v0.8.0 | ||
Yaku v0.9.1 | ||
(c) 2015 Yad Smood. http://ysmood.org | ||
@@ -123,3 +123,3 @@ License MIT | ||
* var Promise = require('yaku'); | ||
* var p = Promise.reject(10); | ||
* var p = Promise.reject(new Error("ERR")); | ||
* | ||
@@ -172,3 +172,3 @@ * p['catch']((v) => { | ||
* var Promise = require('yaku'); | ||
* var p = Promise.reject(10); | ||
* var p = Promise.reject(new Error("ERR")); | ||
* ``` | ||
@@ -175,0 +175,0 @@ */ |
{ | ||
"name": "yaku", | ||
"version": "0.8.0", | ||
"version": "0.9.1", | ||
"description": "A light-weight ES6 Promises/A+ implementation that doesn't hurt.", | ||
@@ -5,0 +5,0 @@ "main": "lib/yaku.js", |
@@ -234,3 +234,3 @@ <a href="http://promisesaplus.com/"> | ||
var Promise = require('yaku'); | ||
var p = Promise.reject(10); | ||
var p = Promise.reject(new Error("ERR")); | ||
@@ -276,3 +276,3 @@ p['catch']((v) => { | ||
var Promise = require('yaku'); | ||
var p = Promise.reject(10); | ||
var p = Promise.reject(new Error("ERR")); | ||
``` | ||
@@ -449,3 +449,3 @@ | ||
Promise.resolve(0), | ||
Promise.reject(1) | ||
Promise.reject(new Error("ERR")) | ||
]) | ||
@@ -676,7 +676,7 @@ .then((value) => { | ||
- ### **[source(executor)](src/utils.js?source#L279)** | ||
- ### **[Observable(executor)](src/utils.js?source#L285)** | ||
Create a composable event source function. | ||
Create a composable observable object. | ||
Promise can't resolve multiple times, this function makes it possible, so | ||
that you can easily map, filter and debounce events in a promise way. | ||
that you can easily map, filter and even back pressure events in a promise way. | ||
For real world example: [Double Click Demo](https://jsfiddle.net/ysmood/musds0sv/). | ||
@@ -692,14 +692,20 @@ | ||
- **<u>return</u>**: { _Function_ } | ||
- **<u>return</u>**: { _Object_ } | ||
`(onEmit, onError) ->` The function's | ||
members: | ||
The observable object's members: | ||
```js | ||
{ | ||
emit: (value) => { /* ... */ }, | ||
// It will create a new Observable, like promise. | ||
subscribe: (onEmit, onError) => Observable, | ||
// Get current value from it. | ||
value: Promise, | ||
// Unsubscribe this. | ||
unsubscribe: () => {}, | ||
// All the children spawned from current source. | ||
// Emit a value | ||
emit: (value) => {}, | ||
// The parent observable of this. | ||
parent: Observable || null, | ||
// All the children subscribed this observable. | ||
children: Array | ||
@@ -712,12 +718,10 @@ } | ||
```js | ||
var source = require("yaku/lib/source"); | ||
var linear = source(); | ||
var Observable = require("yaku/lib/Observable"); | ||
var linear = new Observable(); | ||
var x = 0; | ||
setInterval(() => { | ||
linear.emit(x++); | ||
}, 1000); | ||
setInterval(linear.emit, 1000, x++); | ||
// Wait for a moment then emit the value. | ||
var quad = linear(async x => { | ||
var quad = linear.subscribe(async x => { | ||
await sleep(2000); | ||
@@ -727,5 +731,5 @@ return x * x; | ||
var another = linear(x => -x); | ||
var another = linear.subscribe(x => -x); | ||
quad( | ||
quad.subscribe( | ||
value => { console.log(value); }, | ||
@@ -736,8 +740,8 @@ reason => { console.error(reason); } | ||
// Emit error | ||
linear.emit(Promise.reject("reason")); | ||
linear.emit(Promise.reject(new Error("reason"))); | ||
// Dispose a specific source. | ||
linear.children.splice(linear.children.indexOf(quad)); | ||
// Unsubscribe a observable. | ||
quad.unsubscribe(); | ||
// Dispose all children. | ||
// Unsubscribe all children. | ||
linear.children = []; | ||
@@ -752,12 +756,12 @@ ``` | ||
var keyup = source((emit) => { | ||
var keyup = new Observable((emit) => { | ||
document.querySelector('input').onkeyup = emit; | ||
}); | ||
var keyupText = keyup(e => e.target.value); | ||
var keyupText = keyup.subscribe(e => e.target.value); | ||
// Now we only get the input when the text length is greater than 3. | ||
var keyupTextGT3 = keyupText(filter(text => text.length > 3)); | ||
var keyupTextGT3 = keyupText.subscribe(filter(text => text.length > 3)); | ||
keyupTextGT3(v => console.log(v)); | ||
keyupTextGT3.subscribe(v => console.log(v)); | ||
``` | ||
@@ -769,11 +773,13 @@ | ||
```js | ||
let one = source(emit => setInterval(emit, 100, 'one')); | ||
let two = source(emit => setInterval(emit, 200, 'two')); | ||
let merge = arr => arr.forEach(src => src(emit)); | ||
let one = new Observable(emit => setInterval(emit, 100, 'one')); | ||
let two = new Observable(emit => setInterval(emit, 200, 'two')); | ||
let merge = list => new Observable( | ||
(emit) => list.forEach(o => o.subscribe(emit)) | ||
); | ||
let three = merge([one, two]); | ||
three(v => console.log(v)); | ||
three.subscribe(v => console.log(v)); | ||
``` | ||
- ### **[retry(countdown, fn, this)](src/utils.js?source#L328)** | ||
- ### **[retry(countdown, fn, this)](src/utils.js?source#L334)** | ||
@@ -845,3 +851,3 @@ Retry a function until it resolves before a mount of times, or reject with all | ||
- ### **[throw(err)](src/utils.js?source#L342)** | ||
- ### **[throw(err)](src/utils.js?source#L348)** | ||
@@ -848,0 +854,0 @@ Throw an error to break the program. |
1334
897
71655
21