@tramvai/module-router 2.145.1 → 2.146.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.
@@ -1,26 +1,30 @@
1
1
  import uniq from '@tinkoff/utils/array/uniq';
2
2
  import { isRedirectFoundError, isNotFoundError } from '@tinkoff/errors';
3
+ import { ACTION_PARAMETERS } from '@tramvai/core';
3
4
 
4
5
  const stopRunAtError = (error) => {
5
6
  if (isNotFoundError(error) || isRedirectFoundError(error)) {
6
7
  return true;
7
8
  }
8
9
  };
9
- const runActionsFactory = ({ store, router, actionRegistry, actionPageRunner, }) => {
10
+ const getActions = ({ store, router, actionRegistry, actionPageRunner, }) => {
11
+ const route = router.getCurrentRoute();
12
+ const { config: { bundle, pageComponent } = {} } = route;
13
+ if (!bundle || !pageComponent) {
14
+ throw new Error(`bundle and pageComponent should be defined, but got ${route}`);
15
+ }
16
+ return uniq([
17
+ ...(actionRegistry.getGlobal() || []),
18
+ ...(actionRegistry.get(bundle) || []),
19
+ ...(actionRegistry.get(pageComponent) || []),
20
+ ]);
21
+ };
22
+ const runActionsFactory = (deps) => {
10
23
  return function runActions() {
11
- const route = router.getCurrentRoute();
12
- const { config: { bundle, pageComponent } = {} } = route;
13
- if (!bundle || !pageComponent) {
14
- throw new Error(`bundle and pageComponent should be defined, but got ${route}`);
15
- }
16
- const actions = uniq([
17
- ...(actionRegistry.getGlobal() || []),
18
- ...(actionRegistry.get(bundle) || []),
19
- ...(actionRegistry.get(pageComponent) || []),
20
- ]);
21
- return actionPageRunner.runActions(actions, stopRunAtError).catch((err) => {
24
+ const actions = getActions(deps);
25
+ return deps.actionPageRunner.runActions(actions, stopRunAtError).catch((err) => {
22
26
  if (isRedirectFoundError(err)) {
23
- return router.navigate({
27
+ return deps.router.navigate({
24
28
  url: err.nextUrl,
25
29
  replace: true,
26
30
  code: err.httpStatus,
@@ -30,5 +34,17 @@ const runActionsFactory = ({ store, router, actionRegistry, actionPageRunner, })
30
34
  });
31
35
  };
32
36
  };
37
+ const resetDeferredActions = (deps) => {
38
+ const actions = getActions(deps);
39
+ actions.forEach((action) => {
40
+ const parameters = action[ACTION_PARAMETERS];
41
+ const isDeferredAction = parameters === null || parameters === void 0 ? void 0 : parameters.deferred;
42
+ const deferred = deps.deferredActionsMap.get(parameters === null || parameters === void 0 ? void 0 : parameters.name);
43
+ // here only deferred actions with always or dynamic conditions will be refreshed
44
+ if (isDeferredAction && deferred && deps.actionExecution.canExecute(action)) {
45
+ deferred.reset();
46
+ }
47
+ });
48
+ };
33
49
 
34
- export { runActionsFactory };
50
+ export { getActions, resetDeferredActions, runActionsFactory };
@@ -1,8 +1,22 @@
1
- import type { ACTION_REGISTRY_TOKEN, ACTION_PAGE_RUNNER_TOKEN, STORE_TOKEN } from '@tramvai/tokens-common';
1
+ import type { ACTION_REGISTRY_TOKEN, ACTION_PAGE_RUNNER_TOKEN, STORE_TOKEN, DEFERRED_ACTIONS_MAP_TOKEN, ACTION_EXECUTION_TOKEN } from '@tramvai/tokens-common';
2
2
  import type { ROUTER_TOKEN } from '@tramvai/tokens-router';
3
- export declare const runActionsFactory: ({ store, router, actionRegistry, actionPageRunner, }: {
3
+ export declare const getActions: ({ store, router, actionRegistry, actionPageRunner, }: {
4
+ store: typeof STORE_TOKEN;
5
+ router: typeof ROUTER_TOKEN;
6
+ actionRegistry: typeof ACTION_REGISTRY_TOKEN;
7
+ actionPageRunner: typeof ACTION_PAGE_RUNNER_TOKEN;
8
+ }) => import("@tramvai/core").PageAction[];
9
+ export declare const runActionsFactory: (deps: {
4
10
  store: typeof STORE_TOKEN;
5
11
  router: typeof ROUTER_TOKEN;
6
12
  actionRegistry: typeof ACTION_REGISTRY_TOKEN;
7
13
  actionPageRunner: typeof ACTION_PAGE_RUNNER_TOKEN;
8
14
  }) => () => Promise<any>;
15
+ export declare const resetDeferredActions: (deps: {
16
+ store: typeof STORE_TOKEN;
17
+ router: typeof ROUTER_TOKEN;
18
+ actionRegistry: typeof ACTION_REGISTRY_TOKEN;
19
+ actionPageRunner: typeof ACTION_PAGE_RUNNER_TOKEN;
20
+ deferredActionsMap: typeof DEFERRED_ACTIONS_MAP_TOKEN;
21
+ actionExecution: typeof ACTION_EXECUTION_TOKEN;
22
+ }) => void;
@@ -1,26 +1,30 @@
1
1
  import uniq from '@tinkoff/utils/array/uniq';
2
2
  import { isRedirectFoundError, isNotFoundError } from '@tinkoff/errors';
3
+ import '@tramvai/core';
3
4
 
4
5
  const stopRunAtError = (error) => {
5
6
  if (isNotFoundError(error) || isRedirectFoundError(error)) {
6
7
  return true;
7
8
  }
8
9
  };
9
- const runActionsFactory = ({ store, router, actionRegistry, actionPageRunner, }) => {
10
+ const getActions = ({ store, router, actionRegistry, actionPageRunner, }) => {
11
+ const route = router.getCurrentRoute();
12
+ const { config: { bundle, pageComponent } = {} } = route;
13
+ if (!bundle || !pageComponent) {
14
+ throw new Error(`bundle and pageComponent should be defined, but got ${route}`);
15
+ }
16
+ return uniq([
17
+ ...(actionRegistry.getGlobal() || []),
18
+ ...(actionRegistry.get(bundle) || []),
19
+ ...(actionRegistry.get(pageComponent) || []),
20
+ ]);
21
+ };
22
+ const runActionsFactory = (deps) => {
10
23
  return function runActions() {
11
- const route = router.getCurrentRoute();
12
- const { config: { bundle, pageComponent } = {} } = route;
13
- if (!bundle || !pageComponent) {
14
- throw new Error(`bundle and pageComponent should be defined, but got ${route}`);
15
- }
16
- const actions = uniq([
17
- ...(actionRegistry.getGlobal() || []),
18
- ...(actionRegistry.get(bundle) || []),
19
- ...(actionRegistry.get(pageComponent) || []),
20
- ]);
21
- return actionPageRunner.runActions(actions, stopRunAtError).catch((err) => {
24
+ const actions = getActions(deps);
25
+ return deps.actionPageRunner.runActions(actions, stopRunAtError).catch((err) => {
22
26
  if (isRedirectFoundError(err)) {
23
- return router.navigate({
27
+ return deps.router.navigate({
24
28
  url: err.nextUrl,
25
29
  replace: true,
26
30
  code: err.httpStatus,
@@ -31,4 +35,4 @@ const runActionsFactory = ({ store, router, actionRegistry, actionPageRunner, })
31
35
  };
32
36
  };
33
37
 
34
- export { runActionsFactory };
38
+ export { getActions, runActionsFactory };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var uniq = require('@tinkoff/utils/array/uniq');
6
6
  var errors = require('@tinkoff/errors');
7
+ require('@tramvai/core');
7
8
 
8
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
10
 
@@ -14,21 +15,24 @@ const stopRunAtError = (error) => {
14
15
  return true;
15
16
  }
16
17
  };
17
- const runActionsFactory = ({ store, router, actionRegistry, actionPageRunner, }) => {
18
+ const getActions = ({ store, router, actionRegistry, actionPageRunner, }) => {
19
+ const route = router.getCurrentRoute();
20
+ const { config: { bundle, pageComponent } = {} } = route;
21
+ if (!bundle || !pageComponent) {
22
+ throw new Error(`bundle and pageComponent should be defined, but got ${route}`);
23
+ }
24
+ return uniq__default["default"]([
25
+ ...(actionRegistry.getGlobal() || []),
26
+ ...(actionRegistry.get(bundle) || []),
27
+ ...(actionRegistry.get(pageComponent) || []),
28
+ ]);
29
+ };
30
+ const runActionsFactory = (deps) => {
18
31
  return function runActions() {
19
- const route = router.getCurrentRoute();
20
- const { config: { bundle, pageComponent } = {} } = route;
21
- if (!bundle || !pageComponent) {
22
- throw new Error(`bundle and pageComponent should be defined, but got ${route}`);
23
- }
24
- const actions = uniq__default["default"]([
25
- ...(actionRegistry.getGlobal() || []),
26
- ...(actionRegistry.get(bundle) || []),
27
- ...(actionRegistry.get(pageComponent) || []),
28
- ]);
29
- return actionPageRunner.runActions(actions, stopRunAtError).catch((err) => {
32
+ const actions = getActions(deps);
33
+ return deps.actionPageRunner.runActions(actions, stopRunAtError).catch((err) => {
30
34
  if (errors.isRedirectFoundError(err)) {
31
- return router.navigate({
35
+ return deps.router.navigate({
32
36
  url: err.nextUrl,
33
37
  replace: true,
34
38
  code: err.httpStatus,
@@ -39,4 +43,5 @@ const runActionsFactory = ({ store, router, actionRegistry, actionPageRunner, })
39
43
  };
40
44
  };
41
45
 
46
+ exports.getActions = getActions;
42
47
  exports.runActionsFactory = runActionsFactory;
@@ -1,10 +1,10 @@
1
1
  import noop from '@tinkoff/utils/function/noop';
2
2
  import { DI_TOKEN, COMMAND_LINE_RUNNER_TOKEN, commandLineListTokens } from '@tramvai/core';
3
3
  import { ROUTER_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN } from '@tramvai/tokens-router';
4
- import { STORE_TOKEN, ACTION_REGISTRY_TOKEN, ACTION_PAGE_RUNNER_TOKEN } from '@tramvai/tokens-common';
4
+ import { STORE_TOKEN, ACTION_REGISTRY_TOKEN, ACTION_PAGE_RUNNER_TOKEN, DEFERRED_ACTIONS_MAP_TOKEN, ACTION_EXECUTION_TOKEN } from '@tramvai/tokens-common';
5
5
  import { beforeNavigateHooksToken, afterNavigateHooksToken } from '../../tokens.browser.js';
6
6
  import { runCommandsSpa, runCommandsAfterSpa } from './runCommands.browser.js';
7
- import { runActionsFactory } from '../runActions.browser.js';
7
+ import { resetDeferredActions, runActionsFactory } from '../runActions.browser.js';
8
8
 
9
9
  const spaHooks = [
10
10
  {
@@ -29,10 +29,14 @@ const spaHooks = [
29
29
  provide: commandLineListTokens.spaTransition,
30
30
  multi: true,
31
31
  useFactory: ({ spaMode, ...deps }) => {
32
- if (spaMode !== 'after') {
33
- return runActionsFactory(deps);
34
- }
35
- return noop;
32
+ return () => {
33
+ // we need to reset dynamic deferred actions promises befor page render with updated route,
34
+ // defered promise will be fresh and fallback will be shown
35
+ resetDeferredActions(deps);
36
+ if (spaMode !== 'after') {
37
+ return runActionsFactory(deps)();
38
+ }
39
+ };
36
40
  },
37
41
  deps: {
38
42
  store: STORE_TOKEN,
@@ -43,6 +47,8 @@ const spaHooks = [
43
47
  token: ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN,
44
48
  optional: true,
45
49
  },
50
+ deferredActionsMap: DEFERRED_ACTIONS_MAP_TOKEN,
51
+ actionExecution: ACTION_EXECUTION_TOKEN,
46
52
  },
47
53
  },
48
54
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-router",
3
- "version": "2.145.1",
3
+ "version": "2.146.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "browser": {
@@ -28,25 +28,25 @@
28
28
  "@tinkoff/errors": "0.3.8",
29
29
  "@tinkoff/router": "0.2.17",
30
30
  "@tinkoff/url": "0.8.6",
31
- "@tramvai/react": "2.145.1",
31
+ "@tramvai/react": "2.146.0",
32
32
  "@tramvai/safe-strings": "0.5.12",
33
- "@tramvai/tokens-child-app": "2.145.1",
34
- "@tramvai/tokens-render": "2.145.1",
35
- "@tramvai/tokens-router": "2.145.1",
36
- "@tramvai/tokens-server": "2.145.1",
37
- "@tramvai/experiments": "2.145.1"
33
+ "@tramvai/tokens-child-app": "2.146.0",
34
+ "@tramvai/tokens-render": "2.146.0",
35
+ "@tramvai/tokens-router": "2.146.0",
36
+ "@tramvai/tokens-server": "2.146.0",
37
+ "@tramvai/experiments": "2.146.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@tinkoff/utils": "^2.1.2",
41
- "@tramvai/cli": "2.145.1",
42
- "@tramvai/core": "2.145.1",
43
- "@tramvai/module-log": "2.145.1",
44
- "@tramvai/module-server": "2.145.1",
45
- "@tramvai/papi": "2.145.1",
46
- "@tramvai/state": "2.145.1",
47
- "@tramvai/test-helpers": "2.145.1",
48
- "@tramvai/test-mocks": "2.145.1",
49
- "@tramvai/tokens-common": "2.145.1",
41
+ "@tramvai/cli": "2.146.0",
42
+ "@tramvai/core": "2.146.0",
43
+ "@tramvai/module-log": "2.146.0",
44
+ "@tramvai/module-server": "2.146.0",
45
+ "@tramvai/papi": "2.146.0",
46
+ "@tramvai/state": "2.146.0",
47
+ "@tramvai/test-helpers": "2.146.0",
48
+ "@tramvai/test-mocks": "2.146.0",
49
+ "@tramvai/tokens-common": "2.146.0",
50
50
  "@tinkoff/dippy": "0.8.15",
51
51
  "react": "*",
52
52
  "tslib": "^2.4.0"