Skip to content

Commit

Permalink
Put a key on memory history's initial location
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Feb 17, 2017
1 parent e80dd2b commit f2dbf6f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions modules/__tests__/MemoryHistory-test.js
Expand Up @@ -15,8 +15,8 @@ describe('a memory history', () => {
})

describe('the initial location', () => {
it('does not have a key', (done) => {
TestSequences.InitialLocationNoKey(history, done)
it('has a key', (done) => {
TestSequences.InitialLocationHasKey(history, done)
})
})

Expand Down
12 changes: 12 additions & 0 deletions modules/__tests__/TestSequences/InitialLocationHasKey.js
@@ -0,0 +1,12 @@
import expect from 'expect'
import execSteps from './execSteps'

export default (history, done) => {
const steps = [
(location) => {
expect(location.key).toExist()
}
]

execSteps(steps, history, done)
}
1 change: 1 addition & 0 deletions modules/__tests__/TestSequences/index.js
Expand Up @@ -9,6 +9,7 @@ export GoForward from './GoForward'
export HashbangHashPathCoding from './HashbangHashPathCoding'
export HashChangeTransitionHook from './HashChangeTransitionHook'
export InitialLocationNoKey from './InitialLocationNoKey'
export InitialLocationHasKey from './InitialLocationHasKey'
export Listen from './Listen'
export NoslashHashPathCoding from './NoslashHashPathCoding'
export PushNewLocation from './PushNewLocation'
Expand Down
6 changes: 3 additions & 3 deletions modules/createMemoryHistory.js
Expand Up @@ -34,10 +34,10 @@ const createMemoryHistory = (props = {}) => {
Math.random().toString(36).substr(2, keyLength)

const index = clamp(initialIndex, 0, initialEntries.length - 1)
const entries = initialEntries.map((entry, index) => (
const entries = initialEntries.map(entry => (
typeof entry === 'string'
? createLocation(entry, undefined, index ? createKey() : undefined)
: createLocation(entry, undefined, index ? (entry.key || createKey()) : undefined)
? createLocation(entry, undefined, createKey())
: createLocation(entry, undefined, entry.key || createKey())
))

// Public interface
Expand Down

0 comments on commit f2dbf6f

Please sign in to comment.