evt.pipe(...)
An alternative to compose for chaining operaors.
Last updated
An alternative to compose for chaining operaors.
Last updated
Being familiar with and is a prerequisite for properly using pipe.
A new Evt instance toward which are forwarded the transformed events matched by the operator(s).
Ctx
: Optional, the context to which will be bound the handler responsible for forwarding events to the returned Evt.
...Operator[]
: One or many operators composable with one another.
There are two ways of using pipe, the first is to call pipe only once and passing it all the operators to chain, the second is to chain the pipe
calls providing each time a single operator. Depending on the situation, you should favor one approach over the other.
Let us consider a case where the two approaches are equally valid.
Using a single call to pipe
:
Same thing chaining pipe
:
The first approach (calling pipe only once) is preferable as it is slightly less verbose but in some cases you will reach the limits of TypeScript inference capabilities especially if you throw filters and generic operators into the mix. Bottom point is: try the first method, see how TypeScript infer the types, if detection fails fallback to chainging pipe()
.
Pipe can also be used to create proxies to a source Evt
.
********
********
When chaining pipe
if one operator in the midle of the chain returns "DETACH"
all the handler upstream will stay attached. You must always detach the first link of the chain using a .