-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rstream-csp): add new package, remove CSP dep from rstream
- Loading branch information
1 parent
c74353b
commit e37f6a1
Showing
9 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
© 2018 Karsten Schmidt <[email protected]> // Apache Software License 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
packages/rstream/src/from/channel.ts → packages/rstream-csp/src/from/channel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./from/channel"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../build", | ||
}, | ||
"include": [ | ||
"./**/*.ts", | ||
"../src/**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "." | ||
}, | ||
"include": [ | ||
"./src/**/*.ts", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters