ArchStream

WIP
Modular stream for domain and data oriented program architecture design.
API
dist/arch-stream.d.ts
- ArchStream
- Message
- Proxy
- Tick
Install
$ npm i arch-stream
Usage
import A, {Msg} from 'arch-stream';
export default A<Entity>()
.pipe(e => Msg().send(e))
.export();
import A from 'arch-stream';
import app from './app/main';
export default A<Entity>()
.import(app)
.export();
import model from './model/main';
model.read(e => console.log(e));
model.write(new Entity());
API
Thenable data cannot send directly.
Modular stream
import ArchStream from 'arch-stream';
const add1 =
ArchStream<{val: number}>()
.pipe(e => ++e.val)
.export(Infinity),
add2 =
ArchStream<{val: number}>()
.import(add1)
.import(add1)
.export(Infinity),
add3 =
ArchStream<{val: number}>()
.import(add1)
.import(add2)
.export();
ArchStream<{val: number}>()
.import(add1)
.import(add2)
.import(add3)
.export()
.read(e => console.log(e.val))
.write({val: 0})
.write({val: 9});
Thenable
import A from 'arch-stream';
A<{val: number}>()
.pipe(e => new Promise(resolve => resolve(++e.val)))
.pipe(e => A.Msg().send(++e.val, true))
.pipe(e => A.Msg().send(++e.val))
.export()
.read(n => console.log(n))
.write({val: 1})
.write({val: 2});
Proxy
Case
import A from 'arch-stream';
A<{val: number}>()
.proxy(A.Proxy.Case({index: [0, 1], indexer: e => e.val % 2}))
.pipe(_ => _, e => e.val = -e.val)
.export()
.read(e => console.log(e.val))
.write({val: 1})
.write({val: 2});
Hook
Responsibility
Call order constraints (Type constraint)
Possible
- pipe > pipe
- pipe > export
- pipe > proxy
- proxy > pipe
- proxy > proxy
- import > import
- import > export
- export > flow
- export > read
- read > write
- flow > read
Impossible
- pipe > import
- pipe > read
- proxy -> import
- import > pipe
- import > read
- export > pipe
- export > import
- read > read
- write > read
- read > flow
Browser
Test
$ npm i && gulp install
$ gulp test
$ gulp bench