bound-subject-decorator
A decorator for reducing boilerplate around using RxJS 5 Subjects in Components (like React or similar)
Installation
npm i -S bound-subject-decorator
Usage
By decorating any property that returns a Subject
(or BehaviorSubject
, et al)
with @boundSubject
, it binds the subject instance's next
, error
and complete
methods to the subject instance, so they can be used with less boilerplate in
components. This can be used in any framework or environment that might require
this behavior.
React.js Basic Example
;;; Component { superprops; thisstate = count: 0 ; } { thissub = thisclicks ; } { thissub; } // convert the `clicks` property to a function-subject! @boundSubject clicks = ; { // now we can use `{this.clicks.next}` directly as a handler return <div> <button onClick=thisclicksnext>Click Me</button> <div>count: thisstatecount</div> </div>; }