Take Advantage Of The Let Operator in Angular
Imagine that you have a general input component for your application.
Our input
is a dumb component that will emit the input value every time the value changes.
But we have one problem, what if the consumer wants to combine other Rx operators like debounce
, filter
or any other sequence to the valueChanges
observable?
Rx has operator exactly for this kind of problem.
The Let Operator —
Let me have the whole observable
Returns an observable sequence that is the result of invoking the selector on the source sequence.
We have new Input called middleware
that is a function that takes the valueChanges
observable and needs to return a new observable.
If the consumer does not use the middleware
Input, we are returning the same observable.
The Usage —
Remember: This approach is relevant to any observable in your application.
The full example.
Follow me on Medium or Twitter to read more about Angular, Vue and JS!