Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request omnidan#123 from jscissr/future-length
Browse files Browse the repository at this point in the history
future length should be ignored when inserting
  • Loading branch information
omnidan authored Nov 4, 2016
2 parents 1fa339a + 4a3181f commit c988e4a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ import * as debug from './debug'
import { ActionTypes } from './actions'
import { parseActions, isHistory } from './helpers'

// length: get length of history
function length (history) {
const { past, future } = history
return past.length + 1 + future.length
// lengthWithoutFuture: get length of history
function lengthWithoutFuture (history) {
return history.past.length + 1
}

// insert: insert `state` into history, which means adding the current state
// into `past`, setting the new `state` as `present` and erasing
// the `future`.
function insert (history, state, limit) {
debug.log('inserting', state)
debug.log('new free: ', limit - length(history))
debug.log('new free: ', limit - lengthWithoutFuture(history))

const { past, present } = history
const historyOverflow = limit && length(history) >= limit
const historyOverflow = limit && lengthWithoutFuture(history) >= limit

const newPast = history.wasFiltered
? past // if the last `present` was filtered, don't store it in the history
Expand Down

0 comments on commit c988e4a

Please sign in to comment.