@@ -138,7 +138,7 @@ function liftAction(action) {
138138/**
139139 * Creates a history state reducer from an app's reducer.
140140 */
141- function liftReducerWith ( reducer , initialCommittedState , monitorReducer ) {
141+ function liftReducerWith ( reducer , initialCommittedState , monitorReducer , options ) {
142142 const initialLiftedState = {
143143 monitorState : monitorReducer ( undefined , { } ) ,
144144 nextActionId : 1 ,
@@ -235,6 +235,14 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer) {
235235 break ;
236236 }
237237 case ActionTypes . PERFORM_ACTION : {
238+ if ( options . maxAge && stagedActionIds . length === options . maxAge ) {
239+ // If maxAge has been reached, remove oldest action
240+ delete actionsById [ stagedActionIds [ 0 ] ] ;
241+ skippedActionIds = skippedActionIds . filter ( id => id !== stagedActionIds [ 0 ] ) ;
242+ stagedActionIds = stagedActionIds . slice ( 1 ) ;
243+ committedState = computedStates [ 1 ] . state ;
244+ computedStates = computedStates . slice ( 1 ) ;
245+ }
238246 if ( currentStateIndex === stagedActionIds . length - 1 ) {
239247 currentStateIndex ++ ;
240248 }
@@ -339,7 +347,9 @@ function unliftStore(liftedStore, liftReducer) {
339347/**
340348 * Redux instrumentation store enhancer.
341349 */
342- export default function instrument ( monitorReducer = ( ) => null ) {
350+ export default function instrument ( monitorReducer , options = { } ) {
351+ if ( ! monitorReducer ) { monitorReducer = ( ) => null ; }
352+
343353 return createStore => ( reducer , initialState , enhancer ) => {
344354
345355 function liftReducer ( r ) {
@@ -354,7 +364,7 @@ export default function instrument(monitorReducer = () => null) {
354364 }
355365 throw new Error ( 'Expected the reducer to be a function.' ) ;
356366 }
357- return liftReducerWith ( r , initialState , monitorReducer ) ;
367+ return liftReducerWith ( r , initialState , monitorReducer , options ) ;
358368 }
359369
360370 const liftedStore = createStore ( liftReducer ( reducer ) , enhancer ) ;
0 commit comments