-
Higher-order interceptor. Returns interceptor which assigns given event to FX_DISPATCH_NOW
side effect.
-
Specialization of ensurePred to ensure an event's payload value is within given min
/ max
closed interval. By default, assumes event format like: [event-id, value]
. However if value
is given, the provided function can be used to extract the value to be validated from any event. If the value is outside the given interval, triggers FX_CANCEL
side effect and if err
is given, the error interceptor can return any number of other side effects and so be used to dispatch alternative events instead.
-
-
event value extractor
error interceptor
Higher-order interceptor for validation purposes. Takes a predicate function and an optional interceptor function, which will only be called if the predicate fails for a given event. By default the FX_CANCEL
side effect is triggered if the predicate failed, thus ensuring the actual event handler for the failed event will not be executed anymore. However, this can be overridden using the error interceptor's result, which is merged into the result of this interceptor.
The error interceptor can return any number of other side effects and so be used to dispatch alternative events instead, for example:
// this interceptor will cause cancellation of current event
// and trigger an "error" event instead
ensurePred(
// a dummy predicate which always fails
() => false
// error interceptor fn
() => ({[FX_DISPATCH_NOW]: ["error", "reason"]})
)
Note: For this interceptor to work as expected, it needs to be provided BEFORE the main handler in the interceptor list for a given event, i.e.
[
ensurePred((state, e) => false),
// actual event handler
(state, e) => console.log("no one never calls me")
]
predicate applied to given state & event
interceptor triggered on predicate failure
Specialization of ensurePred to ensure a state value is greater than given min. See ensureStateLessThan for further details.
-
path extractor
error interceptor
Specialization of ensurePred to ensure a state value is less than given max at the time when the event is being processed. The optional path
fn is used to extract or produce the path for the state value to be validated. If omitted, the event's payload item is interpreted as the value path.
For example, without a provided path
function and for an event of this form: ["event-id", "foo.bar"]
, the term "foo.bar"
would be interpreted as path.
If the event has this shape: ["event-id", ["foo.bar", 23]]
, we must provide (e) => e[1][0]
as path function to extract "foo.bar"
from the event.
-
path extractor
error interceptor
Specialization of ensurePred to ensure a state value is within given min
/ max
closed interval. See ensureStateLessThan for further details.
-
-
path extractor
error interceptor
Higher-order interceptor. Returns interceptor which unpacks payload from event and assigns it as is to given side effect ID. Assigns true
to side effect if event has no payload.
side effect ID
Higher-order interceptor. Returns interceptor which calls ctx[id].record()
, where ctx
is the currently active InterceptorContext passed to all event handlers and ctx[id]
is assumed to be a {@link @thi.ng/atom#History} instance, passed to EventBus.processQueue. The default ID for the history instance is "history"
.
Example usage:
-
Debug interceptor to log the current event to the console.
Higher-order interceptor. Returns new interceptor to set state value at provided path. This allows for dedicated events to set state values more concisely, e.g. given this event definition:
-
-
Higher-order interceptor. Returns new interceptor to update state value at provided path with given function. This allows for dedicated events to update state values more concisely, e.g. given this event definition:
-
-
Generated using TypeDoc
Higher-order interceptor. Returns interceptor which assigns given event to
FX_DISPATCH
side effect.