Skip to content

Instantly share code, notes, and snippets.

@dherges
Created January 4, 2018 07:13
Show Gist options
  • Save dherges/a69c2ac69dd133357a2eeba7ac9180d6 to your computer and use it in GitHub Desktop.
Save dherges/a69c2ac69dd133357a2eeba7ac9180d6 to your computer and use it in GitHub Desktop.
Event Bus on RxJS
export type MyStuff = string;
export interface Event<T> {
type: 'Starts' | 'Finishes',
payload: T
}
/** @experimental */
export class Bus<P> extends Subject<Event<P>> {
private handlers: HandlerFn<P>[] = [];
public run(): void {
this.subscribe(
(next) => { debugger; },
(err) => { debugger; },
() => { debugger; }
)
for (let handler of this.handlers) {
this.pipe(handler.attachTo).subscribe(this);
}
this.next({ type: '/init/', payload: undefined });
}
}
export interface HandlerFn<T> {
(source$: EventBus<T>): Observable<Event<T>>
}
import { pipe } from 'rxjs/util/pipe';
export class HandlerBuildery<P, A, R> {
constructor(
private id: string
) {}
public build(): HandlerFn<any> {
return pipe(
/* ... */
);
}
/*
return {
id: this.identifier,
attachTo
};
}
*/
}
export function handler<T>(id: string) {
return new HandlerBuilder<T, {}, {}>(id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment