Package zendesk.support.suas
Interface Middleware
-
public interface Middleware
Middleware definition.
A middleware can be used to implement- Logging that is called before and after the dispatcher
- Asynchronous operations by consuming an
Action
- And probably a million more use-cases I can't think about right now
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description void
onAction(Action<?> action, GetState state, Dispatcher dispatcher, Continuation continuation)
-
-
-
Method Detail
-
onAction
void onAction(Action<?> action, GetState state, Dispatcher dispatcher, Continuation continuation)
Called before anAction
gets passed to theReducer
s.Examples: Log state changes:
void onAction(...) { State oldState = state.getState(); continuation.next(action); State newState = state.getState(); System.out.println(stateDiff(oldState, newState)); }
Consume anAction
and dispatch it on a background thread:void onAction(...) { if(action.getData() instanceof AsyncAction) { // consume action backgroundTask.start(action.getData, dispatcher); } else { continuation.next(action); } }
- Parameters:
action
- a dispatched actionstate
- access to the current statedispatcher
- access to the dispatcher for dispatching a new actioncontinuation
- callback for passing the action to the next middleware
-
-