@stated-library/core
Version:
Core functionality for [`Stated Libraries`](https://github.com/bradfordlemley/stated-library)
20 lines (19 loc) • 624 B
TypeScript
declare type ValueHandler<T> = (value: T) => void;
declare type ValueHandlerObj<T> = {
next: ValueHandler<T>;
};
declare type Observer<T> = ValueHandler<T> | ValueHandlerObj<T>;
declare type Opts<Value> = {
onSubscribe?: () => void;
onUnsubscribe?: () => void;
getValue?: () => Value;
};
export default function createObservable<Value>(initialValue: Value, opts?: Opts<Value>): {
[x: string]: Value | ((nextValue: any) => void);
readonly value: Value;
subscribe(observer: Observer<Value>): {
unsubscribe: () => void;
};
next(nextValue: any): void;
};
export { createObservable };