onState

open suspend fun PipelineContext<S, I, A>.onState(old: S, new: S): S?

A callback to be invoked each time StateReceiver.updateState or StateReceiver.withState is called. This callback is invoked before the state changes, and any plugin can veto (forbid) or modify the state change.

This callback is invoked after a StateReceiver.updateState call is finished. This callback is not invoked at all when state is changed through StateReceiver.updateStateImmediate or when StateProvider.state is obtained.

  • Return null to cancel the state change. All plugins registered later when building the store will not receive this event.

  • Return new to continue the chain of modification, or allow the state to change, if no other plugins change it.

  • Return old to veto the state change, but allow next plugins in the queue to process the state.

  • Execute other operations using PipelineContext.