Created
December 20, 2017 11:38
-
-
Save fpapado/35e0b8a533e0789102a044d64dbd2a49 to your computer and use it in GitHub Desktop.
Injecting Streams?
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
import xs, { Stream } from 'xstream'; | |
import { initModule, MyMsg } from './module_injecting'; | |
// Stuff | |
init( | |
xs.create({ | |
start: function(listener) { | |
someSource$.subscribe(msg => { | |
// do stuff with someSource$ to get it in shape | |
listener.next(msg); | |
}); | |
}, | |
stop: function() { | |
someSource$.unsubscribe(); | |
} | |
}) | |
); | |
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
import xs, { Stream } from 'xstream'; | |
import { initModule, MyMsg } from './module_injecting'; | |
// Stuff | |
export const myMsg$: Stream<MyMsg> = // do something with someSource$ | |
initModule(); |
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
import xs, { Stream } from 'xstream'; | |
export type MyMsg = {msgType: 'MyMsg', data: any}; | |
export function initModule(msg$: Stream<MyMsg>): void { | |
msg$.addListener({ | |
next: msg => update(msg), | |
error: err => console.error(err), | |
complete: () => console.log('completed') | |
}); | |
} |
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
import xs, { Stream } from 'xstream'; | |
// This | |
import { myMsg$ } from './index_notinjecting.ts'; | |
export type MyMsg = {msgType: 'MyMsg', data: any}; | |
export function initModule(): void { | |
myMsg$.addListener({ | |
next: msg => update(msg), | |
error: err => console.error(err), | |
complete: () => console.log('completed') | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment