##// END OF EJS Templates
Added test widgets to the playground
Added test widgets to the playground

File last commit:

r97:8b413dc7fc42 v1.3
r100:ff52224a63f0 v1.3
Show More
observable.ts
34 lines | 907 B | video/mp2t | TypeScriptLexer
/ djx / src / main / ts / observable.ts
cin
refactoring, adding scope to rendering methods
r96 import { IDestroyable } from "@implab/core-amd/interfaces";
export interface Sink<T> {
next: (value: T) => void;
error: (e: unknown) => void;
complete: () => void;
}
export type Consumer<T> = Partial<Sink<T>>;
export type Producer<T> = (sink: Sink<T>) => (void | (() => void));
export interface Observable<T> {
cin
Added playground project
r97 on(consumer: Partial<Sink<T>>): IDestroyable;
cin
refactoring, adding scope to rendering methods
r96 }
const noop = () => {};
const sink = <T>(consumer: Consumer<T>) => {
const { next = noop, error = noop, complete = noop } = consumer;
let done = false;
return {
next: (value: T) => done && next(value),
error: (e: unknown) => done && (done = true, error(e)),
complete: () => done && (done = true, complete())
};
}
cin
Added playground project
r97 export const observe = <T>(producer: Producer<T>) : Observable<T> => ({
cin
refactoring, adding scope to rendering methods
r96 on: (consumer: Consumer<T>) => ({
destroy: producer(sink(consumer)) ?? noop
})
});