Comparing version 5.2.4 to 5.3.0
@@ -0,1 +1,26 @@ | ||
<a name="5.3.0"></a> | ||
# [5.3.0](https://github.com/staltz/xstream/compare/v5.2.4...v5.3.0) (2016-07-22) | ||
### Features | ||
* **fromEvent:** Aggregate multiple arguments ([714dd01](https://github.com/staltz/xstream/commit/714dd01)), closes [staltz/xstream#84](https://github.com/staltz/xstream/issues/84) [#89](https://github.com/staltz/xstream/issues/89) | ||
### BREAKING CHANGES | ||
* fromEvent: . | ||
2. An expanded function signature would become 'crowded', and one of | ||
the architectural goals of xstream is to keep interfaces as small | ||
as they need to be to achieve their goals. | ||
3. Aggregating emitted events into an array is consistent with the | ||
implementation in Most.js, and achieves similar flexibility with Rx | ||
when providing a selector function to `.map()` on a result stream. | ||
`fromEvent` will now emit mixed-types. If consumers are not responsible | ||
for calling `.emit()` on the source emitter, they should implement | ||
appropriate guards to ensure they are dealing with an intended type. | ||
<a name="5.2.4"></a> | ||
@@ -2,0 +27,0 @@ ## [5.2.4](https://github.com/staltz/xstream/compare/v5.2.3...v5.2.4) (2016-07-20) |
@@ -408,2 +408,6 @@ <!-- This EXTRA_DOCS.md file is automatically generated from source code and files in the /markdown directory. Please DO NOT send pull requests to directly modify this file. Instead, edit the JSDoc comments in source code or the md files in /markdown or the md.ejs files in /tools. --> | ||
When creating a stream from EventEmitters, if the source event has more than | ||
one argument all the arguments will be aggregated into an array in the | ||
result stream. | ||
Marble diagram: | ||
@@ -457,2 +461,22 @@ | ||
```js | ||
import fromEvent from 'xstream/extra/fromEvent' | ||
import {EventEmitter} from 'events' | ||
const MyEmitter = new EventEmitter() | ||
const stream = fromEvent(MyEmitter, 'foo') | ||
stream.addListener({ | ||
next: i => console.log(i), | ||
error: err => console.error(err), | ||
complete: () => console.log('completed') | ||
}) | ||
MyEmitter.emit('foo', 'bar', 'baz', 'buzz') | ||
``` | ||
```text | ||
> ['bar', 'baz', 'buzz'] | ||
``` | ||
#### Arguments: | ||
@@ -459,0 +483,0 @@ |
@@ -28,2 +28,6 @@ /// <reference path="../typings/globals/node/index.d.ts" /> | ||
* | ||
* When creating a stream from EventEmitters, if the source event has more than | ||
* one argument all the arguments will be aggregated into an array in the | ||
* result stream. | ||
* | ||
* Marble diagram: | ||
@@ -77,2 +81,22 @@ * | ||
* | ||
* ```js | ||
* import fromEvent from 'xstream/extra/fromEvent' | ||
* import {EventEmitter} from 'events' | ||
* | ||
* const MyEmitter = new EventEmitter() | ||
* const stream = fromEvent(MyEmitter, 'foo') | ||
* | ||
* stream.addListener({ | ||
* next: i => console.log(i), | ||
* error: err => console.error(err), | ||
* complete: () => console.log('completed') | ||
* }) | ||
* | ||
* MyEmitter.emit('foo', 'bar', 'baz', 'buzz') | ||
* ``` | ||
* | ||
* ```text | ||
* > ['bar', 'baz', 'buzz'] | ||
* ``` | ||
* | ||
* @param {EventTarget|EventEmitter} element The element upon which to listen. | ||
@@ -79,0 +103,0 @@ * @param {string} eventName The name of the event for which to listen. |
@@ -28,3 +28,9 @@ "use strict"; | ||
NodeEventProducer.prototype._start = function (out) { | ||
this.listener = function (e) { return out._n(e); }; | ||
this.listener = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i - 0] = arguments[_i]; | ||
} | ||
return (args.length > 1) ? out._n(args) : out._n(args[0]); | ||
}; | ||
this.node.addListener(this.eventName, this.listener); | ||
@@ -47,2 +53,6 @@ }; | ||
* | ||
* When creating a stream from EventEmitters, if the source event has more than | ||
* one argument all the arguments will be aggregated into an array in the | ||
* result stream. | ||
* | ||
* Marble diagram: | ||
@@ -96,2 +106,22 @@ * | ||
* | ||
* ```js | ||
* import fromEvent from 'xstream/extra/fromEvent' | ||
* import {EventEmitter} from 'events' | ||
* | ||
* const MyEmitter = new EventEmitter() | ||
* const stream = fromEvent(MyEmitter, 'foo') | ||
* | ||
* stream.addListener({ | ||
* next: i => console.log(i), | ||
* error: err => console.error(err), | ||
* complete: () => console.log('completed') | ||
* }) | ||
* | ||
* MyEmitter.emit('foo', 'bar', 'baz', 'buzz') | ||
* ``` | ||
* | ||
* ```text | ||
* > ['bar', 'baz', 'buzz'] | ||
* ``` | ||
* | ||
* @param {EventTarget|EventEmitter} element The element upon which to listen. | ||
@@ -98,0 +128,0 @@ * @param {string} eventName The name of the event for which to listen. |
{ | ||
"name": "xstream", | ||
"version": "5.2.4", | ||
"version": "5.3.0", | ||
"description": "An extremely intuitive, small, and fast functional reactive stream library for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,3 +32,5 @@ /// <reference path="../../typings/globals/node/index.d.ts" /> | ||
_start(out: InternalListener<any>) { | ||
this.listener = (e: any) => out._n(e); | ||
this.listener = (...args: Array<any>) => { | ||
return (args.length > 1) ? out._n(args) : out._n(args[0]); | ||
}; | ||
this.node.addListener(this.eventName, this.listener); | ||
@@ -52,2 +54,6 @@ } | ||
* | ||
* When creating a stream from EventEmitters, if the source event has more than | ||
* one argument all the arguments will be aggregated into an array in the | ||
* result stream. | ||
* | ||
* Marble diagram: | ||
@@ -101,2 +107,22 @@ * | ||
* | ||
* ```js | ||
* import fromEvent from 'xstream/extra/fromEvent' | ||
* import {EventEmitter} from 'events' | ||
* | ||
* const MyEmitter = new EventEmitter() | ||
* const stream = fromEvent(MyEmitter, 'foo') | ||
* | ||
* stream.addListener({ | ||
* next: i => console.log(i), | ||
* error: err => console.error(err), | ||
* complete: () => console.log('completed') | ||
* }) | ||
* | ||
* MyEmitter.emit('foo', 'bar', 'baz', 'buzz') | ||
* ``` | ||
* | ||
* ```text | ||
* > ['bar', 'baz', 'buzz'] | ||
* ``` | ||
* | ||
* @param {EventTarget|EventEmitter} element The element upon which to listen. | ||
@@ -103,0 +129,0 @@ * @param {string} eventName The name of the event for which to listen. |
@@ -190,2 +190,23 @@ /// <reference path="../../typings/globals/mocha/index.d.ts" /> | ||
}); | ||
it('should aggregate arguments from emitters', (done) => { | ||
const target = new FakeEventEmitter(); | ||
const stream = fromEvent(target, 'test').take(2); | ||
let expected = [[1, 'foo', true], [2, 'bar', false]]; | ||
stream.addListener({ | ||
next: (x: any) => { | ||
assert.deepEqual(x, expected.shift()); | ||
}, | ||
error: (err: any) => done(err), | ||
complete: () => { | ||
assert.strictEqual(expected.length, 0); | ||
done(); | ||
} | ||
}); | ||
target.emit( 'test', 1, 'foo', true ); | ||
target.emit( 'test', 2, 'bar', false ); | ||
}); | ||
}); |
/// <reference path="globals/es6-promise/index.d.ts" /> | ||
/// <reference path="globals/mocha/index.d.ts" /> | ||
/// <reference path="globals/node/index.d.ts" /> | ||
/// <reference path="modules/sinon/index.d.ts" /> |
Sorry, the diff of this file is not supported yet
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
838296
146
16130