Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/rstream

Package Overview
Dependencies
Maintainers
1
Versions
399
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/rstream - npm Package Compare versions

Comparing version 0.9.4 to 1.0.0

17

CHANGELOG.md

@@ -6,2 +6,19 @@ # Change Log

<a name="1.0.0"></a>
# [1.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream@0.9.4...@thi.ng/rstream@1.0.0) (2018-02-18)
### Features
* **rstream:** fix [#8](https://github.com/thi-ng/umbrella/issues/8), support infinite StreamMerge's, update ctor ([4942e2e](https://github.com/thi-ng/umbrella/commit/4942e2e))
### BREAKING CHANGES
* **rstream:** StreamMerge ctor now accepts an options object
only (`StreamMergeOpts`).
<a name="0.9.4"></a>

@@ -8,0 +25,0 @@ ## [0.9.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream@0.9.3...@thi.ng/rstream@0.9.4) (2018-02-08)

16

package.json
{
"name": "@thi.ng/rstream",
"version": "0.9.4",
"version": "1.0.0",
"description": "Reactive multi-tap streams & transformation pipeline constructs",

@@ -19,14 +19,14 @@ "main": "./index.js",

"devDependencies": {
"@types/mocha": "^2.2.46",
"@types/node": "^9.3.0",
"@types/mocha": "^2.2.48",
"@types/node": "^9.4.6",
"mocha": "^5.0.0",
"nyc": "^11.4.1",
"ts-loader": "^3.3.1",
"ts-loader": "^3.5.0",
"typedoc": "^0.10.0",
"typescript": "^2.7.1",
"webpack": "^3.10.0"
"typescript": "^2.7.2",
"webpack": "^3.11.0"
},
"dependencies": {
"@thi.ng/atom": "^0.5.3",
"@thi.ng/transducers": "^1.1.0"
"@thi.ng/atom": "^0.6.0",
"@thi.ng/transducers": "^1.2.0"
},

@@ -33,0 +33,0 @@ "keywords": [

@@ -77,7 +77,9 @@ # @thi.ng/rstream

```typescript
new rs.StreamMerge([
rs.fromEvent(document, "mousemove"),
rs.fromEvent(document, "mousedown"),
rs.fromEvent(document, "mouseup"),
])
new rs.StreamMerge({
src: [
rs.fromEvent(document, "mousemove"),
rs.fromEvent(document, "mousedown"),
rs.fromEvent(document, "mouseup"),
]
})
// add event transformer

@@ -101,3 +103,3 @@ .subscribe(tx.map((e) => [e.type, [e.clientX, e.clientY]]))

// central app state / single source of truth
const app = new atom.Atom({ui: {theme: "dark", mode: false}, foo: "bar"});
const app = new atom.Atom({ ui: { theme: "dark", mode: false}, foo: "bar" });

@@ -139,4 +141,4 @@ // define some cursors for different UI params

// update another part of the app state (SPREAD, DON'T MUTATE!)
app.swap((state) => ({...state, session: {user: "asterix"}}));
// update another part of the app state (DON'T MUTATE!)
app.swap((state) => atom.setIn(state, "session.user", "asterix"));
// user: asterix

@@ -143,0 +145,0 @@ // { ui: { theme: 'light', mode: false },

@@ -0,12 +1,26 @@

import { IID } from "@thi.ng/api/api";
import { Transducer } from "@thi.ng/transducers/api";
import { ISubscribable } from "./api";
import { Subscription } from "./subscription";
export interface StreamMergeOpts<A, B> extends IID<string> {
src: Iterable<ISubscribable<A>>;
xform: Transducer<A, B>;
close: boolean;
}
/**
* Subscription type consuming inputs from multiple inputs and passing
* received values on to any subscribers. Input streams can be added and
* removed dynamically. By default, the StreamMerge calls `done()` when
* the last active input is done, but this behavior can be overridden via
* the `close` constructor option (set to `false`).
*/
export declare class StreamMerge<A, B> extends Subscription<A, B> {
sources: ISubscribable<A>[];
wrappedSources: Subscription<A, any>[];
constructor(sources: Iterable<ISubscribable<A>>, id?: string);
constructor(xform: Transducer<A, B>, id?: string);
constructor(sources: Iterable<ISubscribable<A>>, xform: Transducer<A, B>, id?: string);
autoClose: boolean;
constructor(opts?: Partial<StreamMergeOpts<A, B>>);
add(src: ISubscribable<A>): void;
addAll(src: Iterable<ISubscribable<A>>): void;
remove(src: ISubscribable<A>): void;
removeAll(src: Iterable<ISubscribable<A>>): void;
unsubscribe(sub?: Subscription<B, any>): any;

@@ -13,0 +27,0 @@ done(): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_function_1 = require("@thi.ng/checks/is-function");
const is_string_1 = require("@thi.ng/checks/is-string");
const api_1 = require("./api");
const subscription_1 = require("./subscription");
/**
* Subscription type consuming inputs from multiple inputs and passing
* received values on to any subscribers. Input streams can be added and
* removed dynamically. By default, the StreamMerge calls `done()` when
* the last active input is done, but this behavior can be overridden via
* the `close` constructor option (set to `false`).
*/
class StreamMerge extends subscription_1.Subscription {
constructor(...args) {
let id = is_string_1.isString(args[args.length - 1]) ? args.pop() : `streammerge-${subscription_1.Subscription.NEXT_ID++}`;
let src, xform;
switch (args.length) {
case 2:
src = args[0];
xform = args[1];
break;
case 1:
if (is_function_1.isFunction(args[0])) {
xform = args[0];
}
else {
src = args[0];
}
break;
default:
throw new Error(`illegal arity ${args.length}`);
}
super(null, xform, null, id);
constructor(opts) {
opts = opts || {};
super(null, opts.xform, null, opts.id || `streammerge-${subscription_1.Subscription.NEXT_ID++}`);
this.sources = [];
this.wrappedSources = [];
if (src) {
for (let s of src) {
this.add(s);
}
this.autoClose = opts.close !== false;
if (opts.src) {
this.addAll(opts.src);
}

@@ -38,3 +25,2 @@ }

this.ensureState();
this.sources.push(src);
this.wrappedSources.push(src.subscribe({

@@ -44,3 +30,9 @@ next: (x) => this.next(x),

}));
this.sources.push(src);
}
addAll(src) {
for (let s of src) {
this.add(s);
}
}
remove(src) {

@@ -54,2 +46,7 @@ const idx = this.sources.indexOf(src);

}
removeAll(src) {
for (let s of src) {
this.remove(s);
}
}
unsubscribe(sub) {

@@ -79,3 +76,3 @@ if (!sub) {

this.remove(src);
if (!this.sources.length) {
if (this.autoClose && !this.sources.length) {
this.done();

@@ -82,0 +79,0 @@ }

@@ -70,5 +70,3 @@ "use strict";

}
else {
throw new Error("subscription has no parent");
}
return true;
}

@@ -75,0 +73,0 @@ if (this.subs) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc