TypeScript decorators for binding RxJS Subject with class properties
npm install subjectize``sh`
npm i -S subjectize
or
`sh`
yarn add subjectize
js
import { Subjectize, SubjectizeProps } from 'subjectize';
import { ReplaySubject } from 'rxjs';class SomeClass {
propA: any;
propB: any;
@Subjectize('propA')
propA$ = new ReplaySubject(1);
@SubjectizeProps(['propA', 'propB'])
propAB$ = new ReplaySubject(1);
}
const instance = new SomeClass();
instance.propA = 'A';
instance.propB = 'B';
// would print 'A'
instance.propA$.subscribe(console.log);
// would print ['propA', 'A'], then ['propB', 'B']
instance.propAB$.subscribe(console.log);
`
$3
`js
import { Component, Input } from "@angular/core";
import { ReplaySubject } from "rxjs";
import { Subjectize } from "subjectize";@Component({
selector: "app-counter",
templateUrl: "./counter.component.html",
styleUrls: []
})
export class CounterComponent {
@Input()
count: number;
@Subjectize("count")
count$ = new ReplaySubject(1);
}
``š¤ hankchiutw
* Website: https://hankchiu.tw/
* Twitter: @hankchiu\_tw
* Github: @hankchiutw
* LinkedIn: @hankchiutw
Give a āļø if this project helped you!
Copyright Ā© 2021 hankchiutw.
This project is MIT licensed.