diff --git a/src/Machine.ts b/src/Producer.ts similarity index 76% rename from src/Machine.ts rename to src/Producer.ts index ad641b5..52581a0 100644 --- a/src/Machine.ts +++ b/src/Producer.ts @@ -1,6 +1,6 @@ import {Observer} from './Observer'; -export interface Machine { +export interface Producer { start: (observer: Observer) => void; stop: () => void; } diff --git a/src/Stream.ts b/src/Stream.ts index bdbd843..0aabf04 100644 --- a/src/Stream.ts +++ b/src/Stream.ts @@ -1,18 +1,18 @@ import {Observer} from './Observer'; -import {Machine} from './Machine'; -import {MapMachine} from './operator/MapMachine'; -import {FilterMachine} from './operator/FilterMachine'; -import {TakeMachine} from './operator/TakeMachine'; -import {SkipMachine} from './operator/SkipMachine'; -import {DebugMachine} from './operator/DebugMachine'; -import {FoldMachine} from './operator/FoldMachine'; -import {LastMachine} from './operator/LastMachine'; +import {Producer} from './Producer'; +import {MapProducer} from './operator/MapProducer'; +import {FilterProducer} from './operator/FilterProducer'; +import {TakeProducer} from './operator/TakeProducer'; +import {SkipProducer} from './operator/SkipProducer'; +import {DebugProducer} from './operator/DebugProducer'; +import {FoldProducer} from './operator/FoldProducer'; +import {LastProducer} from './operator/LastProducer'; export class Stream implements Observer { public observers: Array>; public num: number; // Number of non-operator subscribers - constructor(public machine: Machine) { + constructor(public machine: Producer) { this.observers = []; this.num = 0; } @@ -64,30 +64,30 @@ export class Stream implements Observer { } map(project: (t: T) => U): Stream { - return new Stream(new MapMachine(project, this)); + return new Stream(new MapProducer(project, this)); } filter(predicate: (t: T) => boolean): Stream { - return new Stream(new FilterMachine(predicate, this)); + return new Stream(new FilterProducer(predicate, this)); } take(amount: number): Stream { - return new Stream(new TakeMachine(amount, this)); + return new Stream(new TakeProducer(amount, this)); } skip(amount: number): Stream { - return new Stream(new SkipMachine(amount, this)); + return new Stream(new SkipProducer(amount, this)); } debug(spy: (t: T) => void = null): Stream { - return new Stream(new DebugMachine(spy, this)); + return new Stream(new DebugProducer(spy, this)); } fold(accumulate: (acc: R, t: T) => R, init: R): Stream { - return new Stream(new FoldMachine(accumulate, init, this)); + return new Stream(new FoldProducer(accumulate, init, this)); } last(): Stream { - return new Stream(new LastMachine(this)); + return new Stream(new LastProducer(this)); } } diff --git a/src/factory/from.ts b/src/factory/from.ts index 47b5954..029a7d3 100644 --- a/src/factory/from.ts +++ b/src/factory/from.ts @@ -1,9 +1,9 @@ -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Observer} from '../Observer'; import {Stream} from '../Stream'; import {noop} from '../utils/noop'; -class FromMachine implements Machine { +class FromProducer implements Producer { constructor(public array: Array) { } @@ -22,6 +22,6 @@ class FromMachine implements Machine { } export default function from(array: Array) { - const fromMachine = new FromMachine(array); - return new Stream(fromMachine); + const fromProducer = new FromProducer(array); + return new Stream(fromProducer); } diff --git a/src/factory/interval.ts b/src/factory/interval.ts index 9ef7ff2..aff307c 100644 --- a/src/factory/interval.ts +++ b/src/factory/interval.ts @@ -1,8 +1,8 @@ -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Observer} from '../Observer'; import {Stream} from '../Stream'; -class IntervalMachine implements Machine { +class IntervalProducer implements Producer { on: boolean; intervalID: any; i: number; @@ -25,6 +25,6 @@ class IntervalMachine implements Machine { } export default function interval(period: number) { - const intervalMachine = new IntervalMachine(period); - return new Stream(intervalMachine); + const intervalProducer = new IntervalProducer(period); + return new Stream(intervalProducer); } diff --git a/src/operator/DebugMachine.ts b/src/operator/DebugProducer.ts similarity index 87% rename from src/operator/DebugMachine.ts rename to src/operator/DebugProducer.ts index 7d451a7..d66cf65 100644 --- a/src/operator/DebugMachine.ts +++ b/src/operator/DebugProducer.ts @@ -1,9 +1,9 @@ import {Observer} from '../Observer'; -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Stream} from '../Stream'; import {emptyObserver} from '../utils/emptyObserver'; -export class DebugMachine implements Machine { +export class DebugProducer implements Producer { public proxy: Observer = emptyObserver; constructor(public spy: (t: T) => void = null, diff --git a/src/operator/FilterMachine.ts b/src/operator/FilterProducer.ts similarity index 77% rename from src/operator/FilterMachine.ts rename to src/operator/FilterProducer.ts index 0ba8047..3e3d4ca 100644 --- a/src/operator/FilterMachine.ts +++ b/src/operator/FilterProducer.ts @@ -1,15 +1,15 @@ import {Observer} from '../Observer'; -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Stream} from '../Stream'; import {emptyObserver} from '../utils/emptyObserver'; export class Proxy implements Observer { constructor(public out: Stream, - public machine: FilterMachine) { + public p: FilterProducer) { } next(t: T) { - if (this.machine.predicate(t)) this.out.next(t); + if (this.p.predicate(t)) this.out.next(t); } error(err: any) { @@ -21,7 +21,7 @@ export class Proxy implements Observer { } } -export class FilterMachine implements Machine { +export class FilterProducer implements Producer { public proxy: Observer = emptyObserver; constructor(public predicate: (t: T) => boolean, diff --git a/src/operator/FoldMachine.ts b/src/operator/FoldProducer.ts similarity index 78% rename from src/operator/FoldMachine.ts rename to src/operator/FoldProducer.ts index e8fa517..efea7e9 100644 --- a/src/operator/FoldMachine.ts +++ b/src/operator/FoldProducer.ts @@ -1,16 +1,16 @@ import {Observer} from '../Observer'; -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Stream} from '../Stream'; import {emptyObserver} from '../utils/emptyObserver'; export class Proxy implements Observer { constructor(public out: Stream, - public m: FoldMachine) { + public p: FoldProducer) { } next(t: T) { - const m = this.m; - this.out.next(m.acc = m.a(m.acc, t)); + const p = this.p; + this.out.next(p.acc = p.a(p.acc, t)); } error(err: any) { @@ -22,7 +22,7 @@ export class Proxy implements Observer { } } -export class FoldMachine implements Machine { +export class FoldProducer implements Producer { public proxy: Observer = emptyObserver; public acc: R; diff --git a/src/operator/LastMachine.ts b/src/operator/LastProducer.ts similarity index 73% rename from src/operator/LastMachine.ts rename to src/operator/LastProducer.ts index 9fd9b7e..e3de0e8 100644 --- a/src/operator/LastMachine.ts +++ b/src/operator/LastProducer.ts @@ -1,17 +1,17 @@ import {Observer} from '../Observer'; -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Stream} from '../Stream'; import {emptyObserver} from '../utils/emptyObserver'; export class Proxy implements Observer { constructor(public out: Stream, - public machine: LastMachine) { + public p: LastProducer) { } next(t: T) { - const m = this.machine; - m.has = true; - m.val = t; + const p = this.p; + p.has = true; + p.val = t; } error(err: any) { @@ -19,10 +19,10 @@ export class Proxy implements Observer { } complete() { - const m = this.machine; + const p = this.p; const out = this.out; - if (m.has) { - out.next(m.val); + if (p.has) { + out.next(p.val); out.complete(); } else { out.error('TODO show proper error'); @@ -30,7 +30,7 @@ export class Proxy implements Observer { } } -export class LastMachine implements Machine { +export class LastProducer implements Producer { public proxy: Observer = emptyObserver; public has: boolean = false; public val: T = {}; diff --git a/src/operator/MapMachine.ts b/src/operator/MapProducer.ts similarity index 77% rename from src/operator/MapMachine.ts rename to src/operator/MapProducer.ts index ff6304a..ad89974 100644 --- a/src/operator/MapMachine.ts +++ b/src/operator/MapProducer.ts @@ -1,15 +1,15 @@ import {Observer} from '../Observer'; -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Stream} from '../Stream'; import {emptyObserver} from '../utils/emptyObserver'; export class Proxy implements Observer { constructor(public out: Stream, - public machine: MapMachine) { + public p: MapProducer) { } next(t: T) { - this.out.next(this.machine.project(t)); + this.out.next(this.p.project(t)); } error(err: any) { @@ -21,7 +21,7 @@ export class Proxy implements Observer { } } -export class MapMachine implements Machine { +export class MapProducer implements Producer { public proxy: Observer = emptyObserver; constructor(public project: (t: T) => U, diff --git a/src/operator/SkipMachine.ts b/src/operator/SkipProducer.ts similarity index 86% rename from src/operator/SkipMachine.ts rename to src/operator/SkipProducer.ts index d804b8c..63898c9 100644 --- a/src/operator/SkipMachine.ts +++ b/src/operator/SkipProducer.ts @@ -1,9 +1,9 @@ import {Observer} from '../Observer'; -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Stream} from '../Stream'; import {emptyObserver} from '../utils/emptyObserver'; -export class SkipMachine implements Machine { +export class SkipProducer implements Producer { public proxy: Observer = emptyObserver; public skipped: number = 0; diff --git a/src/operator/TakeMachine.ts b/src/operator/TakeProducer.ts similarity index 88% rename from src/operator/TakeMachine.ts rename to src/operator/TakeProducer.ts index b33198f..af13eed 100644 --- a/src/operator/TakeMachine.ts +++ b/src/operator/TakeProducer.ts @@ -1,9 +1,9 @@ import {Observer} from '../Observer'; -import {Machine} from '../Machine'; +import {Producer} from '../Producer'; import {Stream} from '../Stream'; import {emptyObserver} from '../utils/emptyObserver'; -export class TakeMachine implements Machine { +export class TakeProducer implements Producer { public proxy: Observer = emptyObserver; public taken: number = 0;