devToolsEnhancer
StoreEnhancer<
- Action action,
- S prevState,
- S nextState
Dev tools enhancer that logs all actions and state changes.
This provides basic Redux DevTools-like functionality for debugging.
Example:
final store = createStore(
reducer,
initialState,
enhancer: devToolsEnhancer(
name: 'MyApp',
onAction: (action, prevState, nextState) {
print('Action: ${action.type}');
print('Prev: $prevState');
print('Next: $nextState');
},
),
);
Implementation
StoreEnhancer<S> devToolsEnhancer<S>({
String name = 'Store',
void Function(Action action, S prevState, S nextState)? onAction,
bool enabled = true,
}) => (createStore, reducer, preloadedState) {
if (!enabled) return createStore(reducer, preloadedState);
S wrappedReducer(S state, Action action) {
final prevState = state;
final nextState = reducer(state, action);
onAction?.call(action, prevState, nextState);
return nextState;
}
return createStore(wrappedReducer, preloadedState);
};