-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(operator): implement debug() operator with DebugMachine
- Loading branch information
Andre Medeiros
committed
Feb 25, 2016
1 parent
32dd8ac
commit e2a0342
Showing
3 changed files
with
57 additions
and
0 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
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,31 @@ | ||
import {Observer} from '../Observer'; | ||
import {Machine} from '../Machine'; | ||
import {Stream} from '../Stream'; | ||
|
||
export class DebugMachine<T> implements Machine<T> { | ||
public proxy: Observer<T>; | ||
|
||
constructor(public spy: (t: T) => void = null, | ||
public inStream: Stream<T>) { | ||
} | ||
|
||
start(outStream: Observer<T>): void { | ||
this.proxy = { | ||
next: (t: T) => { | ||
if (this.spy) { | ||
this.spy(t); | ||
} else { | ||
console.log(t); | ||
} | ||
outStream.next(t); | ||
}, | ||
error: outStream.error, | ||
complete: outStream.complete, | ||
}; | ||
this.inStream.subscribe(this.proxy); | ||
} | ||
|
||
stop(): void { | ||
this.inStream.unsubscribe(this.proxy); | ||
} | ||
} |
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