0.0.3 • Published 6 years ago

rx-deep-subject v0.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

rx-deep-subject

RxJS util for converting plain JS-object to object in which every property is either object or BehaviorSubject of primitive.

NPM version Build Status Dependency Status Coverage percentage experimental

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
0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago