rx-deep-subject
v0.0.3
Published
RxJS util for converting plain JS-object to object in which every property is either object or BehaviorSubject of primitive
Downloads
3
Readme
rx-deep-subject
RxJS util for converting plain JS-object to object in which every property is either object or BehaviorSubject of primitive.
Install
npm install rx-deep-subject --save
or
yarn add rx-deep-subject
Usage
import { fromObject, toObject } from "rx-deep-subject";
const deepSubject = fromObject({
a: {
b: "Hello",
},
d: "World",
});
// Set next value for BehaviorSubject
deepSubject.a.b.next("Goodbye");
const obj = toObject(deepSubject);
console.log(obj); // { a: { b: 'Goodbye' }, d: 'World' }
API
fromObject<T extends { [index: string]: any }>(obj: T): DeepSubject<T>;
toObject<T>(obj: T): UnpackedDeepSubject<T>;
type DeepSubject<T extends { [index: string]: any }> = {
[P in keyof T]: T[P] extends object ?
DeepSubject<T[P]> :
BehaviorSubject<T[P]>; };
type UnpackedDeepSubject<T extends { [index: string]: any }> = {
[P in keyof T]: T[P] extends BehaviorSubject<infer U> ?
U : T[P] extends { [index: string]: any } ? UnpackedDeepSubject<T[P]> : T[P];
};
Test
npm install
npm test