navigation-stack 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +603 -163
- package/data-storage/package.json +6 -0
- package/karma.conf.cjs +21 -4
- package/lib/cjs/NavigationStack.js +73 -0
- package/lib/cjs/data-storage/DataStorage.js +71 -0
- package/lib/cjs/data-storage/LocationDataStorage.js +29 -0
- package/lib/cjs/data-storage/index.js +9 -0
- package/lib/cjs/environment/InMemoryEnvironment.js +15 -0
- package/lib/cjs/environment/WebBrowserEnvironment.js +15 -0
- package/lib/cjs/environment/data-storage/InMemoryDataStorage.js +27 -0
- package/lib/cjs/environment/data-storage/WebBrowserDataStorage.js +21 -0
- package/lib/cjs/environment/scroll-position/InMemoryScrollPosition.js +44 -0
- package/lib/cjs/environment/scroll-position/WebBrowserScrollPosition.js +60 -0
- package/lib/cjs/getLocationFromInternalLocation.js +14 -0
- package/lib/cjs/index.js +20 -16
- package/lib/cjs/navigationBlockers.js +25 -23
- package/lib/cjs/{normalizeInputLocation.js → parseInputLocation.js} +25 -9
- package/lib/cjs/{ActionTypes.js → redux/ActionTypes.js} +1 -1
- package/lib/cjs/redux/ActionTypesInternal.js +8 -0
- package/lib/cjs/{Actions.js → redux/Actions.js} +5 -4
- package/lib/cjs/redux/createMiddlewares.js +60 -0
- package/lib/cjs/redux/index.js +13 -0
- package/lib/cjs/redux/internalLocationReducer.js +14 -0
- package/lib/cjs/redux/middleware/createAddInputLocationBasePathMiddleware.js +32 -0
- package/lib/cjs/redux/middleware/createNonProgrammaticNavigationBlockerMiddleware.js +113 -0
- package/lib/cjs/redux/middleware/createProgrammaticNavigationBlockerMiddleware.js +94 -0
- package/lib/cjs/redux/middleware/createRemoveOutputLocationBasePathMiddleware.js +30 -0
- package/lib/cjs/redux/middleware/createUpdateInternalLocationMiddleware.js +73 -0
- package/lib/cjs/{middleware/navigationActionMiddleware.js → redux/middleware/navigationOperationMiddleware.js} +11 -8
- package/lib/cjs/{middleware/normalizeInputLocationMiddleware.js → redux/middleware/parseInputLocationMiddleware.js} +6 -4
- package/lib/cjs/redux/middleware/updateLocationMiddleware.js +34 -0
- package/lib/cjs/scroll-position/PageScrollPositionSetter.js +97 -0
- package/lib/cjs/scroll-position/ScrollPositionAutoSaver.js +130 -0
- package/lib/cjs/scroll-position/ScrollPositionRestoration.js +383 -0
- package/lib/cjs/scroll-position/ScrollPositionSaver.js +81 -0
- package/lib/cjs/scroll-position/ScrollPositionSetter.js +16 -0
- package/lib/cjs/scroll-position/constants.js +5 -0
- package/lib/cjs/scroll-position/index.js +7 -0
- package/lib/cjs/scroll-position/scheduleNextTick.js +11 -0
- package/lib/cjs/session/InMemorySession.js +22 -0
- package/lib/cjs/session/ServerSideRenderSession.js +17 -0
- package/lib/cjs/session/Session.js +196 -0
- package/lib/cjs/session/WebBrowserSession.js +20 -0
- package/lib/cjs/session/key/createSessionKey.js +23 -0
- package/lib/cjs/session/lifecycle/InMemorySessionLifecycle.js +19 -0
- package/lib/cjs/session/lifecycle/WebBrowserSessionLifecycle.js +128 -0
- package/lib/cjs/session/lifecycle/page-lifecycle/PageLifecycle.js +269 -0
- package/lib/cjs/session/lifecycle/page-lifecycle/PageLifecycleInstance.js +8 -0
- package/lib/cjs/session/lifecycle/page-lifecycle/supportsConstructableEventTarget.js +33 -0
- package/lib/cjs/session/navigation/InMemoryNavigation.js +104 -0
- package/lib/cjs/session/navigation/ServerSideNavigation.js +61 -0
- package/lib/cjs/session/navigation/WebBrowserNavigation.js +221 -0
- package/lib/cjs/session/navigation/error/NavigationOutOfBoundsError.js +12 -0
- package/lib/cjs/session/navigation/error/ServerSideNavigationError.js +21 -0
- package/lib/cjs/session/navigation/operation/operations.js +11 -0
- package/lib/cjs/session/subscription/Subscription.js +81 -0
- package/lib/data-storage/index.d.ts +35 -0
- package/lib/esm/NavigationStack.js +66 -0
- package/lib/esm/data-storage/DataStorage.js +65 -0
- package/lib/esm/data-storage/LocationDataStorage.js +22 -0
- package/lib/esm/data-storage/index.js +2 -0
- package/lib/esm/environment/InMemoryEnvironment.js +8 -0
- package/lib/esm/environment/WebBrowserEnvironment.js +8 -0
- package/lib/esm/environment/data-storage/InMemoryDataStorage.js +21 -0
- package/lib/esm/environment/data-storage/WebBrowserDataStorage.js +15 -0
- package/lib/esm/environment/scroll-position/InMemoryScrollPosition.js +38 -0
- package/lib/esm/environment/scroll-position/WebBrowserScrollPosition.js +54 -0
- package/lib/esm/getLocationFromInternalLocation.js +9 -0
- package/lib/esm/index.js +10 -8
- package/lib/esm/navigationBlockers.js +25 -23
- package/lib/esm/{normalizeInputLocation.js → parseInputLocation.js} +24 -8
- package/lib/esm/{ActionTypes.js → redux/ActionTypes.js} +1 -1
- package/lib/esm/redux/ActionTypesInternal.js +3 -0
- package/lib/esm/{Actions.js → redux/Actions.js} +5 -4
- package/lib/esm/redux/createMiddlewares.js +54 -0
- package/lib/esm/redux/index.js +4 -0
- package/lib/esm/redux/internalLocationReducer.js +8 -0
- package/lib/esm/redux/middleware/createAddInputLocationBasePathMiddleware.js +27 -0
- package/lib/esm/redux/middleware/createNonProgrammaticNavigationBlockerMiddleware.js +108 -0
- package/lib/esm/redux/middleware/createProgrammaticNavigationBlockerMiddleware.js +88 -0
- package/lib/esm/redux/middleware/createRemoveOutputLocationBasePathMiddleware.js +25 -0
- package/lib/esm/redux/middleware/createUpdateInternalLocationMiddleware.js +68 -0
- package/lib/esm/{middleware/navigationActionMiddleware.js → redux/middleware/navigationOperationMiddleware.js} +10 -7
- package/lib/esm/{middleware/normalizeInputLocationMiddleware.js → redux/middleware/parseInputLocationMiddleware.js} +5 -3
- package/lib/esm/redux/middleware/updateLocationMiddleware.js +28 -0
- package/lib/esm/scroll-position/PageScrollPositionSetter.js +91 -0
- package/lib/esm/scroll-position/ScrollPositionAutoSaver.js +123 -0
- package/lib/esm/scroll-position/ScrollPositionRestoration.js +376 -0
- package/lib/esm/scroll-position/ScrollPositionSaver.js +74 -0
- package/lib/esm/scroll-position/ScrollPositionSetter.js +10 -0
- package/lib/esm/scroll-position/constants.js +1 -0
- package/lib/esm/scroll-position/index.js +1 -0
- package/lib/esm/scroll-position/scheduleNextTick.js +6 -0
- package/lib/esm/session/InMemorySession.js +15 -0
- package/lib/esm/session/ServerSideRenderSession.js +11 -0
- package/lib/esm/session/Session.js +189 -0
- package/lib/esm/session/WebBrowserSession.js +13 -0
- package/lib/esm/session/key/createSessionKey.js +18 -0
- package/lib/esm/session/lifecycle/InMemorySessionLifecycle.js +13 -0
- package/lib/esm/session/lifecycle/WebBrowserSessionLifecycle.js +120 -0
- package/lib/esm/session/lifecycle/page-lifecycle/PageLifecycle.js +263 -0
- package/lib/esm/session/lifecycle/page-lifecycle/PageLifecycleInstance.js +2 -0
- package/lib/esm/session/lifecycle/page-lifecycle/supportsConstructableEventTarget.js +30 -0
- package/lib/esm/session/navigation/InMemoryNavigation.js +97 -0
- package/lib/esm/session/navigation/ServerSideNavigation.js +54 -0
- package/lib/esm/session/navigation/WebBrowserNavigation.js +213 -0
- package/lib/esm/session/navigation/error/NavigationOutOfBoundsError.js +6 -0
- package/lib/esm/session/navigation/error/ServerSideNavigationError.js +14 -0
- package/lib/esm/session/navigation/operation/operations.js +6 -0
- package/lib/esm/session/subscription/Subscription.js +75 -0
- package/lib/index.d.ts +178 -157
- package/lib/redux/index.d.ts +90 -0
- package/lib/scroll-position/index.d.ts +107 -0
- package/package.json +9 -5
- package/redux/package.json +6 -0
- package/scroll-position/package.json +6 -0
- package/src/NavigationStack.js +84 -0
- package/src/data-storage/DataStorage.js +69 -0
- package/src/data-storage/LocationDataStorage.js +23 -0
- package/src/data-storage/index.js +2 -0
- package/src/environment/InMemoryEnvironment.js +9 -0
- package/src/environment/WebBrowserEnvironment.js +9 -0
- package/src/environment/data-storage/InMemoryDataStorage.js +23 -0
- package/src/environment/data-storage/WebBrowserDataStorage.js +17 -0
- package/src/environment/scroll-position/InMemoryScrollPosition.js +45 -0
- package/src/environment/scroll-position/WebBrowserScrollPosition.js +72 -0
- package/src/getLocationFromInternalLocation.js +7 -0
- package/src/index.js +10 -8
- package/src/navigationBlockers.js +28 -27
- package/src/{normalizeInputLocation.js → parseInputLocation.js} +23 -8
- package/src/{ActionTypes.js → redux/ActionTypes.js} +1 -1
- package/src/redux/ActionTypesInternal.js +3 -0
- package/src/{Actions.js → redux/Actions.js} +4 -3
- package/src/redux/createMiddlewares.js +65 -0
- package/src/redux/index.js +4 -0
- package/src/redux/internalLocationReducer.js +9 -0
- package/src/redux/middleware/createAddInputLocationBasePathMiddleware.js +27 -0
- package/src/redux/middleware/createNonProgrammaticNavigationBlockerMiddleware.js +119 -0
- package/src/redux/middleware/createProgrammaticNavigationBlockerMiddleware.js +94 -0
- package/src/redux/middleware/createRemoveOutputLocationBasePathMiddleware.js +26 -0
- package/src/redux/middleware/createUpdateInternalLocationMiddleware.js +72 -0
- package/src/{middleware/navigationActionMiddleware.js → redux/middleware/navigationOperationMiddleware.js} +10 -3
- package/src/{middleware/normalizeInputLocationMiddleware.js → redux/middleware/parseInputLocationMiddleware.js} +5 -3
- package/src/redux/middleware/updateLocationMiddleware.js +28 -0
- package/src/scroll-position/PageScrollPositionSetter.js +110 -0
- package/src/scroll-position/ScrollPositionAutoSaver.js +151 -0
- package/src/scroll-position/ScrollPositionRestoration.js +506 -0
- package/src/scroll-position/ScrollPositionSaver.js +100 -0
- package/src/scroll-position/ScrollPositionSetter.js +16 -0
- package/src/scroll-position/constants.js +1 -0
- package/src/scroll-position/index.js +1 -0
- package/src/scroll-position/scheduleNextTick.js +6 -0
- package/src/session/InMemorySession.js +13 -0
- package/src/session/ServerSideRenderSession.js +9 -0
- package/src/session/Session.js +216 -0
- package/src/session/WebBrowserSession.js +13 -0
- package/src/session/key/createSessionKey.js +18 -0
- package/src/session/lifecycle/InMemorySessionLifecycle.js +13 -0
- package/src/session/lifecycle/WebBrowserSessionLifecycle.js +126 -0
- package/src/session/lifecycle/page-lifecycle/PageLifecycle.js +291 -0
- package/src/session/lifecycle/page-lifecycle/PageLifecycleInstance.js +3 -0
- package/src/session/lifecycle/page-lifecycle/supportsConstructableEventTarget.js +32 -0
- package/src/session/navigation/InMemoryNavigation.js +78 -0
- package/src/session/navigation/ServerSideNavigation.js +43 -0
- package/src/session/navigation/WebBrowserNavigation.js +224 -0
- package/src/session/navigation/error/NavigationOutOfBoundsError.js +7 -0
- package/src/session/navigation/error/ServerSideNavigationError.js +18 -0
- package/src/session/navigation/operation/operations.js +6 -0
- package/src/session/subscription/Subscription.js +76 -0
- package/test/NavigationStack.test.js +296 -0
- package/test/{LocationDataStorage.test.js → data-storage/LocationDataStorage.test.js} +3 -3
- package/test/data-storage/index.test.js +8 -0
- package/test/index.js +12 -0
- package/test/index.test.js +8 -7
- package/test/{helpers.js → middlewareTestUtil.js} +9 -12
- package/test/{normalizeInputLocation.test.js → parseInputLocationMiddleware.test.js} +9 -9
- package/test/{Action.test.js → redux/Action.test.js} +7 -6
- package/test/{ActionTypes.test.js → redux/ActionTypes.test.js} +2 -2
- package/test/redux/createMiddlewares.test.js +96 -0
- package/test/redux/index.test.js +10 -0
- package/test/{locationReducer.test.js → redux/locationReducer.test.js} +4 -7
- package/test/redux/middleware/createAddInputLocationBasePathMiddleware.test.js +40 -0
- package/test/redux/middleware/createNonProgrammaticNavigationBlockerMiddleware.test.js +264 -0
- package/test/redux/middleware/createProgrammaticNavigationBlockerMiddleware.test.js +312 -0
- package/test/redux/middleware/createRemoveOutputLocationBasePathMiddleware.test.js +51 -0
- package/test/{middleware/navigationActionMiddleware.test.js → redux/middleware/navigationOperationMiddleware.test.js} +16 -12
- package/test/{middleware/normalizeInputLocationMiddleware.test.js → redux/middleware/parseInputLocationMiddleware.test.js} +4 -4
- package/test/scroll-position/ScrollPositionRestoration.test.js +418 -0
- package/test/scroll-position/addScrollableContainer.js +36 -0
- package/test/scroll-position/addScrollableContainerWithHyperlink.js +50 -0
- package/test/scroll-position/createApp.js +112 -0
- package/test/scroll-position/delay.js +9 -0
- package/test/scroll-position/mockPageLifecycle.js +17 -0
- package/test/scroll-position/runApp.js +24 -0
- package/test/scroll-position/withScrollableContainerAtIndexPage.js +62 -0
- package/test/session/InMemorySession.test.js +348 -0
- package/test/session/ServerSession.test.js +17 -9
- package/test/session/WebBrowserSession.test.js +265 -0
- package/test/testUtil.js +3 -0
- package/types/data-storage/index.d.ts +35 -0
- package/types/index.d.ts +178 -157
- package/types/redux/index.d.ts +90 -0
- package/types/scroll-position/index.d.ts +107 -0
- package/types/tsconfig.json +1 -1
- package/lib/cjs/LocationDataStorage.js +0 -61
- package/lib/cjs/addBeforeLocationChangeListener.js +0 -7
- package/lib/cjs/beforeLocationChangeListeners.js +0 -51
- package/lib/cjs/createMiddlewares.js +0 -47
- package/lib/cjs/middleware/createBasePathMiddleware.js +0 -24
- package/lib/cjs/middleware/createBeforeLocationChangeListenerMiddleware.js +0 -39
- package/lib/cjs/middleware/createLocationMiddleware.js +0 -56
- package/lib/cjs/middleware/createNavigationBlockerMiddleware.js +0 -161
- package/lib/cjs/middleware/createTransformLocationMiddleware.js +0 -38
- package/lib/cjs/onlyAllowedOnClientSide.js +0 -10
- package/lib/cjs/session/BrowserSession.js +0 -235
- package/lib/cjs/session/MemorySession.js +0 -223
- package/lib/cjs/session/ServerSession.js +0 -65
- package/lib/esm/LocationDataStorage.js +0 -54
- package/lib/esm/addBeforeLocationChangeListener.js +0 -2
- package/lib/esm/beforeLocationChangeListeners.js +0 -44
- package/lib/esm/createMiddlewares.js +0 -41
- package/lib/esm/middleware/createBasePathMiddleware.js +0 -19
- package/lib/esm/middleware/createBeforeLocationChangeListenerMiddleware.js +0 -34
- package/lib/esm/middleware/createLocationMiddleware.js +0 -50
- package/lib/esm/middleware/createNavigationBlockerMiddleware.js +0 -156
- package/lib/esm/middleware/createTransformLocationMiddleware.js +0 -33
- package/lib/esm/onlyAllowedOnClientSide.js +0 -5
- package/lib/esm/session/BrowserSession.js +0 -229
- package/lib/esm/session/MemorySession.js +0 -217
- package/lib/esm/session/ServerSession.js +0 -58
- package/src/LocationDataStorage.js +0 -60
- package/src/addBeforeLocationChangeListener.js +0 -2
- package/src/beforeLocationChangeListeners.js +0 -54
- package/src/createMiddlewares.js +0 -45
- package/src/middleware/createBasePathMiddleware.js +0 -20
- package/src/middleware/createBeforeLocationChangeListenerMiddleware.js +0 -40
- package/src/middleware/createLocationMiddleware.js +0 -55
- package/src/middleware/createNavigationBlockerMiddleware.js +0 -168
- package/src/middleware/createTransformLocationMiddleware.js +0 -29
- package/src/onlyAllowedOnClientSide.js +0 -5
- package/src/session/BrowserSession.js +0 -235
- package/src/session/MemorySession.js +0 -219
- package/src/session/ServerSession.js +0 -67
- package/test/createMiddlewares.test.js +0 -62
- package/test/middleware/createBasePathMiddleware.test.js +0 -67
- package/test/middleware/createBeforeLocationChangeListenerMiddleware.test.js +0 -141
- package/test/middleware/createNavigationBlockerMiddleware.test.js +0 -471
- package/test/middleware/createTransformLocationMiddleware.test.js +0 -44
- package/test/session/BrowserSession.test.js +0 -182
- package/test/session/MemorySession.test.js +0 -244
- /package/lib/cjs/{locationReducer.js → redux/locationReducer.js} +0 -0
- /package/lib/esm/{locationReducer.js → redux/locationReducer.js} +0 -0
- /package/src/{locationReducer.js → redux/locationReducer.js} +0 -0
|
@@ -9,6 +9,6 @@ var _default = exports.default = {
|
|
|
9
9
|
NAVIGATE: '@@navigation-stack/NAVIGATE',
|
|
10
10
|
SHIFT: '@@navigation-stack/SHIFT',
|
|
11
11
|
UPDATE: '@@navigation-stack/UPDATE',
|
|
12
|
-
|
|
12
|
+
STOP: '@@navigation-stack/STOP'
|
|
13
13
|
};
|
|
14
14
|
module.exports = exports.default;
|
|
@@ -5,8 +5,9 @@ exports.default = void 0;
|
|
|
5
5
|
var _ActionTypes = _interopRequireDefault(require("./ActionTypes"));
|
|
6
6
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
7
|
var _default = exports.default = {
|
|
8
|
-
init:
|
|
9
|
-
type: _ActionTypes.default.INIT
|
|
8
|
+
init: initialLocation => ({
|
|
9
|
+
type: _ActionTypes.default.INIT,
|
|
10
|
+
payload: initialLocation
|
|
10
11
|
}),
|
|
11
12
|
push: location => ({
|
|
12
13
|
type: _ActionTypes.default.PUSH,
|
|
@@ -20,8 +21,8 @@ var _default = exports.default = {
|
|
|
20
21
|
type: _ActionTypes.default.SHIFT,
|
|
21
22
|
payload: delta
|
|
22
23
|
}),
|
|
23
|
-
|
|
24
|
-
type: _ActionTypes.default.
|
|
24
|
+
stop: () => ({
|
|
25
|
+
type: _ActionTypes.default.STOP
|
|
25
26
|
})
|
|
26
27
|
};
|
|
27
28
|
module.exports = exports.default;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = createMiddlewares;
|
|
5
|
+
var _createAddInputLocationBasePathMiddleware = _interopRequireDefault(require("./middleware/createAddInputLocationBasePathMiddleware"));
|
|
6
|
+
var _createNonProgrammaticNavigationBlockerMiddleware = _interopRequireDefault(require("./middleware/createNonProgrammaticNavigationBlockerMiddleware"));
|
|
7
|
+
var _createProgrammaticNavigationBlockerMiddleware = _interopRequireDefault(require("./middleware/createProgrammaticNavigationBlockerMiddleware"));
|
|
8
|
+
var _createRemoveOutputLocationBasePathMiddleware = _interopRequireDefault(require("./middleware/createRemoveOutputLocationBasePathMiddleware"));
|
|
9
|
+
var _createUpdateInternalLocationMiddleware = _interopRequireDefault(require("./middleware/createUpdateInternalLocationMiddleware"));
|
|
10
|
+
var _navigationOperationMiddleware = _interopRequireDefault(require("./middleware/navigationOperationMiddleware"));
|
|
11
|
+
var _parseInputLocationMiddleware = _interopRequireDefault(require("./middleware/parseInputLocationMiddleware"));
|
|
12
|
+
var _updateLocationMiddleware = _interopRequireDefault(require("./middleware/updateLocationMiddleware"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function createMiddlewares(session, options) {
|
|
15
|
+
// Allows temporarily ignoring location update events.
|
|
16
|
+
let shouldIgnoreNavigationLocationSubscriptionEvents = false;
|
|
17
|
+
const ignoreNavigationLocationSubscriptionEvents = func => {
|
|
18
|
+
shouldIgnoreNavigationLocationSubscriptionEvents = true;
|
|
19
|
+
func();
|
|
20
|
+
shouldIgnoreNavigationLocationSubscriptionEvents = false;
|
|
21
|
+
};
|
|
22
|
+
const middlewares = [
|
|
23
|
+
// Validates that the action "payload" (input location) is a proper `NormalizedInputLocation`.
|
|
24
|
+
_parseInputLocationMiddleware.default,
|
|
25
|
+
// Transforms a "PUSH" / "REPLACE" action into a "NAVIGATE" action.
|
|
26
|
+
_navigationOperationMiddleware.default,
|
|
27
|
+
// If a website is hosted under a certain path (`basePath`)
|
|
28
|
+
// then this middleware will automatically hide that starting segment from the `pathname` of `location`s.
|
|
29
|
+
(0, _createAddInputLocationBasePathMiddleware.default)(options && options.basePath),
|
|
30
|
+
// Allows blocking navigation.
|
|
31
|
+
// Handles `NAVIGATE` actions dispatched by the application itself.
|
|
32
|
+
(0, _createProgrammaticNavigationBlockerMiddleware.default)(session),
|
|
33
|
+
// This "middleware" performs the actual navigation according to the `session` being used.
|
|
34
|
+
// For example, when `WebBrowserSession` is used, it calls methods of the `history` object.
|
|
35
|
+
(0, _createUpdateInternalLocationMiddleware.default)(session, {
|
|
36
|
+
shouldIgnoreNavigationLocationSubscriptionEvents: () => shouldIgnoreNavigationLocationSubscriptionEvents
|
|
37
|
+
}),
|
|
38
|
+
// If a website is hosted under a certain path (`basePath`)
|
|
39
|
+
// then this middleware will automatically hide that starting segment from the `pathname` of `location`s.
|
|
40
|
+
(0, _createRemoveOutputLocationBasePathMiddleware.default)(options && options.basePath),
|
|
41
|
+
// Allows blocking navigation.
|
|
42
|
+
// Handles location `UPDATE` actions dispatched in response to location update events.
|
|
43
|
+
(0, _createNonProgrammaticNavigationBlockerMiddleware.default)(session, {
|
|
44
|
+
ignoreNavigationLocationSubscriptionEvents
|
|
45
|
+
})];
|
|
46
|
+
|
|
47
|
+
// Add `updateLocationMiddleware()`.
|
|
48
|
+
// It dispatches an `UPDATE` action with the new location
|
|
49
|
+
// so that the reducer could update it in global state.
|
|
50
|
+
//
|
|
51
|
+
// If `_internalLocationReducer` option is passed,
|
|
52
|
+
// it will not add this middleware. This is only used in tests.
|
|
53
|
+
//
|
|
54
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
55
|
+
if (!(options && options._internalLocationReducer)) {
|
|
56
|
+
middlewares.push(_updateLocationMiddleware.default);
|
|
57
|
+
}
|
|
58
|
+
return middlewares;
|
|
59
|
+
}
|
|
60
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.locationReducer = exports.createMiddlewares = exports.Actions = exports.ActionTypes = void 0;
|
|
5
|
+
var _Actions = _interopRequireDefault(require("./Actions"));
|
|
6
|
+
exports.Actions = _Actions.default;
|
|
7
|
+
var _ActionTypes = _interopRequireDefault(require("./ActionTypes"));
|
|
8
|
+
exports.ActionTypes = _ActionTypes.default;
|
|
9
|
+
var _createMiddlewares = _interopRequireDefault(require("./createMiddlewares"));
|
|
10
|
+
exports.createMiddlewares = _createMiddlewares.default;
|
|
11
|
+
var _locationReducer = _interopRequireDefault(require("./locationReducer"));
|
|
12
|
+
exports.locationReducer = _locationReducer.default;
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = internalLocationReducer;
|
|
5
|
+
var _ActionTypesInternal = _interopRequireDefault(require("./ActionTypesInternal"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
function internalLocationReducer(state, action) {
|
|
8
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
9
|
+
if (action.type === _ActionTypesInternal.default.INTERNAL_LOCATION_UPDATE) {
|
|
10
|
+
return action.payload;
|
|
11
|
+
}
|
|
12
|
+
return state;
|
|
13
|
+
}
|
|
14
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = createAddInputLocationBasePathMiddleware;
|
|
5
|
+
var _basePath = require("../../basePath");
|
|
6
|
+
var _ActionTypes = _interopRequireDefault(require("../ActionTypes"));
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
// Creates a "middleware" that, when a website is hosted under a certain path (`basePath`),
|
|
9
|
+
// automatically hides that starting segment from the `pathname` of `location`s.
|
|
10
|
+
function createAddInputLocationBasePathMiddleware(basePath) {
|
|
11
|
+
return function addInputLocationBasePathMiddleware() {
|
|
12
|
+
return next => action => {
|
|
13
|
+
const {
|
|
14
|
+
type,
|
|
15
|
+
payload
|
|
16
|
+
} = action;
|
|
17
|
+
switch (type) {
|
|
18
|
+
// Transforms `NAVIGATE` action payload (`location`).
|
|
19
|
+
case _ActionTypes.default.NAVIGATE:
|
|
20
|
+
return next({
|
|
21
|
+
type,
|
|
22
|
+
payload: Object.assign({}, payload, {
|
|
23
|
+
location: (0, _basePath.addBasePath)(payload.location, basePath)
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
default:
|
|
27
|
+
return next(action);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = createNonProgrammaticNavigationBlockerMiddleware;
|
|
5
|
+
var _getLocationFromInternalLocation = _interopRequireDefault(require("../../getLocationFromInternalLocation"));
|
|
6
|
+
var _isPromise = _interopRequireDefault(require("../../isPromise"));
|
|
7
|
+
var _navigationBlockers = require("../../navigationBlockers");
|
|
8
|
+
var _operations = _interopRequireDefault(require("../../session/navigation/operation/operations"));
|
|
9
|
+
var _ActionTypesInternal = _interopRequireDefault(require("../ActionTypesInternal"));
|
|
10
|
+
var _createProgrammaticNavigationBlockerMiddleware = require("./createProgrammaticNavigationBlockerMiddleware");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
// Creates a "middleware" that applies navigation blockers for non-programmatic navigation,
|
|
13
|
+
// i.e. the navigation that wasn't triggered by the application code and was triggered, say, by the user.
|
|
14
|
+
// It also handles programmatic `SHIFT` navigation because it doesn't know the new location until
|
|
15
|
+
// the environment performs the `delta` navigation and then tells the new location to `navigation-stack`.
|
|
16
|
+
function createNonProgrammaticNavigationBlockerMiddleware(session, {
|
|
17
|
+
ignoreNavigationLocationSubscriptionEvents
|
|
18
|
+
}) {
|
|
19
|
+
return function nonProgrammaticNavigationBlockerMiddleware() {
|
|
20
|
+
return next => action => {
|
|
21
|
+
const {
|
|
22
|
+
type,
|
|
23
|
+
payload
|
|
24
|
+
} = action;
|
|
25
|
+
|
|
26
|
+
// Declaring `result` variable here fixes ESLint error:
|
|
27
|
+
// "Unexpected lexical declaration in case block".
|
|
28
|
+
let result;
|
|
29
|
+
switch (type) {
|
|
30
|
+
// One could ask: Why run navigation blockers on `UPDATE` Redux action?
|
|
31
|
+
// Why not just run navigation blockers on `NAVIGATE` and `SHIFT` Redux action?
|
|
32
|
+
// The reason why it handles `UPDATE` Redux actions here is because
|
|
33
|
+
// `NAVIGATE` Redux actions are only emitted for programmatic "push" or "replace" navigation
|
|
34
|
+
// initiated by the application code, and there're other cases of navigation such as
|
|
35
|
+
// programmatic "shift" navigation or when the user manually clicks "Back" or "Forward" button
|
|
36
|
+
// in a web browser. And even if a "shift" navigation is initiated by the application code,
|
|
37
|
+
// it still doesn't know yet what the new location is gonna be cause it only knows the `delta`.
|
|
38
|
+
// Such "other" cases could only be handled by reacting to an `UPDATE` Redux action
|
|
39
|
+
// which is only emitted after the URL in the browser's address bar has changed.
|
|
40
|
+
//
|
|
41
|
+
// There's no real drawback in reacting to an `UPDATE` Redux action "post factum" because
|
|
42
|
+
// from the application's point of view the address bar doesn't matter and even doesn't exist.
|
|
43
|
+
// All that exists from the application's point of view is the `location` object in the Redux state.
|
|
44
|
+
// Until the `location` object in the Redux state is updated, the old page is still rendered.
|
|
45
|
+
// The appliation is only concerned with the updates of the `location` object in the Redux state
|
|
46
|
+
// and completely ignores any updates to the URL in the web browser's address bar.
|
|
47
|
+
//
|
|
48
|
+
// So here, the "middleware" attempts to prevent or allow navigation that has already happened
|
|
49
|
+
// in the web browser's address bar but hasn't yet happened in Redux state.
|
|
50
|
+
// For example, it could be a user clicking a "Back"/"Forward" button in their web browser.
|
|
51
|
+
// If such navigation should've been blocked, it will simply not update the `locaiton` object in Redux state,
|
|
52
|
+
// and it will also "rewind" the change of the URL in the web browser's address bar so that it's consistent
|
|
53
|
+
// with the `location` in Redux state.
|
|
54
|
+
//
|
|
55
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
56
|
+
case _ActionTypesInternal.default.INTERNAL_LOCATION_UPDATE:
|
|
57
|
+
// Programmatic `PUSH`/`REPLACE` actions are handled in another middleware.
|
|
58
|
+
if (payload.operation === _operations.default.PUSH || payload.operation === _operations.default.REPLACE) {
|
|
59
|
+
return next(action);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If no navigation blockers to run, don't do anything.
|
|
63
|
+
if ((0, _navigationBlockers.getNavigationBlockers)(session).length === 0) {
|
|
64
|
+
return next(action);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If it was the initial page load or a redirect,
|
|
68
|
+
// it's not really a navigation that could be rolled back.
|
|
69
|
+
if (payload.delta === 0) {
|
|
70
|
+
return next(action);
|
|
71
|
+
}
|
|
72
|
+
result = (0, _navigationBlockers.runNavigationBlockers)((0, _navigationBlockers.getNavigationBlockers)(session),
|
|
73
|
+
// Here `getLocationFromInternalLocation(payload)` is `Location`.
|
|
74
|
+
(0, _getLocationFromInternalLocation.default)(payload));
|
|
75
|
+
if ((0, _isPromise.default)(result)) {
|
|
76
|
+
const status = (0, _createProgrammaticNavigationBlockerMiddleware.createNavigationBlockersEvaluationStatus)(session);
|
|
77
|
+
|
|
78
|
+
// While location blockers are running, rewind to the previous location.
|
|
79
|
+
ignoreNavigationLocationSubscriptionEvents(() => {
|
|
80
|
+
session.shift(-payload.delta);
|
|
81
|
+
});
|
|
82
|
+
result.then(promiseResult => {
|
|
83
|
+
if (promiseResult) {
|
|
84
|
+
// Navigation blocked.
|
|
85
|
+
// Already rewound to a previous location.
|
|
86
|
+
} else if (!status.cancelled) {
|
|
87
|
+
// Navigation not blocked.
|
|
88
|
+
// Rewind back to the new location.
|
|
89
|
+
ignoreNavigationLocationSubscriptionEvents(() => {
|
|
90
|
+
session.shift(payload.delta);
|
|
91
|
+
});
|
|
92
|
+
// Update the location.
|
|
93
|
+
next(action);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
} else if (result) {
|
|
97
|
+
// Prevent the navigation: rewind to the previous location.
|
|
98
|
+
ignoreNavigationLocationSubscriptionEvents(() => {
|
|
99
|
+
session.shift(-payload.delta);
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
// Update the location.
|
|
103
|
+
return next(action);
|
|
104
|
+
}
|
|
105
|
+
// eslint-disable-next-line consistent-return
|
|
106
|
+
return;
|
|
107
|
+
default:
|
|
108
|
+
return next(action);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.createNavigationBlockersEvaluationStatus = createNavigationBlockersEvaluationStatus;
|
|
5
|
+
exports.default = createProgrammaticNavigationBlockerMiddleware;
|
|
6
|
+
var _isPromise = _interopRequireDefault(require("../../isPromise"));
|
|
7
|
+
var _navigationBlockers = require("../../navigationBlockers");
|
|
8
|
+
var _ActionTypes = _interopRequireDefault(require("../ActionTypes"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
function createNavigationBlockersEvaluationStatus(session) {
|
|
11
|
+
/* eslint-disable no-underscore-dangle */
|
|
12
|
+
if (session._navigationBlockersEvaluationStatus) {
|
|
13
|
+
session._navigationBlockersEvaluationStatus.cancelled = true;
|
|
14
|
+
}
|
|
15
|
+
session._navigationBlockersEvaluationStatus = {
|
|
16
|
+
cancelled: false
|
|
17
|
+
};
|
|
18
|
+
return session._navigationBlockersEvaluationStatus;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Creates a "middleware" that applies navigation blockers for programmatic navigation,
|
|
22
|
+
// i.e. the navigation that was triggered by the application code.
|
|
23
|
+
// This only includes `PUSH` and `REPLACE` navigation, and other programmatic types of navigation
|
|
24
|
+
// such as `SHIFT` aren't able to be handled here due to not yet having `location` info,
|
|
25
|
+
// so they're handled in a different middleware.
|
|
26
|
+
function createProgrammaticNavigationBlockerMiddleware(session) {
|
|
27
|
+
return function programmaticNavigationBlockerMiddleware() {
|
|
28
|
+
return next => action => {
|
|
29
|
+
const {
|
|
30
|
+
type,
|
|
31
|
+
payload
|
|
32
|
+
} = action;
|
|
33
|
+
|
|
34
|
+
// Declaring `result` variable here fixes ESLint error:
|
|
35
|
+
// "Unexpected lexical declaration in case block".
|
|
36
|
+
let result;
|
|
37
|
+
switch (type) {
|
|
38
|
+
// Prevent or allow navigation that was initiated by the application
|
|
39
|
+
// by dispatching a `.push()` or `.replace()` action.
|
|
40
|
+
//
|
|
41
|
+
// It doesn't handle `.shift()` navigation actions because it doesn't yet know
|
|
42
|
+
// the `location` that it's gonna `shift` to. Instead, it waits for the web browser
|
|
43
|
+
// to "shift" to that `location` and then reads it and rewinds the "shift"
|
|
44
|
+
// if it should've been blocked. That is handled by another "navigation blocker" middleware.
|
|
45
|
+
//
|
|
46
|
+
// This type of "shifting" and then rewinding the "shift" doesn't really matter to the application at all.
|
|
47
|
+
// From the application's point of view, all of that doesn't matter and even doesn't exist.
|
|
48
|
+
// All that exists from the application's point of view is the `location` object in the Redux state.
|
|
49
|
+
// Until the `location` object in the Redux state is updated, the old page is still rendered.
|
|
50
|
+
// The appliation is only concerned with the updates of the `location` object in the Redux state
|
|
51
|
+
// and completely ignores any updates to the URL in the web browser's address bar.
|
|
52
|
+
//
|
|
53
|
+
case _ActionTypes.default.NAVIGATE:
|
|
54
|
+
// `resultValue` variable name works around a stupid javascript error:
|
|
55
|
+
// "Cannot redeclare block-scoped variable 'result'".
|
|
56
|
+
result = (0, _navigationBlockers.runNavigationBlockers)((0, _navigationBlockers.getNavigationBlockers)(session),
|
|
57
|
+
// Here `payload.location` is `LocationBase`.
|
|
58
|
+
payload.location);
|
|
59
|
+
if ((0, _isPromise.default)(result)) {
|
|
60
|
+
const status = createNavigationBlockersEvaluationStatus(session);
|
|
61
|
+
// eslint-disable-next-line consistent-return
|
|
62
|
+
result.then(resultValue => {
|
|
63
|
+
if (!status.cancelled) {
|
|
64
|
+
if (!resultValue) {
|
|
65
|
+
return next(action);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} else if (!result) {
|
|
70
|
+
return next(action);
|
|
71
|
+
}
|
|
72
|
+
// eslint-disable-next-line consistent-return
|
|
73
|
+
return;
|
|
74
|
+
|
|
75
|
+
// Programmatic SHIFT actions aren't handled here.
|
|
76
|
+
// Instead, they're handled in non-programmatic navigation blocker middleware.
|
|
77
|
+
// The rationale is that there's no `location` argument on "SHIFT" actions,
|
|
78
|
+
// so the navigation blockers don't know yet what is the new location gonna be.
|
|
79
|
+
// They have to wait for the environment to restore the new location
|
|
80
|
+
// and then tell it to `navigation-stack` by calling a listener.
|
|
81
|
+
case _ActionTypes.default.SHIFT:
|
|
82
|
+
// New `location` isn't known yet. Proceed without blocking anything.
|
|
83
|
+
return next(action);
|
|
84
|
+
|
|
85
|
+
// Remove any navigation blockers on `STOP` event.
|
|
86
|
+
case _ActionTypes.default.STOP:
|
|
87
|
+
(0, _navigationBlockers.removeAllNavigationBlockers)(session);
|
|
88
|
+
return next(action);
|
|
89
|
+
default:
|
|
90
|
+
return next(action);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = createRemoveOutputLocationBasePathMiddleware;
|
|
5
|
+
var _basePath = require("../../basePath");
|
|
6
|
+
var _ActionTypesInternal = _interopRequireDefault(require("../ActionTypesInternal"));
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
// Creates a "middleware" that, when a website is hosted under a certain path (`basePath`),
|
|
9
|
+
// automatically hides that starting segment from the `pathname` of `location`s.
|
|
10
|
+
function createRemoveOutputLocationBasePathMiddleware(basePath) {
|
|
11
|
+
return function removeOutputLocationBasePathMiddleware() {
|
|
12
|
+
return next => action => {
|
|
13
|
+
const {
|
|
14
|
+
type,
|
|
15
|
+
payload
|
|
16
|
+
} = action;
|
|
17
|
+
switch (type) {
|
|
18
|
+
// Transforms `UPDATE` action payload (input `location`).
|
|
19
|
+
case _ActionTypesInternal.default.INTERNAL_LOCATION_UPDATE:
|
|
20
|
+
return next({
|
|
21
|
+
type,
|
|
22
|
+
payload: (0, _basePath.removeBasePath)(payload, basePath)
|
|
23
|
+
});
|
|
24
|
+
default:
|
|
25
|
+
return next(action);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = createUpdateInternalLocationMiddleware;
|
|
5
|
+
var _ActionTypes = _interopRequireDefault(require("../ActionTypes"));
|
|
6
|
+
var _ActionTypesInternal = _interopRequireDefault(require("../ActionTypesInternal"));
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
// Creates a "middleware" that performs the actual navigation according to the `session` being used.
|
|
9
|
+
// For example, when `WebBrowserSession` is used, it calls methods of the `window.history` object.
|
|
10
|
+
function createUpdateInternalLocationMiddleware(session, {
|
|
11
|
+
shouldIgnoreNavigationLocationSubscriptionEvents
|
|
12
|
+
}) {
|
|
13
|
+
return function updateInternalLocationMiddleware() {
|
|
14
|
+
return next => {
|
|
15
|
+
// Whenever browser location changes,
|
|
16
|
+
// perform the same changes with the internal `location` object.
|
|
17
|
+
const unsubscribe = session.subscribe(location => {
|
|
18
|
+
if (!shouldIgnoreNavigationLocationSubscriptionEvents()) {
|
|
19
|
+
next({
|
|
20
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
21
|
+
type: _ActionTypesInternal.default.INTERNAL_LOCATION_UPDATE,
|
|
22
|
+
payload: location
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return action => {
|
|
27
|
+
const {
|
|
28
|
+
type,
|
|
29
|
+
payload
|
|
30
|
+
} = action;
|
|
31
|
+
switch (type) {
|
|
32
|
+
case _ActionTypes.default.INIT:
|
|
33
|
+
// `init()` will trigger the `subscribe()` listener,
|
|
34
|
+
// which will call `updateLocation()`.
|
|
35
|
+
session.start(payload);
|
|
36
|
+
// eslint-disable-next-line consistent-return
|
|
37
|
+
return;
|
|
38
|
+
case _ActionTypes.default.NAVIGATE:
|
|
39
|
+
// `navigate()` will trigger the `subscribe()` listener,
|
|
40
|
+
// which will call `updateLocation()`.
|
|
41
|
+
session.navigate(payload.operation, payload.location);
|
|
42
|
+
// eslint-disable-next-line consistent-return
|
|
43
|
+
return;
|
|
44
|
+
case _ActionTypes.default.SHIFT:
|
|
45
|
+
// `shift()` will trigger the `subscribe()` listener,
|
|
46
|
+
// which will call `updateLocation()`.
|
|
47
|
+
session.shift(payload);
|
|
48
|
+
// eslint-disable-next-line consistent-return
|
|
49
|
+
return;
|
|
50
|
+
case _ActionTypes.default.STOP:
|
|
51
|
+
// Remove location change subscription.
|
|
52
|
+
unsubscribe();
|
|
53
|
+
// Even if it calls `unsubscribe()` function above, any other subscriptions
|
|
54
|
+
// would still stay. We're not talking about `navigationStack.subscribe()`
|
|
55
|
+
// subscriptions because those don't really matter in terms of cleaning them up:
|
|
56
|
+
// those're just Redux store subscriptions that don't have any side effects.
|
|
57
|
+
// Subscriptions we're talking here are `Session`'s own subscription
|
|
58
|
+
// via `session.subscribe()` and any hypothetical manual `session.subscribe()`
|
|
59
|
+
// calls that could be made by the application code for whatever purpose.
|
|
60
|
+
// Both of those should be cleared.
|
|
61
|
+
// To work around that, `.stop()` function removes all subscriptions.
|
|
62
|
+
session.stop();
|
|
63
|
+
// eslint-disable-next-line consistent-return
|
|
64
|
+
return next(action);
|
|
65
|
+
default:
|
|
66
|
+
// eslint-disable-next-line consistent-return
|
|
67
|
+
return next(action);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
module.exports = exports.default;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.default =
|
|
4
|
+
exports.default = navigationOperationMiddleware;
|
|
5
|
+
var _operations = _interopRequireDefault(require("../../session/navigation/operation/operations"));
|
|
5
6
|
var _ActionTypes = _interopRequireDefault(require("../ActionTypes"));
|
|
6
7
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
8
|
// This "middleware" transforms a `PUSH` / `REPLACE` action into a `NAVIGATE` action.
|
|
8
|
-
function
|
|
9
|
+
function navigationOperationMiddleware() {
|
|
9
10
|
return next => action => {
|
|
10
11
|
const {
|
|
11
12
|
type,
|
|
@@ -16,18 +17,20 @@ function navigationActionMiddleware() {
|
|
|
16
17
|
case _ActionTypes.default.PUSH:
|
|
17
18
|
return next({
|
|
18
19
|
type: _ActionTypes.default.NAVIGATE,
|
|
19
|
-
payload:
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
payload: {
|
|
21
|
+
operation: _operations.default.PUSH,
|
|
22
|
+
location: payload
|
|
23
|
+
}
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
// Converts a `REPLACE` action into a `NAVIGATE` action.
|
|
25
27
|
case _ActionTypes.default.REPLACE:
|
|
26
28
|
return next({
|
|
27
29
|
type: _ActionTypes.default.NAVIGATE,
|
|
28
|
-
payload:
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
payload: {
|
|
31
|
+
operation: _operations.default.REPLACE,
|
|
32
|
+
location: payload
|
|
33
|
+
}
|
|
31
34
|
});
|
|
32
35
|
default:
|
|
33
36
|
return next(action);
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.default =
|
|
4
|
+
exports.default = parseInputLocationMiddleware;
|
|
5
|
+
var _parseInputLocation = _interopRequireDefault(require("../../parseInputLocation"));
|
|
5
6
|
var _ActionTypes = _interopRequireDefault(require("../ActionTypes"));
|
|
6
|
-
var _normalizeInputLocation = _interopRequireDefault(require("../normalizeInputLocation"));
|
|
7
7
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
// This "middleware" transforms input location argument into a proper `NormalizedInputLocation`.
|
|
9
|
-
function
|
|
9
|
+
function parseInputLocationMiddleware() {
|
|
10
10
|
return next => action => {
|
|
11
11
|
const {
|
|
12
12
|
type,
|
|
13
13
|
payload
|
|
14
14
|
} = action;
|
|
15
15
|
switch (type) {
|
|
16
|
+
case _ActionTypes.default.INIT:
|
|
16
17
|
case _ActionTypes.default.PUSH:
|
|
17
18
|
case _ActionTypes.default.REPLACE:
|
|
18
19
|
return next({
|
|
19
20
|
type,
|
|
20
|
-
payload
|
|
21
|
+
// `payload` is optional in `INIT` action.
|
|
22
|
+
payload: payload && (0, _parseInputLocation.default)(payload)
|
|
21
23
|
});
|
|
22
24
|
default:
|
|
23
25
|
return next(action);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = updateLocationMiddleware;
|
|
5
|
+
var _getLocationFromInternalLocation = _interopRequireDefault(require("../../getLocationFromInternalLocation"));
|
|
6
|
+
var _ActionTypes = _interopRequireDefault(require("../ActionTypes"));
|
|
7
|
+
var _ActionTypesInternal = _interopRequireDefault(require("../ActionTypesInternal"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function updateLocationMiddleware() {
|
|
10
|
+
return next => action => {
|
|
11
|
+
const {
|
|
12
|
+
type,
|
|
13
|
+
payload
|
|
14
|
+
} = action;
|
|
15
|
+
switch (type) {
|
|
16
|
+
// Convert `LocationInternal` object to a publicly-visible `Location` object.
|
|
17
|
+
// It hides non-essential properties of location such as `operation`, `index`, `delta`.
|
|
18
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
19
|
+
case _ActionTypesInternal.default.INTERNAL_LOCATION_UPDATE:
|
|
20
|
+
// Dispatch a "public" `UPDATE` Redux action.
|
|
21
|
+
// This is what users of this package should use
|
|
22
|
+
// rather than `INTERNAL_LOCATION_UPDATE` which is for internal purposes.
|
|
23
|
+
next({
|
|
24
|
+
type: _ActionTypes.default.UPDATE,
|
|
25
|
+
payload: (0, _getLocationFromInternalLocation.default)(payload)
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
default:
|
|
29
|
+
// eslint-disable-next-line consistent-return
|
|
30
|
+
return next(action);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
module.exports = exports.default;
|