StatefulEvt<T>
A StatefulEvt is an Evt stat keep a reference to the last value posted.
You can think of it as way to observe when a value is changed.
.state
.stateProperty type: T
reading the property gives the last event data posted. Setting the property (evt.state = data) is equivalent to calling .post(data).
.pipe(...)
.pipe(...)Same as evt.pipe(...) but return a StatefulEvt. Be aware that the current state of the StatefulEvt must be matched by the operator ( if any ) when invoking .pipe(), elst an exception will be thrown.
Converting an Evt into a StatefulEvt
Evt into a StatefulEvtBasic example:
Concrete example:
onlyIfChanged operator
When using stetefull Evt is often usefull to have event posted only when the state value has changed. For that purpose you can pipe with the onlyIfChanged operator.
Concrete example:
If we take the previous example:
Now if we put the onlyIfChanged operator intor the mix:
Merging multiple StatefulEvts
StatefulEvts****Run the example****
Make a StatefulEvt readonly
StatefulEvt readonlyTo prevent a StatefulEvt to be posted by parts of the code that is not supposed to StatefulEvt can be exposed as StatefulReadonlyEvt.
.toStateless([ctx])
.toStateless([ctx])Return a stateless copy of the Evt.
evt.toStateless() is equivalent to Evt.prototype.pipe.call(evt)
Last updated