in packages/redux-dag-history/src/reducer.ts [123:159]
function trackHistoryReducer(state: any, action: Action<any> = EMPTY_ACTION) {
if (!state || !state.graph) {
return handleBlankState(action)
}
const history = tryToHandleHistoryAction(state, action)
// Pass the event to the client reducer.
// Clients may be interested in DagHistory events so propagate those to the client reducer as well.
const newState = reducer(history.current, action)
let result: DagHistory<T>
const isActionAllowed = config.actionFilter(action.type)
const isHistoryHandled = history !== state
const isReplacement = isHistoryHandled || !isActionAllowed
log(
'is action [%s] replacement? %s; allowed=%s, historyHandled=%s',
action.type,
isReplacement,
isActionAllowed,
isHistoryHandled,
)
if (isReplacement) {
result = DagHistoryImpl.replaceCurrentState(newState, history, config)
} else {
// If this is a state we've seen previously, then jump to it.
const existingState = DagHistoryImpl.getExistingState(
newState,
history,
config,
)
return existingState
? DagHistoryImpl.jumpToStateLogged(existingState, history)
: DagHistoryImpl.insert(newState, history, config)
}
return result
}