Skip to content

Commit

Permalink
feat(rstream-csp): add new package, remove CSP dep from rstream
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 28, 2018
1 parent c74353b commit e37f6a1
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 6 deletions.
49 changes: 49 additions & 0 deletions packages/rstream-csp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# @thi.ng/rstream-csp

[![npm (scoped)](https://img.shields.io/npm/v/@thi.ng/rstream-csp.svg)](https://www.npmjs.com/package/@thi.ng/rstream-csp)

## About

Adapter bridge between async [CSP
channels](https://github.com/thi-ng/umbrella/tree/master/packages/csp) and
synchronous stream subscriptions/transformations of
[@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/master/packages/rstream).

## Installation

```
yarn add @thi.ng/rstream-csp
```

## Usage examples

```typescript
import * as rs from "@thi.ng/rstream";
import { fromChannel } from "@thi.ng/rstream-csp";
import { Channel } from "@thi.ng/csp";

ch = new Channel();
stream = fromChannel(ch);

stream.subscribe(rs.trace("all"));
stream.subscribe(rs.trace("only evens"), tx.filter(tx.even));

ch.write(1);
// all 1

ch.write(2);
// all 2
// only evens 2

stream.subscribe(rs.trace("tentimes"), tx.map(x => x * 10));
// all 3
// tentimes 30
```

## Authors

- Karsten Schmidt <[email protected]>

## License

&copy; 2018 Karsten Schmidt <[email protected]> // Apache Software License 2.0
40 changes: 40 additions & 0 deletions packages/rstream-csp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@thi.ng/rstream-csp",
"version": "0.0.1",
"description": "TODO",
"main": "./index.js",
"typings": "./index.d.ts",
"repository": "https://github.com/thi-ng/umbrella",
"author": "Karsten Schmidt <[email protected]>",
"license": "Apache-2.0",
"scripts": {
"build": "yarn run clean && tsc --declaration",
"test": "yarn run clean && tsc -p test && mocha build/test/*.js",
"clean": "rm -rf *.js *.d.ts build doc",
"pub": "yarn run build && yarn publish --access public"
},
"devDependencies": {
"@types/mocha": "^2.2.46",
"@types/node": "^9.3.0",
"mocha": "^5.0.0",
"ts-loader": "^3.3.1",
"typedoc": "^0.9.0",
"typescript": "^2.6.2",
"webpack": "^3.10.0"
},
"dependencies": {
"@thi.ng/api": "^1.2.1",
"@thi.ng/rstream": "^0.5.1"
},
"keywords": [
"bridge",
"csp",
"reactive",
"stream",
"ES6",
"typescript"
],
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Channel } from "@thi.ng/csp/channel";

import { DEBUG } from "../api";
import { Stream } from "../stream";
import { Stream } from "@thi.ng/rstream/stream";
import { DEBUG } from "@thi.ng/rstream/api";

/**
*
Expand Down
1 change: 1 addition & 0 deletions packages/rstream-csp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./from/channel";
26 changes: 26 additions & 0 deletions packages/rstream-csp/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as csp from "@thi.ng/csp";
import * as rs from "@thi.ng/rstream";
import * as assert from "assert";

import { fromChannel } from "../src/index";

describe("fromChannel", function () {

it("receives all values", (done) => {
let ch = csp.Channel.range(5);
let src = fromChannel(ch);
let buf = [];
src.subscribe({
next(x) {
buf.push(x);
},
done() {
assert.deepEqual(buf, [0, 1, 2, 3, 4]);
assert(ch.isClosed(), "channel not closed");
assert.equal(src.getState(), rs.State.DONE, "stream not done");
done();
}
});
});

});
10 changes: 10 additions & 0 deletions packages/rstream-csp/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../build",
},
"include": [
"./**/*.ts",
"../src/**/*.ts"
]
}
9 changes: 9 additions & 0 deletions packages/rstream-csp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "."
},
"include": [
"./src/**/*.ts",
]
}
2 changes: 0 additions & 2 deletions packages/rstream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
},
"dependencies": {
"@thi.ng/api": "^1.2.1",
"@thi.ng/csp": "^0.3.2",
"@thi.ng/dcons": "^0.1.4",
"@thi.ng/transducers": "^0.11.2"
},
"keywords": [
Expand Down
1 change: 0 additions & 1 deletion packages/rstream/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from "./stream";
export * from "./stream-merge";
export * from "./subscription";

export * from "./from/channel";
export * from "./from/event";
export * from "./from/interval";
export * from "./from/iterable";
Expand Down

0 comments on commit e37f6a1

Please sign in to comment.