Skip to content

Instantly share code, notes, and snippets.

@fpapado
Created December 20, 2017 11:38
Show Gist options
  • Save fpapado/35e0b8a533e0789102a044d64dbd2a49 to your computer and use it in GitHub Desktop.
Save fpapado/35e0b8a533e0789102a044d64dbd2a49 to your computer and use it in GitHub Desktop.
Injecting Streams?
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();
}
})
);
import xs, { Stream } from 'xstream';
import { initModule, MyMsg } from './module_injecting';
// Stuff
export const myMsg$: Stream<MyMsg> = // do something with someSource$
initModule();
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')
});
}
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