re-flow.interceptors

Functions to build and use interceptors within re-flow.

Interceptors are the primary method for extending the behavior of re-flow. When a start or transition event are being handled, the event handlers will load any transition interceptors from the app-db and inject them into the re-frame interceptor queue. There are several interceptors that are used by default (see default-interceptors), but you can provide your own list by dispatching a :re-flow.events/set-transition-interceptors event or by calling re-flow.events/set-transition-interceptors.

The only guaranteed provided by re-flow is that the name of the flow will be in the context under the key :re-flow.transition/flow-name. You may also call flow-name to get this value.

It is important to pay attention to the order of the interceptors since some of them (e.g., conform-transition-data) may change the transition data in such a way that data may be lost.

conform-transition-data

Transition interceptor that generates a transition value.

This interceptor intends to take the transition data and conform it with a state’s :transition-spec, if provided.

The spec is provided a map that contains a key :db with the current flow db and a key :td with the transition data. The spec should conform this value into a value that can be used to transition. The event is updated to provide this value.

re-flow.spec/td-spec is designed to make building simple transition specs.

Since this interceptor transforms the transition event directly, you should ensure that you have stored or otherwise processed the transition data with other interceptors before executing this interceptor.

default-interceptors

A default list of interceptors.

This list includes the following in listed order:

flow-name

(flow-name context)

Gets the name of the flow that is the target of the current event.

state-change-dispatch

Transition interceptor that dispatches a specified event on state change.

This interceptor examines the new state after transition. If the new state is different from the old state, it pulls the :dispatch value from the state if one is provided and prepares the event to be dispatched.

The :dispatch value may be a keyword or vector, where the vector is a partial event. The dispatch value with the new state as the final parameter.

It appends the event to :dispatch-n in the effect map in order to avoid overwriting changes caused by other interceptors.

update-flow-db

Transition interceptor that updates the flow db.

This interceptor updates the flow db by determining by conforming the transition value with a state’s db-spec, if provided. If the value does not conform, an error is dispatched and the transition is abandoned.

The spec is provided a map that contains a key :db with the current flow db and a key :td with the transition data. The spec should conform this value into either a single value or a map. If the return value is a simple value, then it will be treated as if in a map associated with a key or either the state’s :key or :name.

The resulting map will be merged into the db after the transition is complete.