Comparing version 1.1.0 to 1.2.0
@@ -27,3 +27,10 @@ var webpack = require('webpack'); | ||
}, | ||
// BS_InternetExplorer_9: { | ||
BS_MobileSafari: { | ||
base: 'BrowserStack', | ||
os: 'ios', | ||
os_version: '7.0', | ||
browser: 'iphone', | ||
real_mobile: false, | ||
}, | ||
// BS_InternetExplorer9: { | ||
// base: 'BrowserStack', | ||
@@ -35,3 +42,3 @@ // os: 'Windows', | ||
// }, | ||
BS_InternetExplorer_10: { | ||
BS_InternetExplorer10: { | ||
base: 'BrowserStack', | ||
@@ -43,3 +50,3 @@ os: 'Windows', | ||
}, | ||
BS_InternetExplorer_11: { | ||
BS_InternetExplorer11: { | ||
base: 'BrowserStack', | ||
@@ -51,8 +58,2 @@ os: 'Windows', | ||
}, | ||
BS_MobileSafari: { | ||
base: 'BrowserStack', | ||
os: 'ios', | ||
os_version: '7.0', | ||
browser: 'iphone' | ||
}, | ||
}; | ||
@@ -97,29 +98,30 @@ | ||
config.reporters = [ 'dots' ]; | ||
config.browserDisconnectTimeout = 10000; | ||
config.browserDisconnectTolerance = 3; | ||
config.browserNoActivityTimeout = 30000; | ||
config.captureTimeout = 120000; | ||
config.browserStack = { | ||
username: process.env.BROWSER_STACK_USERNAME, | ||
accessKey: process.env.BROWSER_STACK_ACCESS_KEY, | ||
pollingTimeout: 10000, | ||
startTunnel: true, | ||
}; | ||
} else if (process.env.TRAVIS) { | ||
config.browsers = Object.keys(customLaunchers); | ||
config.reporters = [ 'dots' ]; | ||
config.captureTimeout = 120000; | ||
if (process.env.TRAVIS) { | ||
var buildLabel = 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER + ' (' + process.env.TRAVIS_BUILD_ID + ')'; | ||
var buildLabel = 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER + ' (' + process.env.TRAVIS_BUILD_ID + ')'; | ||
config.browserStack = { | ||
username: process.env.BROWSER_STACK_USERNAME, | ||
accessKey: process.env.BROWSER_STACK_ACCESS_KEY, | ||
pollingTimeout: 10000, | ||
startTunnel: false, | ||
project: 'history', | ||
build: buildLabel, | ||
name: process.env.TRAVIS_JOB_NUMBER, | ||
}; | ||
config.browserStack = { | ||
username: process.env.BROWSER_STACK_USERNAME, | ||
accessKey: process.env.BROWSER_STACK_ACCESS_KEY, | ||
pollingTimeout: 10000, | ||
startTunnel: false, | ||
project: 'history', | ||
build: buildLabel, | ||
name: process.env.TRAVIS_JOB_NUMBER, | ||
}; | ||
config.singleRun = true; | ||
config.singleRun = true; | ||
} else { | ||
config.browserStack = { | ||
username: process.env.BROWSER_STACK_USERNAME, | ||
accessKey: process.env.BROWSER_STACK_ACCESS_KEY, | ||
pollingTimeout: 10000, | ||
startTunnel: true, | ||
}; | ||
} | ||
} | ||
}; |
@@ -19,2 +19,4 @@ 'use strict'; | ||
var _DOMStateStorage = require('./DOMStateStorage'); | ||
var _createDOMHistory = require('./createDOMHistory'); | ||
@@ -26,32 +28,2 @@ | ||
var _createLocation2 = _interopRequireDefault(_createLocation); | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var _historyState = historyState; | ||
var key = _historyState.key; | ||
var state = key && _DOMUtils.readState(key); | ||
var path = _DOMUtils.getWindowPath(); | ||
return _createLocation2['default'](path, state, undefined, key); | ||
} | ||
function startPopStateListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
function popStateListener(event) { | ||
if (event.state === undefined) return; // Ignore extraneous popstate events in WebKit. | ||
transitionTo(getCurrentLocation(event.state)); | ||
} | ||
_DOMUtils.addEventListener(window, 'popstate', popStateListener); | ||
return function () { | ||
_DOMUtils.removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
/** | ||
@@ -66,2 +38,5 @@ * Creates and returns a history object that uses HTML5's history API | ||
*/ | ||
var _createLocation2 = _interopRequireDefault(_createLocation); | ||
function createBrowserHistory(options) { | ||
@@ -72,7 +47,48 @@ _invariant2['default'](_ExecutionEnvironment.canUseDOM, 'Browser history needs a DOM'); | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var path = _DOMUtils.getWindowPath(); | ||
var _historyState = historyState; | ||
var key = _historyState.key; | ||
var state; | ||
if (key) { | ||
state = _DOMStateStorage.readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
window.history.replaceState(_extends({}, historyState, { key: key }), path); | ||
} | ||
return _createLocation2['default'](path, state, undefined, key); | ||
} | ||
function startPopStateListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
function popStateListener(event) { | ||
if (event.state === undefined) return; // Ignore extraneous popstate events in WebKit. | ||
transitionTo(getCurrentLocation(event.state)); | ||
} | ||
_DOMUtils.addEventListener(window, 'popstate', popStateListener); | ||
return function () { | ||
_DOMUtils.removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
function finishTransition(location) { | ||
var key = location.key; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
if (action === _Actions.POP) return; // Nothing to do. | ||
_DOMStateStorage.saveState(key, state); | ||
var path = pathname + search; | ||
@@ -83,16 +99,11 @@ var historyState = { | ||
switch (location.action) { | ||
case _Actions.PUSH: | ||
_DOMUtils.saveState(location.key, location.state); | ||
if (action === _Actions.PUSH) { | ||
if (isSupported) { | ||
window.history.pushState(historyState, null, path); | ||
} else { | ||
window.location.href = path; // Use page reload to preserve the URL. | ||
} | ||
} else { | ||
// REPLACE | ||
if (isSupported) { | ||
window.history.pushState(historyState, null, path); | ||
} else { | ||
window.location.href = path; // Use page reload to preserve the URL. | ||
} | ||
break; | ||
case _Actions.REPLACE: | ||
_DOMUtils.saveState(location.key, location.state); | ||
if (isSupported) { | ||
window.history.replaceState(historyState, null, path); | ||
@@ -102,4 +113,3 @@ } else { | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
@@ -117,3 +127,4 @@ | ||
finishTransition: finishTransition, | ||
cancelTransition: cancelTransition | ||
cancelTransition: cancelTransition, | ||
saveState: _DOMStateStorage.saveState | ||
})); | ||
@@ -125,10 +136,10 @@ | ||
function listen(listener) { | ||
var unlisten = history.listen(listener); | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
var unlisten = history.listen(listener); | ||
return function () { | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
}; | ||
@@ -135,0 +146,0 @@ } |
@@ -48,4 +48,2 @@ 'use strict'; | ||
}, options, { | ||
saveState: _DOMUtils.saveState, | ||
readState: _DOMUtils.readState, | ||
go: _DOMUtils.go | ||
@@ -52,0 +50,0 @@ })); |
@@ -23,2 +23,4 @@ 'use strict'; | ||
var _DOMStateStorage = require('./DOMStateStorage'); | ||
var _createDOMHistory = require('./createDOMHistory'); | ||
@@ -77,3 +79,10 @@ | ||
path = stripQueryStringValueFromPath(path, queryKey); | ||
state = key && _DOMUtils.readState(key); | ||
if (key) { | ||
state = _DOMStateStorage.readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
_DOMUtils.replaceHashPath(addQueryStringValueToPath(path, queryKey, key)); | ||
} | ||
} | ||
@@ -102,6 +111,7 @@ | ||
function finishTransition(location) { | ||
var key = location.key; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
@@ -118,3 +128,3 @@ if (action === _Actions.POP) return; // Nothing to do. | ||
if (queryKey) { | ||
_DOMUtils.saveState(location.key, location.state); | ||
_DOMStateStorage.saveState(key, state); | ||
} else { | ||
@@ -128,2 +138,3 @@ // Drop key and state. | ||
} else { | ||
// REPLACE | ||
_DOMUtils.replaceHashPath(path); | ||
@@ -144,3 +155,4 @@ } | ||
finishTransition: finishTransition, | ||
cancelTransition: cancelTransition | ||
cancelTransition: cancelTransition, | ||
saveState: _DOMStateStorage.saveState | ||
})); | ||
@@ -152,10 +164,10 @@ | ||
function listen(listener) { | ||
var unlisten = history.listen(listener); | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
var unlisten = history.listen(listener); | ||
return function () { | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
}; | ||
@@ -162,0 +174,0 @@ } |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
@@ -39,2 +41,3 @@ | ||
var cancelTransition = options.cancelTransition; | ||
var saveState = options.saveState; | ||
var go = options.go; | ||
@@ -95,3 +98,3 @@ var keyLength = options.keyLength; | ||
for (var i = 0, len = transitionHooks.length; i < len && typeof message !== 'string'; ++i) message = transitionHooks[i].call(this); | ||
for (var i = 0, len = transitionHooks.length; i < len && message == null; ++i) message = transitionHooks[i].call(this); | ||
@@ -102,5 +105,5 @@ return message; | ||
function confirmTransition(callback) { | ||
var message; | ||
var message = getTransitionConfirmationMessage(); | ||
if (getUserConfirmation && (message = getTransitionConfirmationMessage())) { | ||
if (getUserConfirmation && typeof message === 'string') { | ||
getUserConfirmation(message, function (ok) { | ||
@@ -110,3 +113,3 @@ callback(ok !== false); | ||
} else { | ||
callback(true); | ||
callback(message !== false); | ||
} | ||
@@ -144,2 +147,16 @@ } | ||
function setState(state) { | ||
if (location) { | ||
updateLocationState(location, state); | ||
updateLocation(location); | ||
} else { | ||
updateLocationState(getCurrentLocation(), state); | ||
} | ||
} | ||
function updateLocationState(location, state) { | ||
location.state = _extends({}, location.state, state); | ||
saveState(location.key, location.state); | ||
} | ||
function goBack() { | ||
@@ -169,2 +186,3 @@ go(-1); | ||
replaceState: replaceState, | ||
setState: setState, | ||
go: go, | ||
@@ -171,0 +189,0 @@ goBack: goBack, |
@@ -45,2 +45,3 @@ 'use strict'; | ||
cancelTransition: cancelTransition, | ||
saveState: saveState, | ||
go: go | ||
@@ -86,10 +87,18 @@ })); | ||
function getCurrentLocation() { | ||
var _entries$current = entries[current]; | ||
var key = _entries$current.key; | ||
var pathname = _entries$current.pathname; | ||
var search = _entries$current.search; | ||
var entry = entries[current]; | ||
var key = entry.key; | ||
var pathname = entry.pathname; | ||
var search = entry.search; | ||
var path = pathname + (search || ''); | ||
var state = readState(key); | ||
var state; | ||
if (key) { | ||
state = readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
entry.key = key; | ||
} | ||
return _createLocation2['default'](path, state, undefined, key); | ||
@@ -96,0 +105,0 @@ } |
@@ -9,4 +9,2 @@ 'use strict'; | ||
exports.getWindowPath = getWindowPath; | ||
exports.saveState = saveState; | ||
exports.readState = readState; | ||
exports.go = go; | ||
@@ -46,20 +44,2 @@ exports.supportsHistory = supportsHistory; | ||
function saveState(key, state) { | ||
window.sessionStorage.setItem(key, JSON.stringify(state)); | ||
} | ||
function readState(key) { | ||
var json = window.sessionStorage.getItem(key); | ||
if (json) { | ||
try { | ||
return JSON.parse(json); | ||
} catch (error) { | ||
// Ignore invalid JSON. | ||
} | ||
} | ||
return null; | ||
} | ||
function go(n) { | ||
@@ -66,0 +46,0 @@ if (n) window.history.go(n); |
@@ -69,3 +69,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _createHashHistory2 = __webpack_require__(12); | ||
var _createHashHistory2 = __webpack_require__(13); | ||
@@ -76,3 +76,3 @@ var _createHashHistory3 = _interopRequireDefault(_createHashHistory2); | ||
var _createMemoryHistory2 = __webpack_require__(14); | ||
var _createMemoryHistory2 = __webpack_require__(15); | ||
@@ -83,3 +83,3 @@ var _createMemoryHistory3 = _interopRequireDefault(_createMemoryHistory2); | ||
var _createLocation2 = __webpack_require__(11); | ||
var _createLocation2 = __webpack_require__(12); | ||
@@ -90,3 +90,3 @@ var _createLocation3 = _interopRequireDefault(_createLocation2); | ||
var _Actions2 = __webpack_require__(4); | ||
var _Actions2 = __webpack_require__(3); | ||
@@ -109,48 +109,20 @@ var _Actions3 = _interopRequireDefault(_Actions2); | ||
var _invariant = __webpack_require__(3); | ||
var _invariant = __webpack_require__(2); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _Actions = __webpack_require__(4); | ||
var _Actions = __webpack_require__(3); | ||
var _ExecutionEnvironment = __webpack_require__(5); | ||
var _ExecutionEnvironment = __webpack_require__(4); | ||
var _DOMUtils = __webpack_require__(2); | ||
var _DOMUtils = __webpack_require__(5); | ||
var _createDOMHistory = __webpack_require__(6); | ||
var _DOMStateStorage = __webpack_require__(6); | ||
var _createDOMHistory = __webpack_require__(7); | ||
var _createDOMHistory2 = _interopRequireDefault(_createDOMHistory); | ||
var _createLocation = __webpack_require__(11); | ||
var _createLocation = __webpack_require__(12); | ||
var _createLocation2 = _interopRequireDefault(_createLocation); | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var _historyState = historyState; | ||
var key = _historyState.key; | ||
var state = key && _DOMUtils.readState(key); | ||
var path = _DOMUtils.getWindowPath(); | ||
return _createLocation2['default'](path, state, undefined, key); | ||
} | ||
function startPopStateListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
function popStateListener(event) { | ||
if (event.state === undefined) return; // Ignore extraneous popstate events in WebKit. | ||
transitionTo(getCurrentLocation(event.state)); | ||
} | ||
_DOMUtils.addEventListener(window, 'popstate', popStateListener); | ||
return function () { | ||
_DOMUtils.removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
/** | ||
@@ -165,2 +137,5 @@ * Creates and returns a history object that uses HTML5's history API | ||
*/ | ||
var _createLocation2 = _interopRequireDefault(_createLocation); | ||
function createBrowserHistory(options) { | ||
@@ -171,7 +146,48 @@ _invariant2['default'](_ExecutionEnvironment.canUseDOM, 'Browser history needs a DOM'); | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var path = _DOMUtils.getWindowPath(); | ||
var _historyState = historyState; | ||
var key = _historyState.key; | ||
var state; | ||
if (key) { | ||
state = _DOMStateStorage.readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
window.history.replaceState(_extends({}, historyState, { key: key }), path); | ||
} | ||
return _createLocation2['default'](path, state, undefined, key); | ||
} | ||
function startPopStateListener(_ref) { | ||
var transitionTo = _ref.transitionTo; | ||
function popStateListener(event) { | ||
if (event.state === undefined) return; // Ignore extraneous popstate events in WebKit. | ||
transitionTo(getCurrentLocation(event.state)); | ||
} | ||
_DOMUtils.addEventListener(window, 'popstate', popStateListener); | ||
return function () { | ||
_DOMUtils.removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
function finishTransition(location) { | ||
var key = location.key; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
if (action === _Actions.POP) return; // Nothing to do. | ||
_DOMStateStorage.saveState(key, state); | ||
var path = pathname + search; | ||
@@ -182,16 +198,11 @@ var historyState = { | ||
switch (location.action) { | ||
case _Actions.PUSH: | ||
_DOMUtils.saveState(location.key, location.state); | ||
if (action === _Actions.PUSH) { | ||
if (isSupported) { | ||
window.history.pushState(historyState, null, path); | ||
} else { | ||
window.location.href = path; // Use page reload to preserve the URL. | ||
} | ||
} else { | ||
// REPLACE | ||
if (isSupported) { | ||
window.history.pushState(historyState, null, path); | ||
} else { | ||
window.location.href = path; // Use page reload to preserve the URL. | ||
} | ||
break; | ||
case _Actions.REPLACE: | ||
_DOMUtils.saveState(location.key, location.state); | ||
if (isSupported) { | ||
window.history.replaceState(historyState, null, path); | ||
@@ -201,4 +212,3 @@ } else { | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
@@ -216,3 +226,4 @@ | ||
finishTransition: finishTransition, | ||
cancelTransition: cancelTransition | ||
cancelTransition: cancelTransition, | ||
saveState: _DOMStateStorage.saveState | ||
})); | ||
@@ -224,10 +235,10 @@ | ||
function listen(listener) { | ||
var unlisten = history.listen(listener); | ||
if (++listenerCount === 1) stopPopStateListener = startPopStateListener(history); | ||
var unlisten = history.listen(listener); | ||
return function () { | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) stopPopStateListener(); | ||
}; | ||
@@ -246,97 +257,2 @@ } | ||
/* 2 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
exports.addEventListener = addEventListener; | ||
exports.removeEventListener = removeEventListener; | ||
exports.getHashPath = getHashPath; | ||
exports.replaceHashPath = replaceHashPath; | ||
exports.getWindowPath = getWindowPath; | ||
exports.saveState = saveState; | ||
exports.readState = readState; | ||
exports.go = go; | ||
exports.supportsHistory = supportsHistory; | ||
exports.supportsGoWithoutReloadUsingHash = supportsGoWithoutReloadUsingHash; | ||
function addEventListener(node, event, listener) { | ||
if (node.addEventListener) { | ||
node.addEventListener(event, listener, false); | ||
} else { | ||
node.attachEvent('on' + event, listener); | ||
} | ||
} | ||
function removeEventListener(node, event, listener) { | ||
if (node.removeEventListener) { | ||
node.removeEventListener(event, listener, false); | ||
} else { | ||
node.detachEvent('on' + event, listener); | ||
} | ||
} | ||
function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
return window.location.href.split('#')[1] || ''; | ||
} | ||
function replaceHashPath(path) { | ||
window.location.replace(window.location.pathname + window.location.search + '#' + path); | ||
} | ||
function getWindowPath() { | ||
return window.location.pathname + window.location.search; | ||
} | ||
function saveState(key, state) { | ||
window.sessionStorage.setItem(key, JSON.stringify(state)); | ||
} | ||
function readState(key) { | ||
var json = window.sessionStorage.getItem(key); | ||
if (json) { | ||
try { | ||
return JSON.parse(json); | ||
} catch (error) { | ||
// Ignore invalid JSON. | ||
} | ||
} | ||
return null; | ||
} | ||
function go(n) { | ||
if (n) window.history.go(n); | ||
} | ||
/** | ||
* Returns true if the HTML5 history API is supported. Taken from modernizr. | ||
* | ||
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/rackt/react-router/issues/586 | ||
*/ | ||
function supportsHistory() { | ||
var ua = navigator.userAgent; | ||
if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) { | ||
return false; | ||
} | ||
return window.history && 'pushState' in window.history; | ||
} | ||
/** | ||
* Returns false if using go(n) with hash history causes a full page reload. | ||
*/ | ||
function supportsGoWithoutReloadUsingHash() { | ||
var ua = navigator.userAgent; | ||
return ua.indexOf('Firefox') === -1; | ||
} | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -400,3 +316,3 @@ | ||
/***/ }, | ||
/* 4 */ | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
@@ -437,3 +353,3 @@ | ||
/***/ }, | ||
/* 5 */ | ||
/* 4 */ | ||
/***/ function(module, exports) { | ||
@@ -448,3 +364,111 @@ | ||
/***/ }, | ||
/* 5 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
exports.addEventListener = addEventListener; | ||
exports.removeEventListener = removeEventListener; | ||
exports.getHashPath = getHashPath; | ||
exports.replaceHashPath = replaceHashPath; | ||
exports.getWindowPath = getWindowPath; | ||
exports.go = go; | ||
exports.supportsHistory = supportsHistory; | ||
exports.supportsGoWithoutReloadUsingHash = supportsGoWithoutReloadUsingHash; | ||
function addEventListener(node, event, listener) { | ||
if (node.addEventListener) { | ||
node.addEventListener(event, listener, false); | ||
} else { | ||
node.attachEvent('on' + event, listener); | ||
} | ||
} | ||
function removeEventListener(node, event, listener) { | ||
if (node.removeEventListener) { | ||
node.removeEventListener(event, listener, false); | ||
} else { | ||
node.detachEvent('on' + event, listener); | ||
} | ||
} | ||
function getHashPath() { | ||
// We can't use window.location.hash here because it's not | ||
// consistent across browsers - Firefox will pre-decode it! | ||
return window.location.href.split('#')[1] || ''; | ||
} | ||
function replaceHashPath(path) { | ||
window.location.replace(window.location.pathname + window.location.search + '#' + path); | ||
} | ||
function getWindowPath() { | ||
return window.location.pathname + window.location.search; | ||
} | ||
function go(n) { | ||
if (n) window.history.go(n); | ||
} | ||
/** | ||
* Returns true if the HTML5 history API is supported. Taken from modernizr. | ||
* | ||
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE | ||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js | ||
* changed to avoid false negatives for Windows Phones: https://github.com/rackt/react-router/issues/586 | ||
*/ | ||
function supportsHistory() { | ||
var ua = navigator.userAgent; | ||
if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) { | ||
return false; | ||
} | ||
return window.history && 'pushState' in window.history; | ||
} | ||
/** | ||
* Returns false if using go(n) with hash history causes a full page reload. | ||
*/ | ||
function supportsGoWithoutReloadUsingHash() { | ||
var ua = navigator.userAgent; | ||
return ua.indexOf('Firefox') === -1; | ||
} | ||
/***/ }, | ||
/* 6 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
exports.saveState = saveState; | ||
exports.readState = readState; | ||
var KeyPrefix = '@@History/'; | ||
function createKey(key) { | ||
return KeyPrefix + key; | ||
} | ||
function saveState(key, state) { | ||
window.sessionStorage.setItem(createKey(key), JSON.stringify(state)); | ||
} | ||
function readState(key) { | ||
var json = window.sessionStorage.getItem(createKey(key)); | ||
if (json) { | ||
try { | ||
return JSON.parse(json); | ||
} catch (error) { | ||
// Ignore invalid JSON. | ||
} | ||
} | ||
return null; | ||
} | ||
/***/ }, | ||
/* 7 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -460,11 +484,11 @@ | ||
var _invariant = __webpack_require__(3); | ||
var _invariant = __webpack_require__(2); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _ExecutionEnvironment = __webpack_require__(5); | ||
var _ExecutionEnvironment = __webpack_require__(4); | ||
var _DOMUtils = __webpack_require__(2); | ||
var _DOMUtils = __webpack_require__(5); | ||
var _createHistory = __webpack_require__(7); | ||
var _createHistory = __webpack_require__(8); | ||
@@ -500,4 +524,2 @@ var _createHistory2 = _interopRequireDefault(_createHistory); | ||
}, options, { | ||
saveState: _DOMUtils.saveState, | ||
readState: _DOMUtils.readState, | ||
go: _DOMUtils.go | ||
@@ -532,3 +554,3 @@ })); | ||
/***/ }, | ||
/* 7 */ | ||
/* 8 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -540,15 +562,17 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _invariant = __webpack_require__(3); | ||
var _invariant = __webpack_require__(2); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _deepEqual = __webpack_require__(8); | ||
var _deepEqual = __webpack_require__(9); | ||
var _deepEqual2 = _interopRequireDefault(_deepEqual); | ||
var _Actions = __webpack_require__(4); | ||
var _Actions = __webpack_require__(3); | ||
var _createLocation = __webpack_require__(11); | ||
var _createLocation = __webpack_require__(12); | ||
@@ -574,2 +598,3 @@ var _createLocation2 = _interopRequireDefault(_createLocation); | ||
var cancelTransition = options.cancelTransition; | ||
var saveState = options.saveState; | ||
var go = options.go; | ||
@@ -630,3 +655,3 @@ var keyLength = options.keyLength; | ||
for (var i = 0, len = transitionHooks.length; i < len && typeof message !== 'string'; ++i) message = transitionHooks[i].call(this); | ||
for (var i = 0, len = transitionHooks.length; i < len && message == null; ++i) message = transitionHooks[i].call(this); | ||
@@ -637,5 +662,5 @@ return message; | ||
function confirmTransition(callback) { | ||
var message; | ||
var message = getTransitionConfirmationMessage(); | ||
if (getUserConfirmation && (message = getTransitionConfirmationMessage())) { | ||
if (getUserConfirmation && typeof message === 'string') { | ||
getUserConfirmation(message, function (ok) { | ||
@@ -645,3 +670,3 @@ callback(ok !== false); | ||
} else { | ||
callback(true); | ||
callback(message !== false); | ||
} | ||
@@ -679,2 +704,16 @@ } | ||
function setState(state) { | ||
if (location) { | ||
updateLocationState(location, state); | ||
updateLocation(location); | ||
} else { | ||
updateLocationState(getCurrentLocation(), state); | ||
} | ||
} | ||
function updateLocationState(location, state) { | ||
location.state = _extends({}, location.state, state); | ||
saveState(location.key, location.state); | ||
} | ||
function goBack() { | ||
@@ -704,2 +743,3 @@ go(-1); | ||
replaceState: replaceState, | ||
setState: setState, | ||
go: go, | ||
@@ -717,8 +757,8 @@ goBack: goBack, | ||
/***/ }, | ||
/* 8 */ | ||
/* 9 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var pSlice = Array.prototype.slice; | ||
var objectKeys = __webpack_require__(9); | ||
var isArguments = __webpack_require__(10); | ||
var objectKeys = __webpack_require__(10); | ||
var isArguments = __webpack_require__(11); | ||
@@ -818,3 +858,3 @@ var deepEqual = module.exports = function (actual, expected, opts) { | ||
/***/ }, | ||
/* 9 */ | ||
/* 10 */ | ||
/***/ function(module, exports) { | ||
@@ -834,3 +874,3 @@ | ||
/***/ }, | ||
/* 10 */ | ||
/* 11 */ | ||
/***/ function(module, exports) { | ||
@@ -861,3 +901,3 @@ | ||
/***/ }, | ||
/* 11 */ | ||
/* 12 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -869,3 +909,3 @@ | ||
var _Actions = __webpack_require__(4); | ||
var _Actions = __webpack_require__(3); | ||
@@ -904,3 +944,3 @@ function createLocation() { | ||
/***/ }, | ||
/* 12 */ | ||
/* 13 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -916,21 +956,23 @@ | ||
var _warning = __webpack_require__(13); | ||
var _warning = __webpack_require__(14); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
var _invariant = __webpack_require__(3); | ||
var _invariant = __webpack_require__(2); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _Actions = __webpack_require__(4); | ||
var _Actions = __webpack_require__(3); | ||
var _ExecutionEnvironment = __webpack_require__(5); | ||
var _ExecutionEnvironment = __webpack_require__(4); | ||
var _DOMUtils = __webpack_require__(2); | ||
var _DOMUtils = __webpack_require__(5); | ||
var _createDOMHistory = __webpack_require__(6); | ||
var _DOMStateStorage = __webpack_require__(6); | ||
var _createDOMHistory = __webpack_require__(7); | ||
var _createDOMHistory2 = _interopRequireDefault(_createDOMHistory); | ||
var _createLocation = __webpack_require__(11); | ||
var _createLocation = __webpack_require__(12); | ||
@@ -984,3 +1026,10 @@ var _createLocation2 = _interopRequireDefault(_createLocation); | ||
path = stripQueryStringValueFromPath(path, queryKey); | ||
state = key && _DOMUtils.readState(key); | ||
if (key) { | ||
state = _DOMStateStorage.readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
_DOMUtils.replaceHashPath(addQueryStringValueToPath(path, queryKey, key)); | ||
} | ||
} | ||
@@ -1009,6 +1058,7 @@ | ||
function finishTransition(location) { | ||
var key = location.key; | ||
var pathname = location.pathname; | ||
var search = location.search; | ||
var state = location.state; | ||
var action = location.action; | ||
var key = location.key; | ||
@@ -1025,3 +1075,3 @@ if (action === _Actions.POP) return; // Nothing to do. | ||
if (queryKey) { | ||
_DOMUtils.saveState(location.key, location.state); | ||
_DOMStateStorage.saveState(key, state); | ||
} else { | ||
@@ -1035,2 +1085,3 @@ // Drop key and state. | ||
} else { | ||
// REPLACE | ||
_DOMUtils.replaceHashPath(path); | ||
@@ -1051,3 +1102,4 @@ } | ||
finishTransition: finishTransition, | ||
cancelTransition: cancelTransition | ||
cancelTransition: cancelTransition, | ||
saveState: _DOMStateStorage.saveState | ||
})); | ||
@@ -1059,10 +1111,10 @@ | ||
function listen(listener) { | ||
var unlisten = history.listen(listener); | ||
if (++listenerCount === 1) stopHashChangeListener = startHashChangeListener(history); | ||
var unlisten = history.listen(listener); | ||
return function () { | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) stopHashChangeListener(); | ||
}; | ||
@@ -1108,3 +1160,3 @@ } | ||
/***/ }, | ||
/* 13 */ | ||
/* 14 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1175,3 +1227,3 @@ | ||
/***/ }, | ||
/* 14 */ | ||
/* 15 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1187,13 +1239,13 @@ | ||
var _invariant = __webpack_require__(3); | ||
var _invariant = __webpack_require__(2); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _Actions = __webpack_require__(4); | ||
var _Actions = __webpack_require__(3); | ||
var _createLocation = __webpack_require__(11); | ||
var _createLocation = __webpack_require__(12); | ||
var _createLocation2 = _interopRequireDefault(_createLocation); | ||
var _createHistory = __webpack_require__(7); | ||
var _createHistory = __webpack_require__(8); | ||
@@ -1224,2 +1276,3 @@ var _createHistory2 = _interopRequireDefault(_createHistory); | ||
cancelTransition: cancelTransition, | ||
saveState: saveState, | ||
go: go | ||
@@ -1265,10 +1318,18 @@ })); | ||
function getCurrentLocation() { | ||
var _entries$current = entries[current]; | ||
var key = _entries$current.key; | ||
var pathname = _entries$current.pathname; | ||
var search = _entries$current.search; | ||
var entry = entries[current]; | ||
var key = entry.key; | ||
var pathname = entry.pathname; | ||
var search = entry.search; | ||
var path = pathname + (search || ''); | ||
var state = readState(key); | ||
var state; | ||
if (key) { | ||
state = readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
entry.key = key; | ||
} | ||
return _createLocation2['default'](path, state, undefined, key); | ||
@@ -1275,0 +1336,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.History=e():t.History=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=n(8),a=r(o);e.createHistory=a["default"];var i=n(9),u=r(i);e.createHashHistory=u["default"];var s=n(10),c=r(s);e.createMemoryHistory=c["default"];var f=n(2),l=r(f);e.createLocation=l["default"];var d=n(1),h=r(d);e.Actions=h["default"]},function(t,e){"use strict";e.__esModule=!0;var n="PUSH";e.PUSH=n;var r="REPLACE";e.REPLACE=r;var o="POP";e.POP=o,e["default"]={PUSH:n,REPLACE:r,POP:o}},function(t,e,n){"use strict";function r(){var t,e,n=arguments.length<=0||void 0===arguments[0]?"/":arguments[0],r=arguments.length<=1||void 0===arguments[1]?null:arguments[1],a=arguments.length<=2||void 0===arguments[2]?o.POP:arguments[2],i=arguments.length<=3||void 0===arguments[3]?null:arguments[3],u=n.indexOf("?");return-1!==u?(t=n.substring(0,u),e=n.substring(u)):(t=n,e=""),""===t&&(t="/"),{pathname:t,search:e,state:r,action:a,key:i}}e.__esModule=!0;var o=n(1);e["default"]=r,t.exports=e["default"]},function(t,e,n){"use strict";var r=function(t,e,n,r,o,a,i,u){if(!t){var s;if(void 0===e)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,a,i,u],f=0;s=new Error("Invariant Violation: "+e.replace(/%s/g,function(){return c[f++]}))}throw s.framesToPop=1,s}};t.exports=r},function(t,e){"use strict";function n(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent("on"+e,n)}function r(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent("on"+e,n)}function o(){return window.location.href.split("#")[1]||""}function a(t){window.location.replace(window.location.pathname+window.location.search+"#"+t)}function i(){return window.location.pathname+window.location.search}function u(t,e){window.sessionStorage.setItem(t,JSON.stringify(e))}function s(t){var e=window.sessionStorage.getItem(t);if(e)try{return JSON.parse(e)}catch(n){}return null}function c(t){t&&window.history.go(t)}function f(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history:!1}function l(){var t=navigator.userAgent;return-1===t.indexOf("Firefox")}e.__esModule=!0,e.addEventListener=n,e.removeEventListener=r,e.getHashPath=o,e.replaceHashPath=a,e.getWindowPath=i,e.saveState=u,e.readState=s,e.go=c,e.supportsHistory=f,e.supportsGoWithoutReloadUsingHash=l},function(t,e){"use strict";e.__esModule=!0;var n=!("undefined"==typeof window||!window.document||!window.document.createElement);e.canUseDOM=n},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){e(window.confirm(t))}function a(t){function e(t){var e=n();return"string"==typeof e?((t||window.event).returnValue=e,e):void 0}var n=t.getTransitionConfirmationMessage;return l.addEventListener(window,"beforeunload",e),function(){l.removeEventListener(window,"beforeunload",e)}}function i(t){function e(t){c["default"](f.canUseDOM,"DOM history needs a DOM"),1===++i&&(n=a(r));var e=r.listen(t);return function(){e(),0===--i&&n()}}var n,r=h["default"](u({getUserConfirmation:o},t,{saveState:l.saveState,readState:l.readState,go:l.go})),i=0;return u({},r,{listen:e})}e.__esModule=!0;var u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s=n(3),c=r(s),f=n(5),l=n(4),d=n(7),h=r(d);e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return Math.random().toString(36).substr(2,t)}function a(t,e){return t.pathname===e.pathname&&t.search===e.search&&t.key===e.key&&f["default"](t.state,e.state)}function i(){function t(t){M=t,L.forEach(function(t){t(M)})}function e(t){L.push(t)}function n(t){L=L.filter(function(e){return e!==t})}function r(r){return e(r),M?r(M):t(b()),function(){n(r)}}function i(t){-1===j.indexOf(t)&&j.push(t)}function u(t){j=j.filter(function(e){return e!==t})}function c(){for(var t=null,e=0,n=j.length;n>e&&"string"!=typeof t;++e)t=j[e].call(this);return t}function f(t){var e;H&&(e=c())?H(e,function(e){t(e!==!1)}):t(!0)}function d(e){M&&a(M,e)||(s["default"](null==k,"transitionTo: Another transition is already in progress"),k=e,f(function(n){k=null,n?(S(e),t(e)):x&&x(e)}))}function g(t,e){d(h["default"](e,t,l.PUSH,w()))}function v(t,e){d(h["default"](e,t,l.REPLACE,w()))}function y(){E(-1)}function m(){E(1)}function w(){return o(_)}function O(t){return t}var P=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],b=P.getCurrentLocation,S=P.finishTransition,x=P.cancelTransition,E=P.go,_=P.keyLength,H=P.getUserConfirmation;"number"!=typeof _&&(_=p);var M,k,j=[],L=[];return{listen:r,registerTransitionHook:i,unregisterTransitionHook:u,getTransitionConfirmationMessage:c,transitionTo:d,pushState:g,replaceState:v,go:E,goBack:y,goForward:m,createKey:w,createHref:O}}e.__esModule=!0;var u=n(3),s=r(u),c=n(11),f=r(c),l=n(1),d=n(2),h=r(d),p=6;e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){t=t||window.history.state||{};var e=t,n=e.key,r=n&&d.readState(n),o=d.getWindowPath();return v["default"](o,r,void 0,n)}function a(t){function e(t){void 0!==t.state&&n(o(t.state))}var n=t.transitionTo;return d.addEventListener(window,"popstate",e),function(){d.removeEventListener(window,"popstate",e)}}function i(t){function e(t){var e=t.key,n=t.pathname,r=t.search,o=n+r,a={key:e};switch(t.action){case f.PUSH:d.saveState(t.key,t.state),s?window.history.pushState(a,null,o):window.location.href=o;break;case f.REPLACE:d.saveState(t.key,t.state),s?window.history.replaceState(a,null,o):window.location.replace(o)}}function n(t){if(t.action===f.POP){var e=0;d.go(e)}}function r(t){1===++g&&(i=a(h));var e=h.listen(t);return function(){e(),0===--g&&i()}}c["default"](l.canUseDOM,"Browser history needs a DOM");var i,s=d.supportsHistory(),h=p["default"](u({},t,{getCurrentLocation:o,finishTransition:e,cancelTransition:n})),g=0;return u({},h,{listen:r})}e.__esModule=!0;var u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s=n(3),c=r(s),f=n(1),l=n(5),d=n(4),h=n(6),p=r(h),g=n(2),v=r(g);e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return"string"==typeof t&&"/"===t.charAt(0)}function a(){var t=y.getHashPath();return o(t)?!0:(y.replaceHashPath("/"+t),!1)}function i(t,e,n){return t+(-1===t.indexOf("?")?"?":"&")+(e+"="+n)}function u(t,e){return t.replace(new RegExp("[?&]?"+e+"=[a-zA-Z0-9]+"),"")}function s(t,e){var n=t.match(new RegExp("\\?.*?\\b"+e+"=(.+?)\\b"));return n&&n[1]}function c(){function t(){var t,e,n=y.getHashPath();return S&&(t=s(n,S),n=u(n,S),e=t&&y.readState(t)),P["default"](n,e,void 0,t)}function e(e){function n(){a()&&r(t())}var r=e.transitionTo;return a(),y.addEventListener(window,"hashchange",n),function(){y.removeEventListener(window,"hashchange",n)}}function n(t){var e=t.key,n=t.pathname,r=t.search,o=t.action;if(o!==g.POP){var a=n+r;S&&(a=i(a,S,e)),a===y.getHashPath()?d["default"](!1,"You cannot %s the same path using hash history",o):(S?y.saveState(t.key,t.state):t.key=t.state=null,o===g.PUSH?window.location.hash=a:y.replaceHashPath(a))}}function r(t){if(t.action===g.POP){var e=0;h(e)}}function o(t){1===++_&&(x=e(E));var n=E.listen(t);return function(){n(),0===--_&&x()}}function c(t,e){d["default"](S||null==t,"You cannot use state without a queryKey; it will be dropped"),E.pushState(t,e)}function l(t,e){d["default"](S||null==t,"You cannot use state without a queryKey; it will be dropped"),E.replaceState(t,e)}function h(t){d["default"](H,"Hash history go(n) causes a full page reload in this browser"),E.go(t)}function m(t){return"#"+E.createHref(t)}var O=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];p["default"](v.canUseDOM,"Hash history needs a DOM");var S=O.queryKey;(void 0===S||S)&&(S="string"==typeof S?S:b);var x,E=w["default"](f({},O,{getCurrentLocation:t,finishTransition:n,cancelTransition:r})),_=0,H=y.supportsGoWithoutReloadUsingHash();return f({},E,{listen:o,pushState:c,replaceState:l,go:h,createHref:m})}e.__esModule=!0;var f=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},l=n(14),d=r(l),h=n(3),p=r(h),g=n(1),v=n(5),y=n(4),m=n(6),w=r(m),O=n(2),P=r(O),b="_k";e["default"]=c,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return t.filter(function(t){return t.state}).reduce(function(t,e){return t[e.key]=e.state,t},{})}function a(){function t(t,e){m[t]=e}function e(t){return m[t]}function n(){var t=v[y],n=t.key,r=t.pathname,o=t.search,a=r+(o||""),i=e(n);return l["default"](a,i,void 0,n)}function r(t){var e=y+t;return e>=0&&e<v.length}function a(t){if(t){s["default"](r(t),"Cannot go(%s); there is not enough history",t),y+=t;var e=n();p.transitionTo(i({},e,{action:c.POP}))}}function u(e){switch(e.action){case c.PUSH:y+=1,y<v.length-1&&v.splice(y),v.push(e),t(e.key,e.state);break;case c.REPLACE:v[y]=e,t(e.key,e.state)}}function f(t){if(t.action===c.POP){var e=0;y+=e}}var d=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];Array.isArray(d)?d={entries:d}:"string"==typeof d&&(d={entries:[d]});var p=h["default"](i({},d,{getCurrentLocation:n,finishTransition:u,cancelTransition:f,go:a})),g=d,v=g.entries,y=g.current;"string"==typeof v?v=[v]:Array.isArray(v)||(v=["/"]),v=v.map(function(t){var e=p.createKey();return"string"==typeof t?{pathname:t,key:e}:"object"==typeof t&&t?i({},t,{key:e}):void s["default"](!1,"Unable to create history entry from %s",t)}),null==y?y=v.length-1:s["default"](y>=0&&y<v.length,"Current index must be >= 0 and < %s, was %s",v.length,y);var m=o(v);return p}e.__esModule=!0;var i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},u=n(3),s=r(u),c=n(1),f=n(2),l=r(f),d=n(7),h=r(d);e["default"]=a,t.exports=e["default"]},function(t,e,n){function r(t){return null===t||void 0===t}function o(t){return t&&"object"==typeof t&&"number"==typeof t.length?"function"!=typeof t.copy||"function"!=typeof t.slice?!1:t.length>0&&"number"!=typeof t[0]?!1:!0:!1}function a(t,e,n){var a,f;if(r(t)||r(e))return!1;if(t.prototype!==e.prototype)return!1;if(s(t))return s(e)?(t=i.call(t),e=i.call(e),c(t,e,n)):!1;if(o(t)){if(!o(e))return!1;if(t.length!==e.length)return!1;for(a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0}try{var l=u(t),d=u(e)}catch(h){return!1}if(l.length!=d.length)return!1;for(l.sort(),d.sort(),a=l.length-1;a>=0;a--)if(l[a]!=d[a])return!1;for(a=l.length-1;a>=0;a--)if(f=l[a],!c(t[f],e[f],n))return!1;return typeof t==typeof e}var i=Array.prototype.slice,u=n(13),s=n(12),c=t.exports=function(t,e,n){return n||(n={}),t===e?!0:t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():"object"!=typeof t&&"object"!=typeof e?n.strict?t===e:t==e:a(t,e,n)}},function(t,e){function n(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function r(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=o?n:r,e.supported=n,e.unsupported=r},function(t,e){function n(t){var e=[];for(var n in t)e.push(n);return e}e=t.exports="function"==typeof Object.keys?Object.keys:n,e.shim=n},function(t,e,n){"use strict";var r=function(){};t.exports=r}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.History=e():t.History=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=n(9),a=r(o);e.createHistory=a["default"];var i=n(10),u=r(i);e.createHashHistory=u["default"];var s=n(11),c=r(s);e.createMemoryHistory=c["default"];var f=n(2),l=r(f);e.createLocation=l["default"];var d=n(1),p=r(d);e.Actions=p["default"]},function(t,e){"use strict";e.__esModule=!0;var n="PUSH";e.PUSH=n;var r="REPLACE";e.REPLACE=r;var o="POP";e.POP=o,e["default"]={PUSH:n,REPLACE:r,POP:o}},function(t,e,n){"use strict";function r(){var t,e,n=arguments.length<=0||void 0===arguments[0]?"/":arguments[0],r=arguments.length<=1||void 0===arguments[1]?null:arguments[1],a=arguments.length<=2||void 0===arguments[2]?o.POP:arguments[2],i=arguments.length<=3||void 0===arguments[3]?null:arguments[3],u=n.indexOf("?");return-1!==u?(t=n.substring(0,u),e=n.substring(u)):(t=n,e=""),""===t&&(t="/"),{pathname:t,search:e,state:r,action:a,key:i}}e.__esModule=!0;var o=n(1);e["default"]=r,t.exports=e["default"]},function(t,e,n){"use strict";var r=function(t,e,n,r,o,a,i,u){if(!t){var s;if(void 0===e)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,a,i,u],f=0;s=new Error("Invariant Violation: "+e.replace(/%s/g,function(){return c[f++]}))}throw s.framesToPop=1,s}};t.exports=r},function(t,e){"use strict";function n(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent("on"+e,n)}function r(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent("on"+e,n)}function o(){return window.location.href.split("#")[1]||""}function a(t){window.location.replace(window.location.pathname+window.location.search+"#"+t)}function i(){return window.location.pathname+window.location.search}function u(t){t&&window.history.go(t)}function s(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history:!1}function c(){var t=navigator.userAgent;return-1===t.indexOf("Firefox")}e.__esModule=!0,e.addEventListener=n,e.removeEventListener=r,e.getHashPath=o,e.replaceHashPath=a,e.getWindowPath=i,e.go=u,e.supportsHistory=s,e.supportsGoWithoutReloadUsingHash=c},function(t,e){"use strict";e.__esModule=!0;var n=!("undefined"==typeof window||!window.document||!window.document.createElement);e.canUseDOM=n},function(t,e){"use strict";function n(t){return a+t}function r(t,e){window.sessionStorage.setItem(n(t),JSON.stringify(e))}function o(t){var e=window.sessionStorage.getItem(n(t));if(e)try{return JSON.parse(e)}catch(r){}return null}e.__esModule=!0,e.saveState=r,e.readState=o;var a="@@History/"},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){e(window.confirm(t))}function a(t){function e(t){var e=n();return"string"==typeof e?((t||window.event).returnValue=e,e):void 0}var n=t.getTransitionConfirmationMessage;return l.addEventListener(window,"beforeunload",e),function(){l.removeEventListener(window,"beforeunload",e)}}function i(t){function e(t){c["default"](f.canUseDOM,"DOM history needs a DOM"),1===++i&&(n=a(r));var e=r.listen(t);return function(){e(),0===--i&&n()}}var n,r=p["default"](u({getUserConfirmation:o},t,{go:l.go})),i=0;return u({},r,{listen:e})}e.__esModule=!0;var u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s=n(3),c=r(s),f=n(5),l=n(4),d=n(8),p=r(d);e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return Math.random().toString(36).substr(2,t)}function a(t,e){return t.pathname===e.pathname&&t.search===e.search&&t.key===e.key&&l["default"](t.state,e.state)}function i(){function t(t){A=t,U.forEach(function(t){t(A)})}function e(t){U.push(t)}function n(t){U=U.filter(function(e){return e!==t})}function r(r){return e(r),A?r(A):t(x()),function(){n(r)}}function i(t){-1===C.indexOf(t)&&C.push(t)}function s(t){C=C.filter(function(e){return e!==t})}function f(){for(var t=null,e=0,n=C.length;n>e&&null==t;++e)t=C[e].call(this);return t}function l(t){var e=f();L&&"string"==typeof e?L(e,function(e){t(e!==!1)}):t(e!==!1)}function p(e){A&&a(A,e)||(c["default"](null==T,"transitionTo: Another transition is already in progress"),T=e,l(function(n){T=null,n?(H(e),t(e)):E&&E(e)}))}function v(t,e){p(h["default"](e,t,d.PUSH,b()))}function y(t,e){p(h["default"](e,t,d.REPLACE,b()))}function m(e){A?(w(A,e),t(A)):w(x(),e)}function w(t,e){t.state=u({},t.state,e),M(t.key,t.state)}function O(){j(-1)}function P(){j(1)}function b(){return o(k)}function S(t){return t}var _=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],x=_.getCurrentLocation,H=_.finishTransition,E=_.cancelTransition,M=_.saveState,j=_.go,k=_.keyLength,L=_.getUserConfirmation;"number"!=typeof k&&(k=g);var A,T,C=[],U=[];return{listen:r,registerTransitionHook:i,unregisterTransitionHook:s,getTransitionConfirmationMessage:f,transitionTo:p,pushState:v,replaceState:y,setState:m,go:j,goBack:O,goForward:P,createKey:b,createHref:S}}e.__esModule=!0;var u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s=n(3),c=r(s),f=n(12),l=r(f),d=n(1),p=n(2),h=r(p),g=6;e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){function e(t){t=t||window.history.state||{};var e,n=f.getWindowPath(),r=t,o=r.key;return o?e=l.readState(o):(e=null,o=v.createKey(),window.history.replaceState(a({},t,{key:o}),n)),g["default"](n,e,void 0,o)}function n(t){function n(t){void 0!==t.state&&r(e(t.state))}var r=t.transitionTo;return f.addEventListener(window,"popstate",n),function(){f.removeEventListener(window,"popstate",n)}}function r(t){var e=t.pathname,n=t.search,r=t.state,o=t.action,a=t.key;if(o!==s.POP){l.saveState(a,r);var i=e+n,u={key:a};o===s.PUSH?h?window.history.pushState(u,null,i):window.location.href=i:h?window.history.replaceState(u,null,i):window.location.replace(i)}}function o(t){if(t.action===s.POP){var e=0;f.go(e)}}function i(t){var e=v.listen(t);return 1===++y&&(d=n(v)),function(){0===--y&&d(),e()}}u["default"](c.canUseDOM,"Browser history needs a DOM");var d,h=f.supportsHistory(),v=p["default"](a({},t,{getCurrentLocation:e,finishTransition:r,cancelTransition:o,saveState:l.saveState})),y=0;return a({},v,{listen:i})}e.__esModule=!0;var a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i=n(3),u=r(i),s=n(1),c=n(5),f=n(4),l=n(6),d=n(7),p=r(d),h=n(2),g=r(h);e["default"]=o,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return"string"==typeof t&&"/"===t.charAt(0)}function a(){var t=y.getHashPath();return o(t)?!0:(y.replaceHashPath("/"+t),!1)}function i(t,e,n){return t+(-1===t.indexOf("?")?"?":"&")+(e+"="+n)}function u(t,e){return t.replace(new RegExp("[?&]?"+e+"=[a-zA-Z0-9]+"),"")}function s(t,e){var n=t.match(new RegExp("\\?.*?\\b"+e+"=(.+?)\\b"));return n&&n[1]}function c(){function t(){var t,e,n=y.getHashPath();return _&&(t=s(n,_),n=u(n,_),t?e=m.readState(t):(e=null,t=H.createKey(),y.replaceHashPath(i(n,_,t)))),b["default"](n,e,void 0,t)}function e(e){function n(){a()&&r(t())}var r=e.transitionTo;return a(),y.addEventListener(window,"hashchange",n),function(){y.removeEventListener(window,"hashchange",n)}}function n(t){var e=t.pathname,n=t.search,r=t.state,o=t.action,a=t.key;if(o!==g.POP){var u=e+n;_&&(u=i(u,_,a)),u===y.getHashPath()?d["default"](!1,"You cannot %s the same path using hash history",o):(_?m.saveState(a,r):t.key=t.state=null,o===g.PUSH?window.location.hash=u:y.replaceHashPath(u))}}function r(t){if(t.action===g.POP){var e=0;p(e)}}function o(t){var n=H.listen(t);return 1===++E&&(x=e(H)),function(){0===--E&&x(),n()}}function c(t,e){d["default"](_||null==t,"You cannot use state without a queryKey; it will be dropped"),H.pushState(t,e)}function l(t,e){d["default"](_||null==t,"You cannot use state without a queryKey; it will be dropped"),H.replaceState(t,e)}function p(t){d["default"](M,"Hash history go(n) causes a full page reload in this browser"),H.go(t)}function w(t){return"#"+H.createHref(t)}var P=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];h["default"](v.canUseDOM,"Hash history needs a DOM");var _=P.queryKey;(void 0===_||_)&&(_="string"==typeof _?_:S);var x,H=O["default"](f({},P,{getCurrentLocation:t,finishTransition:n,cancelTransition:r,saveState:m.saveState})),E=0,M=y.supportsGoWithoutReloadUsingHash();return f({},H,{listen:o,pushState:c,replaceState:l,go:p,createHref:w})}e.__esModule=!0;var f=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},l=n(15),d=r(l),p=n(3),h=r(p),g=n(1),v=n(5),y=n(4),m=n(6),w=n(7),O=r(w),P=n(2),b=r(P),S="_k";e["default"]=c,t.exports=e["default"]},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t){return t.filter(function(t){return t.state}).reduce(function(t,e){return t[e.key]=e.state,t},{})}function a(){function t(t,e){m[t]=e}function e(t){return m[t]}function n(){var t,n=v[y],r=n.key,o=n.pathname,a=n.search,i=o+(a||"");return r?t=e(r):(t=null,r=h.createKey(),n.key=r),l["default"](i,t,void 0,r)}function r(t){var e=y+t;return e>=0&&e<v.length}function a(t){if(t){s["default"](r(t),"Cannot go(%s); there is not enough history",t),y+=t;var e=n();h.transitionTo(i({},e,{action:c.POP}))}}function u(e){switch(e.action){case c.PUSH:y+=1,y<v.length-1&&v.splice(y),v.push(e),t(e.key,e.state);break;case c.REPLACE:v[y]=e,t(e.key,e.state)}}function f(t){if(t.action===c.POP){var e=0;y+=e}}var d=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];Array.isArray(d)?d={entries:d}:"string"==typeof d&&(d={entries:[d]});var h=p["default"](i({},d,{getCurrentLocation:n,finishTransition:u,cancelTransition:f,saveState:t,go:a})),g=d,v=g.entries,y=g.current;"string"==typeof v?v=[v]:Array.isArray(v)||(v=["/"]),v=v.map(function(t){var e=h.createKey();return"string"==typeof t?{pathname:t,key:e}:"object"==typeof t&&t?i({},t,{key:e}):void s["default"](!1,"Unable to create history entry from %s",t)}),null==y?y=v.length-1:s["default"](y>=0&&y<v.length,"Current index must be >= 0 and < %s, was %s",v.length,y);var m=o(v);return h}e.__esModule=!0;var i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},u=n(3),s=r(u),c=n(1),f=n(2),l=r(f),d=n(8),p=r(d);e["default"]=a,t.exports=e["default"]},function(t,e,n){function r(t){return null===t||void 0===t}function o(t){return t&&"object"==typeof t&&"number"==typeof t.length?"function"!=typeof t.copy||"function"!=typeof t.slice?!1:t.length>0&&"number"!=typeof t[0]?!1:!0:!1}function a(t,e,n){var a,f;if(r(t)||r(e))return!1;if(t.prototype!==e.prototype)return!1;if(s(t))return s(e)?(t=i.call(t),e=i.call(e),c(t,e,n)):!1;if(o(t)){if(!o(e))return!1;if(t.length!==e.length)return!1;for(a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0}try{var l=u(t),d=u(e)}catch(p){return!1}if(l.length!=d.length)return!1;for(l.sort(),d.sort(),a=l.length-1;a>=0;a--)if(l[a]!=d[a])return!1;for(a=l.length-1;a>=0;a--)if(f=l[a],!c(t[f],e[f],n))return!1;return typeof t==typeof e}var i=Array.prototype.slice,u=n(14),s=n(13),c=t.exports=function(t,e,n){return n||(n={}),t===e?!0:t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():"object"!=typeof t&&"object"!=typeof e?n.strict?t===e:t==e:a(t,e,n)}},function(t,e){function n(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function r(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=o?n:r,e.supported=n,e.unsupported=r},function(t,e){function n(t){var e=[];for(var n in t)e.push(n);return e}e=t.exports="function"==typeof Object.keys?Object.keys:n,e.shim=n},function(t,e,n){"use strict";var r=function(){};t.exports=r}])}); |
import invariant from 'invariant'; | ||
import { PUSH, REPLACE, POP } from './Actions'; | ||
import { canUseDOM } from './ExecutionEnvironment'; | ||
import { addEventListener, removeEventListener, readState, saveState, getWindowPath, go, supportsHistory } from './DOMUtils'; | ||
import { addEventListener, removeEventListener, getWindowPath, go, supportsHistory } from './DOMUtils'; | ||
import { saveState, readState } from './DOMStateStorage'; | ||
import createDOMHistory from './createDOMHistory'; | ||
import createLocation from './createLocation'; | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var { key } = historyState; | ||
var state = key && readState(key); | ||
var path = getWindowPath(); | ||
return createLocation(path, state, undefined, key); | ||
} | ||
function startPopStateListener({ transitionTo }) { | ||
function popStateListener(event) { | ||
if (event.state === undefined) | ||
return; // Ignore extraneous popstate events in WebKit. | ||
transitionTo( | ||
getCurrentLocation(event.state) | ||
); | ||
} | ||
addEventListener(window, 'popstate', popStateListener); | ||
return function () { | ||
removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
/** | ||
@@ -52,4 +26,45 @@ * Creates and returns a history object that uses HTML5's history API | ||
function getCurrentLocation(historyState) { | ||
historyState = historyState || window.history.state || {}; | ||
var path = getWindowPath(); | ||
var { key } = historyState; | ||
var state; | ||
if (key) { | ||
state = readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
window.history.replaceState({ ...historyState, key }, path); | ||
} | ||
return createLocation(path, state, undefined, key); | ||
} | ||
function startPopStateListener({ transitionTo }) { | ||
function popStateListener(event) { | ||
if (event.state === undefined) | ||
return; // Ignore extraneous popstate events in WebKit. | ||
transitionTo( | ||
getCurrentLocation(event.state) | ||
); | ||
} | ||
addEventListener(window, 'popstate', popStateListener); | ||
return function () { | ||
removeEventListener(window, 'popstate', popStateListener); | ||
}; | ||
} | ||
function finishTransition(location) { | ||
var { key, pathname, search } = location; | ||
var { pathname, search, state, action, key } = location; | ||
if (action === POP) | ||
return; // Nothing to do. | ||
saveState(key, state); | ||
var path = pathname + search; | ||
@@ -60,21 +75,14 @@ var historyState = { | ||
switch (location.action) { | ||
case PUSH: | ||
saveState(location.key, location.state); | ||
if (isSupported) { | ||
window.history.pushState(historyState, null, path); | ||
} else { | ||
window.location.href = path; // Use page reload to preserve the URL. | ||
} | ||
break; | ||
case REPLACE: | ||
saveState(location.key, location.state); | ||
if (isSupported) { | ||
window.history.replaceState(historyState, null, path); | ||
} else { | ||
window.location.replace(path); // Use page reload to preserve the URL. | ||
} | ||
break; | ||
if (action === PUSH) { | ||
if (isSupported) { | ||
window.history.pushState(historyState, null, path); | ||
} else { | ||
window.location.href = path; // Use page reload to preserve the URL. | ||
} | ||
} else { // REPLACE | ||
if (isSupported) { | ||
window.history.replaceState(historyState, null, path); | ||
} else { | ||
window.location.replace(path); // Use page reload to preserve the URL. | ||
} | ||
} | ||
@@ -94,3 +102,4 @@ } | ||
finishTransition, | ||
cancelTransition | ||
cancelTransition, | ||
saveState | ||
}); | ||
@@ -101,12 +110,12 @@ | ||
function listen(listener) { | ||
var unlisten = history.listen(listener); | ||
if (++listenerCount === 1) | ||
stopPopStateListener = startPopStateListener(history); | ||
var unlisten = history.listen(listener); | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) | ||
stopPopStateListener(); | ||
unlisten(); | ||
}; | ||
@@ -113,0 +122,0 @@ } |
import invariant from 'invariant'; | ||
import { canUseDOM } from './ExecutionEnvironment'; | ||
import { addEventListener, removeEventListener, saveState, readState, go } from './DOMUtils'; | ||
import { addEventListener, removeEventListener, go } from './DOMUtils'; | ||
import createHistory from './createHistory'; | ||
@@ -31,4 +31,2 @@ | ||
...options, | ||
saveState, | ||
readState, | ||
go | ||
@@ -35,0 +33,0 @@ }); |
@@ -5,3 +5,4 @@ import warning from 'warning'; | ||
import { canUseDOM } from './ExecutionEnvironment'; | ||
import { addEventListener, removeEventListener, readState, saveState, getHashPath, replaceHashPath, supportsGoWithoutReloadUsingHash } from './DOMUtils'; | ||
import { addEventListener, removeEventListener, getHashPath, replaceHashPath, supportsGoWithoutReloadUsingHash } from './DOMUtils'; | ||
import { saveState, readState } from './DOMStateStorage'; | ||
import createDOMHistory from './createDOMHistory'; | ||
@@ -58,3 +59,10 @@ import createLocation from './createLocation'; | ||
path = stripQueryStringValueFromPath(path, queryKey); | ||
state = key && readState(key); | ||
if (key) { | ||
state = readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
replaceHashPath(addQueryStringValueToPath(path, queryKey, key)); | ||
} | ||
} | ||
@@ -84,3 +92,3 @@ | ||
function finishTransition(location) { | ||
var { key, pathname, search, action } = location; | ||
var { pathname, search, state, action, key } = location; | ||
@@ -103,3 +111,3 @@ if (action === POP) | ||
if (queryKey) { | ||
saveState(location.key, location.state); | ||
saveState(key, state); | ||
} else { | ||
@@ -112,3 +120,3 @@ // Drop key and state. | ||
window.location.hash = path; | ||
} else { | ||
} else { // REPLACE | ||
replaceHashPath(path); | ||
@@ -130,3 +138,4 @@ } | ||
finishTransition, | ||
cancelTransition | ||
cancelTransition, | ||
saveState | ||
}); | ||
@@ -137,12 +146,12 @@ | ||
function listen(listener) { | ||
var unlisten = history.listen(listener); | ||
if (++listenerCount === 1) | ||
stopHashChangeListener = startHashChangeListener(history); | ||
var unlisten = history.listen(listener); | ||
return function () { | ||
unlisten(); | ||
if (--listenerCount === 0) | ||
stopHashChangeListener(); | ||
unlisten(); | ||
}; | ||
@@ -149,0 +158,0 @@ } |
@@ -21,3 +21,3 @@ import invariant from 'invariant'; | ||
function createHistory(options={}) { | ||
var { getCurrentLocation, finishTransition, cancelTransition, go, keyLength, getUserConfirmation } = options; | ||
var { getCurrentLocation, finishTransition, cancelTransition, saveState, go, keyLength, getUserConfirmation } = options; | ||
@@ -73,3 +73,3 @@ if (typeof keyLength !== 'number') | ||
for (var i = 0, len = transitionHooks.length; i < len && typeof message !== 'string'; ++i) | ||
for (var i = 0, len = transitionHooks.length; i < len && message == null; ++i) | ||
message = transitionHooks[i].call(this); | ||
@@ -81,5 +81,5 @@ | ||
function confirmTransition(callback) { | ||
var message; | ||
var message = getTransitionConfirmationMessage(); | ||
if (getUserConfirmation && (message = getTransitionConfirmationMessage())) { | ||
if (getUserConfirmation && typeof message === 'string') { | ||
getUserConfirmation(message, function (ok) { | ||
@@ -89,3 +89,3 @@ callback(ok !== false); | ||
} else { | ||
callback(true); | ||
callback(message !== false); | ||
} | ||
@@ -131,2 +131,16 @@ } | ||
function setState(state) { | ||
if (location) { | ||
updateLocationState(location, state); | ||
updateLocation(location); | ||
} else { | ||
updateLocationState(getCurrentLocation(), state); | ||
} | ||
} | ||
function updateLocationState(location, state) { | ||
location.state = { ...location.state, ...state }; | ||
saveState(location.key, location.state); | ||
} | ||
function goBack() { | ||
@@ -156,2 +170,3 @@ go(-1); | ||
replaceState, | ||
setState, | ||
go, | ||
@@ -158,0 +173,0 @@ goBack, |
@@ -27,2 +27,3 @@ import invariant from 'invariant'; | ||
cancelTransition, | ||
saveState, | ||
go | ||
@@ -76,6 +77,15 @@ }); | ||
function getCurrentLocation() { | ||
var { key, pathname, search } = entries[current]; | ||
var entry = entries[current]; | ||
var { key, pathname, search } = entry; | ||
var path = pathname + (search || ''); | ||
var state = readState(key); | ||
var state; | ||
if (key) { | ||
state = readState(key); | ||
} else { | ||
state = null; | ||
key = history.createKey(); | ||
entry.key = key; | ||
} | ||
return createLocation(path, state, undefined, key); | ||
@@ -82,0 +92,0 @@ } |
@@ -33,20 +33,2 @@ export function addEventListener(node, event, listener) { | ||
export function saveState(key, state) { | ||
window.sessionStorage.setItem(key, JSON.stringify(state)); | ||
} | ||
export function readState(key) { | ||
var json = window.sessionStorage.getItem(key); | ||
if (json) { | ||
try { | ||
return JSON.parse(json); | ||
} catch (error) { | ||
// Ignore invalid JSON. | ||
} | ||
} | ||
return null; | ||
} | ||
export function go(n) { | ||
@@ -53,0 +35,0 @@ if (n) |
{ | ||
"name": "history", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A minimal, functional history implementation for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
@@ -5,3 +5,3 @@ [![build status](https://img.shields.io/travis/rackt/history/master.svg?style=flat-square)](https://travis-ci.org/rackt/history) | ||
[`history`](https://www.npmjs.com/package/history) is a small, powerful JavaScript library that lets you easily manage session history in browsers, testing environments, and (soon, via [React Native](https://facebook.github.io/react-native/)) native devices. `history` abstracts away the differences in these different platforms and provides a minimal API that lets you manage the history stack, navigate, confirm navigation, and persist state between sessions. `history` is library-agnostic and may easily be included in any JavaScript project. | ||
[`history`](https://www.npmjs.com/package/history) is a JavaScript library that lets you easily manage session history in browsers, testing environments, and (soon, via [React Native](https://facebook.github.io/react-native/)) native devices. `history` abstracts away the differences in these different platforms and provides a minimal API that lets you manage the history stack, navigate, confirm navigation, and persist state between sessions. `history` is library-agnostic and may easily be included in any JavaScript project. | ||
@@ -63,2 +63,3 @@ ### Installation | ||
- `replaceState(state, path)` | ||
- `setState(state)` | ||
- `go(n)` | ||
@@ -68,3 +69,3 @@ - `goBack()` | ||
The `path` argument to `pushState` and `replaceState` represents a complete URL path, including the query string. The `state` argument should be a JSON-serializable object. | ||
The `path` argument to `pushState` and `replaceState` represents a complete URL path, including the query string. The `state` argument should be a JSON-serializable object. In `setState`, the properties in `state` are shallowly merged into the current state. | ||
@@ -95,3 +96,3 @@ ```js | ||
You can dynamically add/remove transition hooks using `unregisterTransitionHook` as well. | ||
You can also simply `return false` to prevent a transition. | ||
@@ -129,1 +130,3 @@ In browsers, `history` uses [`window.confirm`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm) by default to display confirmation messages to users. However, you can provide your own custom confirmation dialog box using the `getUserConfirmation` hook when you create your `history` object. | ||
A big thank-you to [Dan Shaw](https://www.npmjs.com/~dshaw) for letting us use the `history` npm package name! Thanks Dan! | ||
Also, thanks to [BrowserStack](https://www.browserstack.com/) for providing the infrastructure that allows us to run our build in real browsers. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115892
39
2668
128