add entity store class (#70)

This commit is contained in:
Kilin Mikhail
2021-01-14 11:45:46 +03:00
committed by GitHub
parent 555f68ebc6
commit 5078a2cf4b
13 changed files with 4515 additions and 4074 deletions

View File

@ -0,0 +1,23 @@
import {createAdapter} from '@most/adapter';
import {Stream} from '@most/types';
import {hold} from '@most/hold';
export type Subject<T> = {
stream$: Stream<T>;
next: (val: T) => void;
getValue: () => T;
}
export const createSubject = <T>(data: T): Subject<T> => {
let cache = data;
const [handler, stream$] = createAdapter<T>();
return {
next: (val: T) => {
cache = val;
handler(val);
},
stream$: hold(stream$),
getValue: () => cache
};
};