0.2.3 ā€¢ Published 1 year ago

subjectize v0.2.3

Weekly downloads
21
License
MIT
Repository
github
Last release
1 year ago

Subjectize

TypeScript decorators for binding RxJS Subject with class properties

Install

npm i -S subjectize

or

yarn add subjectize

Quick start

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);

Use with Angular @Input

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);
}

See full example here.

How it works

Author

šŸ‘¤ hankchiutw

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2021 hankchiutw. This project is MIT licensed.

0.2.3

1 year ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago