@tramvai/module-router 2.109.1 → 2.111.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/lib/modules/common.browser.js +2 -11
- package/lib/modules/common.d.ts +4 -0
- package/lib/modules/common.es.js +2 -11
- package/lib/modules/common.js +0 -9
- package/lib/modules/guards/common/index.browser.js +8 -10
- package/lib/modules/guards/common/index.es.js +8 -10
- package/lib/modules/guards/common/index.js +6 -8
- package/lib/modules/guards/common/loadBundle.browser.js +3 -38
- package/lib/modules/guards/common/loadBundle.d.ts +4 -7
- package/lib/modules/guards/common/loadBundle.es.js +3 -38
- package/lib/modules/guards/common/loadBundle.js +3 -42
- package/lib/modules/tokens/browser/index.d.ts +20 -14
- package/lib/modules/tokens/browser/prefetch.browser.js +13 -33
- package/lib/modules/tokens/browser/prefetch.d.ts +11 -7
- package/lib/modules/tokens/common/index.browser.js +33 -9
- package/lib/modules/tokens/common/index.es.js +33 -9
- package/lib/modules/tokens/common/index.js +32 -8
- package/lib/modules/tokens/common/pageRegistry.browser.js +57 -0
- package/lib/modules/tokens/common/pageRegistry.d.ts +23 -0
- package/lib/modules/tokens/common/pageRegistry.es.js +57 -0
- package/lib/modules/tokens/common/pageRegistry.js +67 -0
- package/lib/{services/page.browser.js → modules/tokens/common/pageService.browser.js} +16 -16
- package/lib/{services/page.d.ts → modules/tokens/common/pageService.d.ts} +7 -7
- package/lib/{services/page.es.js → modules/tokens/common/pageService.es.js} +16 -16
- package/lib/{services/page.js → modules/tokens/common/pageService.js} +16 -16
- package/package.json +17 -17
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
2
2
|
import { provide, commandLineListTokens } from '@tramvai/core';
|
|
3
3
|
import { setLogger } from '@tinkoff/router';
|
|
4
|
-
import { LOGGER_TOKEN,
|
|
5
|
-
import { ROUTER_TOKEN, ROUTES_TOKEN, ROUTE_RESOLVE_TOKEN, ROUTER_GUARD_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN
|
|
4
|
+
import { LOGGER_TOKEN, COMBINE_REDUCERS } from '@tramvai/tokens-common';
|
|
5
|
+
import { ROUTER_TOKEN, ROUTES_TOKEN, ROUTE_RESOLVE_TOKEN, ROUTER_GUARD_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN } from '@tramvai/tokens-router';
|
|
6
6
|
import { routerClassToken, additionalRouterParameters, routeTransformToken, onChangeHooksToken, beforeResolveHooksToken, beforeNavigateHooksToken, afterNavigateHooksToken, beforeUpdateCurrentHooksToken, afterUpdateCurrentHooksToken } from './tokens.browser.js';
|
|
7
7
|
import { RouterStore } from '../stores/RouterStore.browser.js';
|
|
8
8
|
import { commonGuards } from './guards/common/index.browser.js';
|
|
9
9
|
import { commonHooks } from './hooks/common/index.browser.js';
|
|
10
10
|
import { commonTokens } from './tokens/common/index.browser.js';
|
|
11
|
-
import { PageService } from '../services/page.browser.js';
|
|
12
11
|
import { providers as providers$1 } from './fileSystemPages.browser.js';
|
|
13
12
|
|
|
14
13
|
const providers = [
|
|
@@ -123,14 +122,6 @@ const providers = [
|
|
|
123
122
|
// рассмотреть возможность замены после доработок экшенов
|
|
124
123
|
useValue: 'after',
|
|
125
124
|
}),
|
|
126
|
-
provide({
|
|
127
|
-
provide: PAGE_SERVICE_TOKEN,
|
|
128
|
-
useClass: PageService,
|
|
129
|
-
deps: {
|
|
130
|
-
router: ROUTER_TOKEN,
|
|
131
|
-
componentRegistry: COMPONENT_REGISTRY_TOKEN,
|
|
132
|
-
},
|
|
133
|
-
}),
|
|
134
125
|
provide({
|
|
135
126
|
provide: COMBINE_REDUCERS,
|
|
136
127
|
multi: true,
|
package/lib/modules/common.d.ts
CHANGED
package/lib/modules/common.es.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
2
2
|
import { provide, commandLineListTokens } from '@tramvai/core';
|
|
3
3
|
import { setLogger } from '@tinkoff/router';
|
|
4
|
-
import { LOGGER_TOKEN,
|
|
5
|
-
import { ROUTER_TOKEN, ROUTES_TOKEN, ROUTE_RESOLVE_TOKEN, ROUTER_GUARD_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN
|
|
4
|
+
import { LOGGER_TOKEN, COMBINE_REDUCERS } from '@tramvai/tokens-common';
|
|
5
|
+
import { ROUTER_TOKEN, ROUTES_TOKEN, ROUTE_RESOLVE_TOKEN, ROUTER_GUARD_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN } from '@tramvai/tokens-router';
|
|
6
6
|
import { routerClassToken, additionalRouterParameters, routeTransformToken, onChangeHooksToken, beforeResolveHooksToken, beforeNavigateHooksToken, afterNavigateHooksToken, beforeUpdateCurrentHooksToken, afterUpdateCurrentHooksToken } from './tokens.es.js';
|
|
7
7
|
import { RouterStore } from '../stores/RouterStore.es.js';
|
|
8
8
|
import { commonGuards } from './guards/common/index.es.js';
|
|
9
9
|
import { commonHooks } from './hooks/common/index.es.js';
|
|
10
10
|
import { commonTokens } from './tokens/common/index.es.js';
|
|
11
|
-
import { PageService } from '../services/page.es.js';
|
|
12
11
|
import { providers as providers$1 } from './fileSystemPages.es.js';
|
|
13
12
|
|
|
14
13
|
const providers = [
|
|
@@ -123,14 +122,6 @@ const providers = [
|
|
|
123
122
|
// рассмотреть возможность замены после доработок экшенов
|
|
124
123
|
useValue: 'after',
|
|
125
124
|
}),
|
|
126
|
-
provide({
|
|
127
|
-
provide: PAGE_SERVICE_TOKEN,
|
|
128
|
-
useClass: PageService,
|
|
129
|
-
deps: {
|
|
130
|
-
router: ROUTER_TOKEN,
|
|
131
|
-
componentRegistry: COMPONENT_REGISTRY_TOKEN,
|
|
132
|
-
},
|
|
133
|
-
}),
|
|
134
125
|
provide({
|
|
135
126
|
provide: COMBINE_REDUCERS,
|
|
136
127
|
multi: true,
|
package/lib/modules/common.js
CHANGED
|
@@ -12,7 +12,6 @@ var RouterStore = require('../stores/RouterStore.js');
|
|
|
12
12
|
var index = require('./guards/common/index.js');
|
|
13
13
|
var index$1 = require('./hooks/common/index.js');
|
|
14
14
|
var index$2 = require('./tokens/common/index.js');
|
|
15
|
-
var page = require('../services/page.js');
|
|
16
15
|
var fileSystemPages = require('./fileSystemPages.js');
|
|
17
16
|
|
|
18
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -131,14 +130,6 @@ const providers = [
|
|
|
131
130
|
// рассмотреть возможность замены после доработок экшенов
|
|
132
131
|
useValue: 'after',
|
|
133
132
|
}),
|
|
134
|
-
core.provide({
|
|
135
|
-
provide: tokensRouter.PAGE_SERVICE_TOKEN,
|
|
136
|
-
useClass: page.PageService,
|
|
137
|
-
deps: {
|
|
138
|
-
router: tokensRouter.ROUTER_TOKEN,
|
|
139
|
-
componentRegistry: tokensCommon.COMPONENT_REGISTRY_TOKEN,
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
133
|
core.provide({
|
|
143
134
|
provide: tokensCommon.COMBINE_REDUCERS,
|
|
144
135
|
multi: true,
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { provide } from '@tramvai/core';
|
|
2
|
+
import { LOGGER_TOKEN, BUNDLE_MANAGER_TOKEN, RESPONSE_MANAGER_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
import { ROUTER_GUARD_TOKEN, PAGE_REGISTRY_TOKEN } from '@tramvai/tokens-router';
|
|
3
4
|
import { loadBundle } from './loadBundle.browser.js';
|
|
4
5
|
import { internalError } from './internalError.browser.js';
|
|
5
6
|
|
|
6
7
|
const commonGuards = [
|
|
7
|
-
{
|
|
8
|
+
provide({
|
|
8
9
|
provide: ROUTER_GUARD_TOKEN,
|
|
9
10
|
multi: true,
|
|
10
11
|
useFactory: loadBundle,
|
|
11
12
|
deps: {
|
|
12
13
|
logger: LOGGER_TOKEN,
|
|
13
14
|
bundleManager: BUNDLE_MANAGER_TOKEN,
|
|
14
|
-
actionRegistry: ACTION_REGISTRY_TOKEN,
|
|
15
15
|
responseManager: RESPONSE_MANAGER_TOKEN,
|
|
16
|
-
|
|
17
|
-
dispatcherContext: DISPATCHER_CONTEXT_TOKEN,
|
|
18
|
-
pageService: PAGE_SERVICE_TOKEN,
|
|
16
|
+
pageRegistry: PAGE_REGISTRY_TOKEN,
|
|
19
17
|
},
|
|
20
|
-
},
|
|
21
|
-
{
|
|
18
|
+
}),
|
|
19
|
+
provide({
|
|
22
20
|
provide: ROUTER_GUARD_TOKEN,
|
|
23
21
|
multi: true,
|
|
24
22
|
useFactory: internalError,
|
|
@@ -26,7 +24,7 @@ const commonGuards = [
|
|
|
26
24
|
logger: LOGGER_TOKEN,
|
|
27
25
|
responseManager: RESPONSE_MANAGER_TOKEN,
|
|
28
26
|
},
|
|
29
|
-
},
|
|
27
|
+
}),
|
|
30
28
|
];
|
|
31
29
|
|
|
32
30
|
export { commonGuards };
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { provide } from '@tramvai/core';
|
|
2
|
+
import { LOGGER_TOKEN, BUNDLE_MANAGER_TOKEN, RESPONSE_MANAGER_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
import { ROUTER_GUARD_TOKEN, PAGE_REGISTRY_TOKEN } from '@tramvai/tokens-router';
|
|
3
4
|
import { loadBundle } from './loadBundle.es.js';
|
|
4
5
|
import { internalError } from './internalError.es.js';
|
|
5
6
|
|
|
6
7
|
const commonGuards = [
|
|
7
|
-
{
|
|
8
|
+
provide({
|
|
8
9
|
provide: ROUTER_GUARD_TOKEN,
|
|
9
10
|
multi: true,
|
|
10
11
|
useFactory: loadBundle,
|
|
11
12
|
deps: {
|
|
12
13
|
logger: LOGGER_TOKEN,
|
|
13
14
|
bundleManager: BUNDLE_MANAGER_TOKEN,
|
|
14
|
-
actionRegistry: ACTION_REGISTRY_TOKEN,
|
|
15
15
|
responseManager: RESPONSE_MANAGER_TOKEN,
|
|
16
|
-
|
|
17
|
-
dispatcherContext: DISPATCHER_CONTEXT_TOKEN,
|
|
18
|
-
pageService: PAGE_SERVICE_TOKEN,
|
|
16
|
+
pageRegistry: PAGE_REGISTRY_TOKEN,
|
|
19
17
|
},
|
|
20
|
-
},
|
|
21
|
-
{
|
|
18
|
+
}),
|
|
19
|
+
provide({
|
|
22
20
|
provide: ROUTER_GUARD_TOKEN,
|
|
23
21
|
multi: true,
|
|
24
22
|
useFactory: internalError,
|
|
@@ -26,7 +24,7 @@ const commonGuards = [
|
|
|
26
24
|
logger: LOGGER_TOKEN,
|
|
27
25
|
responseManager: RESPONSE_MANAGER_TOKEN,
|
|
28
26
|
},
|
|
29
|
-
},
|
|
27
|
+
}),
|
|
30
28
|
];
|
|
31
29
|
|
|
32
30
|
export { commonGuards };
|
|
@@ -2,27 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var core = require('@tramvai/core');
|
|
5
6
|
var tokensCommon = require('@tramvai/tokens-common');
|
|
6
7
|
var tokensRouter = require('@tramvai/tokens-router');
|
|
7
8
|
var loadBundle = require('./loadBundle.js');
|
|
8
9
|
var internalError = require('./internalError.js');
|
|
9
10
|
|
|
10
11
|
const commonGuards = [
|
|
11
|
-
{
|
|
12
|
+
core.provide({
|
|
12
13
|
provide: tokensRouter.ROUTER_GUARD_TOKEN,
|
|
13
14
|
multi: true,
|
|
14
15
|
useFactory: loadBundle.loadBundle,
|
|
15
16
|
deps: {
|
|
16
17
|
logger: tokensCommon.LOGGER_TOKEN,
|
|
17
18
|
bundleManager: tokensCommon.BUNDLE_MANAGER_TOKEN,
|
|
18
|
-
actionRegistry: tokensCommon.ACTION_REGISTRY_TOKEN,
|
|
19
19
|
responseManager: tokensCommon.RESPONSE_MANAGER_TOKEN,
|
|
20
|
-
|
|
21
|
-
dispatcherContext: tokensCommon.DISPATCHER_CONTEXT_TOKEN,
|
|
22
|
-
pageService: tokensRouter.PAGE_SERVICE_TOKEN,
|
|
20
|
+
pageRegistry: tokensRouter.PAGE_REGISTRY_TOKEN,
|
|
23
21
|
},
|
|
24
|
-
},
|
|
25
|
-
{
|
|
22
|
+
}),
|
|
23
|
+
core.provide({
|
|
26
24
|
provide: tokensRouter.ROUTER_GUARD_TOKEN,
|
|
27
25
|
multi: true,
|
|
28
26
|
useFactory: internalError.internalError,
|
|
@@ -30,7 +28,7 @@ const commonGuards = [
|
|
|
30
28
|
logger: tokensCommon.LOGGER_TOKEN,
|
|
31
29
|
responseManager: tokensCommon.RESPONSE_MANAGER_TOKEN,
|
|
32
30
|
},
|
|
33
|
-
},
|
|
31
|
+
}),
|
|
34
32
|
];
|
|
35
33
|
|
|
36
34
|
exports.commonGuards = commonGuards;
|
|
@@ -1,57 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import { resolveLazyComponent } from '@tramvai/react';
|
|
3
|
-
|
|
4
|
-
const loadBundle = ({ bundleManager, logger, actionRegistry, responseManager, dispatcher, dispatcherContext, pageService, }) => {
|
|
1
|
+
const loadBundle = ({ bundleManager, logger, responseManager, pageRegistry, }) => {
|
|
5
2
|
const log = logger('route:load-bundles');
|
|
6
3
|
return async ({ to }) => {
|
|
7
|
-
var _a;
|
|
8
4
|
log.debug({
|
|
9
5
|
event: 'load-bundle',
|
|
10
6
|
route: to,
|
|
11
7
|
});
|
|
12
|
-
const { bundle, pageComponent
|
|
8
|
+
const { bundle, pageComponent } = to.config;
|
|
13
9
|
if (!bundleManager.has(bundle, pageComponent)) {
|
|
14
10
|
log.info({
|
|
15
11
|
event: 'load-bundle-not-found',
|
|
16
12
|
bundle,
|
|
17
13
|
pageComponent,
|
|
18
14
|
});
|
|
19
|
-
// если бандл не найден, то всё ок и мы должны вернуть 404 на сервере,
|
|
20
|
-
// а на клиенте просто загрузить новую страницу
|
|
21
15
|
responseManager.setStatus(404);
|
|
22
16
|
return false;
|
|
23
17
|
}
|
|
24
|
-
// Пытаемся загрузить и в случае инициализации на клиенте, т.к.
|
|
25
|
-
// несмотря на наличие бандла в разметке, все равно мы должны дождаться
|
|
26
|
-
// его загрузки перед рендером
|
|
27
18
|
try {
|
|
28
|
-
|
|
29
|
-
// for file-system pages bundle is virtual, so it will be loaded in parallel with nested layout
|
|
30
|
-
// for classic bundles, page component will be loaded after bundle loading
|
|
31
|
-
promises.push(bundleManager.get(bundle, pageComponent));
|
|
32
|
-
if (nestedLayoutComponent) {
|
|
33
|
-
promises.push(resolveLazyComponent(pageService.resolveComponentFromConfig('nestedLayout')));
|
|
34
|
-
}
|
|
35
|
-
const [resolvedBundle, resolvedLayout] = await Promise.all(promises);
|
|
36
|
-
const { components, reducers } = resolvedBundle;
|
|
37
|
-
const component = components[pageComponent];
|
|
38
|
-
// pageComponent should have required fields even if it is lazy,
|
|
39
|
-
// thanks to `git log 9466cb32bfb71ba49144ef839d3d5bce246e213c -L90,103:packages/modules/common/src/bundleManager/bundleManager.ts`
|
|
40
|
-
(_a = component === null || component === void 0 ? void 0 : component.reducers) === null || _a === void 0 ? void 0 : _a.forEach((reducer) => dispatcherContext.getStore(reducer));
|
|
41
|
-
reducers === null || reducers === void 0 ? void 0 : reducers.forEach((reducer) => dispatcherContext.getStore(reducer));
|
|
42
|
-
// @todo: reuse logic from bundleManager?
|
|
43
|
-
// register nested layout actions and reducers for current page
|
|
44
|
-
if (resolvedLayout) {
|
|
45
|
-
if ('actions' in resolvedLayout && isArray(resolvedLayout.actions)) {
|
|
46
|
-
actionRegistry.add(pageComponent, resolvedLayout.actions);
|
|
47
|
-
}
|
|
48
|
-
if ('reducers' in resolvedLayout && isArray(resolvedLayout.reducers)) {
|
|
49
|
-
resolvedLayout.reducers.forEach((reducer) => {
|
|
50
|
-
dispatcher.registerStore(reducer);
|
|
51
|
-
dispatcherContext.getStore(reducer);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
19
|
+
await pageRegistry.resolve(to);
|
|
55
20
|
}
|
|
56
21
|
catch (error) {
|
|
57
22
|
log.error({
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { NavigationGuard } from '@tinkoff/router';
|
|
2
|
-
import type { BUNDLE_MANAGER_TOKEN,
|
|
3
|
-
import type {
|
|
4
|
-
export declare const loadBundle: ({ bundleManager, logger,
|
|
2
|
+
import type { BUNDLE_MANAGER_TOKEN, LOGGER_TOKEN, RESPONSE_MANAGER_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
import type { PAGE_REGISTRY_TOKEN } from '@tramvai/tokens-router';
|
|
4
|
+
export declare const loadBundle: ({ bundleManager, logger, responseManager, pageRegistry, }: {
|
|
5
5
|
bundleManager: typeof BUNDLE_MANAGER_TOKEN;
|
|
6
6
|
logger: typeof LOGGER_TOKEN;
|
|
7
|
-
actionRegistry: typeof ACTION_REGISTRY_TOKEN;
|
|
8
7
|
responseManager: typeof RESPONSE_MANAGER_TOKEN;
|
|
9
|
-
|
|
10
|
-
dispatcherContext: typeof DISPATCHER_CONTEXT_TOKEN;
|
|
11
|
-
pageService: typeof PAGE_SERVICE_TOKEN;
|
|
8
|
+
pageRegistry: typeof PAGE_REGISTRY_TOKEN;
|
|
12
9
|
}) => NavigationGuard;
|
|
@@ -1,57 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import { resolveLazyComponent } from '@tramvai/react';
|
|
3
|
-
|
|
4
|
-
const loadBundle = ({ bundleManager, logger, actionRegistry, responseManager, dispatcher, dispatcherContext, pageService, }) => {
|
|
1
|
+
const loadBundle = ({ bundleManager, logger, responseManager, pageRegistry, }) => {
|
|
5
2
|
const log = logger('route:load-bundles');
|
|
6
3
|
return async ({ to }) => {
|
|
7
|
-
var _a;
|
|
8
4
|
log.debug({
|
|
9
5
|
event: 'load-bundle',
|
|
10
6
|
route: to,
|
|
11
7
|
});
|
|
12
|
-
const { bundle, pageComponent
|
|
8
|
+
const { bundle, pageComponent } = to.config;
|
|
13
9
|
if (!bundleManager.has(bundle, pageComponent)) {
|
|
14
10
|
log.info({
|
|
15
11
|
event: 'load-bundle-not-found',
|
|
16
12
|
bundle,
|
|
17
13
|
pageComponent,
|
|
18
14
|
});
|
|
19
|
-
// если бандл не найден, то всё ок и мы должны вернуть 404 на сервере,
|
|
20
|
-
// а на клиенте просто загрузить новую страницу
|
|
21
15
|
responseManager.setStatus(404);
|
|
22
16
|
return false;
|
|
23
17
|
}
|
|
24
|
-
// Пытаемся загрузить и в случае инициализации на клиенте, т.к.
|
|
25
|
-
// несмотря на наличие бандла в разметке, все равно мы должны дождаться
|
|
26
|
-
// его загрузки перед рендером
|
|
27
18
|
try {
|
|
28
|
-
|
|
29
|
-
// for file-system pages bundle is virtual, so it will be loaded in parallel with nested layout
|
|
30
|
-
// for classic bundles, page component will be loaded after bundle loading
|
|
31
|
-
promises.push(bundleManager.get(bundle, pageComponent));
|
|
32
|
-
if (nestedLayoutComponent) {
|
|
33
|
-
promises.push(resolveLazyComponent(pageService.resolveComponentFromConfig('nestedLayout')));
|
|
34
|
-
}
|
|
35
|
-
const [resolvedBundle, resolvedLayout] = await Promise.all(promises);
|
|
36
|
-
const { components, reducers } = resolvedBundle;
|
|
37
|
-
const component = components[pageComponent];
|
|
38
|
-
// pageComponent should have required fields even if it is lazy,
|
|
39
|
-
// thanks to `git log 9466cb32bfb71ba49144ef839d3d5bce246e213c -L90,103:packages/modules/common/src/bundleManager/bundleManager.ts`
|
|
40
|
-
(_a = component === null || component === void 0 ? void 0 : component.reducers) === null || _a === void 0 ? void 0 : _a.forEach((reducer) => dispatcherContext.getStore(reducer));
|
|
41
|
-
reducers === null || reducers === void 0 ? void 0 : reducers.forEach((reducer) => dispatcherContext.getStore(reducer));
|
|
42
|
-
// @todo: reuse logic from bundleManager?
|
|
43
|
-
// register nested layout actions and reducers for current page
|
|
44
|
-
if (resolvedLayout) {
|
|
45
|
-
if ('actions' in resolvedLayout && isArray(resolvedLayout.actions)) {
|
|
46
|
-
actionRegistry.add(pageComponent, resolvedLayout.actions);
|
|
47
|
-
}
|
|
48
|
-
if ('reducers' in resolvedLayout && isArray(resolvedLayout.reducers)) {
|
|
49
|
-
resolvedLayout.reducers.forEach((reducer) => {
|
|
50
|
-
dispatcher.registerStore(reducer);
|
|
51
|
-
dispatcherContext.getStore(reducer);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
19
|
+
await pageRegistry.resolve(to);
|
|
55
20
|
}
|
|
56
21
|
catch (error) {
|
|
57
22
|
log.error({
|
|
@@ -2,64 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var react = require('@tramvai/react');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
|
|
11
|
-
|
|
12
|
-
const loadBundle = ({ bundleManager, logger, actionRegistry, responseManager, dispatcher, dispatcherContext, pageService, }) => {
|
|
5
|
+
const loadBundle = ({ bundleManager, logger, responseManager, pageRegistry, }) => {
|
|
13
6
|
const log = logger('route:load-bundles');
|
|
14
7
|
return async ({ to }) => {
|
|
15
|
-
var _a;
|
|
16
8
|
log.debug({
|
|
17
9
|
event: 'load-bundle',
|
|
18
10
|
route: to,
|
|
19
11
|
});
|
|
20
|
-
const { bundle, pageComponent
|
|
12
|
+
const { bundle, pageComponent } = to.config;
|
|
21
13
|
if (!bundleManager.has(bundle, pageComponent)) {
|
|
22
14
|
log.info({
|
|
23
15
|
event: 'load-bundle-not-found',
|
|
24
16
|
bundle,
|
|
25
17
|
pageComponent,
|
|
26
18
|
});
|
|
27
|
-
// если бандл не найден, то всё ок и мы должны вернуть 404 на сервере,
|
|
28
|
-
// а на клиенте просто загрузить новую страницу
|
|
29
19
|
responseManager.setStatus(404);
|
|
30
20
|
return false;
|
|
31
21
|
}
|
|
32
|
-
// Пытаемся загрузить и в случае инициализации на клиенте, т.к.
|
|
33
|
-
// несмотря на наличие бандла в разметке, все равно мы должны дождаться
|
|
34
|
-
// его загрузки перед рендером
|
|
35
22
|
try {
|
|
36
|
-
|
|
37
|
-
// for file-system pages bundle is virtual, so it will be loaded in parallel with nested layout
|
|
38
|
-
// for classic bundles, page component will be loaded after bundle loading
|
|
39
|
-
promises.push(bundleManager.get(bundle, pageComponent));
|
|
40
|
-
if (nestedLayoutComponent) {
|
|
41
|
-
promises.push(react.resolveLazyComponent(pageService.resolveComponentFromConfig('nestedLayout')));
|
|
42
|
-
}
|
|
43
|
-
const [resolvedBundle, resolvedLayout] = await Promise.all(promises);
|
|
44
|
-
const { components, reducers } = resolvedBundle;
|
|
45
|
-
const component = components[pageComponent];
|
|
46
|
-
// pageComponent should have required fields even if it is lazy,
|
|
47
|
-
// thanks to `git log 9466cb32bfb71ba49144ef839d3d5bce246e213c -L90,103:packages/modules/common/src/bundleManager/bundleManager.ts`
|
|
48
|
-
(_a = component === null || component === void 0 ? void 0 : component.reducers) === null || _a === void 0 ? void 0 : _a.forEach((reducer) => dispatcherContext.getStore(reducer));
|
|
49
|
-
reducers === null || reducers === void 0 ? void 0 : reducers.forEach((reducer) => dispatcherContext.getStore(reducer));
|
|
50
|
-
// @todo: reuse logic from bundleManager?
|
|
51
|
-
// register nested layout actions and reducers for current page
|
|
52
|
-
if (resolvedLayout) {
|
|
53
|
-
if ('actions' in resolvedLayout && isArray__default["default"](resolvedLayout.actions)) {
|
|
54
|
-
actionRegistry.add(pageComponent, resolvedLayout.actions);
|
|
55
|
-
}
|
|
56
|
-
if ('reducers' in resolvedLayout && isArray__default["default"](resolvedLayout.reducers)) {
|
|
57
|
-
resolvedLayout.reducers.forEach((reducer) => {
|
|
58
|
-
dispatcher.registerStore(reducer);
|
|
59
|
-
dispatcherContext.getStore(reducer);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
23
|
+
await pageRegistry.resolve(to);
|
|
63
24
|
}
|
|
64
25
|
catch (error) {
|
|
65
26
|
log.error({
|
|
@@ -22,13 +22,7 @@ export declare const clientTokens: (import("@tinkoff/dippy/lib/Provider").ValueP
|
|
|
22
22
|
token: import("@tramvai/tokens-router").RouteResolve & {
|
|
23
23
|
__type?: "base token";
|
|
24
24
|
};
|
|
25
|
-
optional:
|
|
26
|
-
};
|
|
27
|
-
componentRegistry: import("@tramvai/tokens-common").ComponentRegistry & {
|
|
28
|
-
__type?: "base token";
|
|
29
|
-
};
|
|
30
|
-
bundleManager: import("@tramvai/tokens-common").BundleManager & {
|
|
31
|
-
__type?: "base token";
|
|
25
|
+
optional: true;
|
|
32
26
|
};
|
|
33
27
|
logger: import("@tramvai/tokens-common").Logger & ((configOrName: string | {
|
|
34
28
|
[key: string]: any;
|
|
@@ -44,6 +38,15 @@ export declare const clientTokens: (import("@tinkoff/dippy/lib/Provider").ValueP
|
|
|
44
38
|
} & {
|
|
45
39
|
__type?: "base token";
|
|
46
40
|
};
|
|
41
|
+
pageRegistry: import("@tramvai/tokens-router").PageRegistry & {
|
|
42
|
+
__type?: "base token";
|
|
43
|
+
};
|
|
44
|
+
prefetchHandlers: {
|
|
45
|
+
token: ((route: import("@tinkoff/router").Route) => Promise<void>) & {
|
|
46
|
+
__type?: "multi token";
|
|
47
|
+
};
|
|
48
|
+
optional: true;
|
|
49
|
+
};
|
|
47
50
|
}, {
|
|
48
51
|
prefetch: (url: string) => Promise<void>;
|
|
49
52
|
}> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithoutDeps<{
|
|
@@ -59,13 +62,7 @@ export declare const clientTokens: (import("@tinkoff/dippy/lib/Provider").ValueP
|
|
|
59
62
|
token: import("@tramvai/tokens-router").RouteResolve & {
|
|
60
63
|
__type?: "base token";
|
|
61
64
|
};
|
|
62
|
-
optional:
|
|
63
|
-
};
|
|
64
|
-
componentRegistry: import("@tramvai/tokens-common").ComponentRegistry & {
|
|
65
|
-
__type?: "base token";
|
|
66
|
-
};
|
|
67
|
-
bundleManager: import("@tramvai/tokens-common").BundleManager & {
|
|
68
|
-
__type?: "base token";
|
|
65
|
+
optional: true;
|
|
69
66
|
};
|
|
70
67
|
logger: import("@tramvai/tokens-common").Logger & ((configOrName: string | {
|
|
71
68
|
[key: string]: any;
|
|
@@ -81,6 +78,15 @@ export declare const clientTokens: (import("@tinkoff/dippy/lib/Provider").ValueP
|
|
|
81
78
|
} & {
|
|
82
79
|
__type?: "base token";
|
|
83
80
|
};
|
|
81
|
+
pageRegistry: import("@tramvai/tokens-router").PageRegistry & {
|
|
82
|
+
__type?: "base token";
|
|
83
|
+
};
|
|
84
|
+
prefetchHandlers: {
|
|
85
|
+
token: ((route: import("@tinkoff/router").Route) => Promise<void>) & {
|
|
86
|
+
__type?: "multi token";
|
|
87
|
+
};
|
|
88
|
+
optional: true;
|
|
89
|
+
};
|
|
84
90
|
}, {
|
|
85
91
|
prefetch: (url: string) => Promise<void>;
|
|
86
92
|
}> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithoutDeps<{
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { createToken, provide } from '@tramvai/core';
|
|
2
|
-
import {
|
|
3
|
-
import { LINK_PREFETCH_MANAGER_TOKEN, ROUTER_TOKEN, ROUTE_RESOLVE_TOKEN } from '@tramvai/tokens-router';
|
|
1
|
+
import { createToken, provide, optional } from '@tramvai/core';
|
|
2
|
+
import { LOGGER_TOKEN } from '@tramvai/tokens-common';
|
|
3
|
+
import { LINK_PREFETCH_MANAGER_TOKEN, ROUTER_TOKEN, ROUTE_RESOLVE_TOKEN, PAGE_REGISTRY_TOKEN, LINK_PREFETCH_HANDLER_TOKEN } from '@tramvai/tokens-router';
|
|
4
4
|
import { parse } from '@tinkoff/url';
|
|
5
|
-
import { resolveLazyComponent } from '@tramvai/react';
|
|
6
5
|
import { scheduling } from '@tramvai/state';
|
|
7
|
-
import { isFileSystemPageComponent } from '@tramvai/experiments';
|
|
8
6
|
import { routeTransformToken } from '../../tokens.browser.js';
|
|
9
7
|
|
|
10
8
|
const PREFETCHED_LINKS_CACHE_TOKEN = createToken();
|
|
@@ -37,7 +35,7 @@ const prefetchProviders = [
|
|
|
37
35
|
}),
|
|
38
36
|
provide({
|
|
39
37
|
provide: LINK_PREFETCH_MANAGER_TOKEN,
|
|
40
|
-
useFactory: ({ router, routeTransform, routeResolve,
|
|
38
|
+
useFactory: ({ router, routeTransform, routeResolve, logger, prefetchedLinksCache, prefetchedLinksQueue, pageRegistry, prefetchHandlers, }) => {
|
|
41
39
|
const log = logger('link-prefetch-manager');
|
|
42
40
|
const prefetch = async (url) => {
|
|
43
41
|
// prefetch needed for cache assets by browser, so we want to prefetch resources for any page only once.
|
|
@@ -68,33 +66,18 @@ const prefetchProviders = [
|
|
|
68
66
|
return;
|
|
69
67
|
}
|
|
70
68
|
// @todo: очередь запросов!
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const promises = [];
|
|
75
|
-
// no need for bundle and page component actions amd reducers initialization,
|
|
76
|
-
// so copy only part of `modules/guards/common/loadBundle.ts` logic,
|
|
77
|
-
// all relative assets will be fetched
|
|
78
|
-
if (bundleManager.has(bundle, pageComponent)) {
|
|
79
|
-
promises.push(bundleManager.get(bundle, pageComponent));
|
|
80
|
-
}
|
|
81
|
-
// no need for nestedLayoutComponent actions amd reducers initialization,
|
|
82
|
-
// so copy only part of `modules/guards/common/loadBundle.ts` logic,
|
|
83
|
-
// all relative assets will be fetched
|
|
84
|
-
if (nestedLayoutComponent) {
|
|
85
|
-
promises.push(resolveLazyComponent(componentRegistry.get(nestedLayoutComponent, isFileSystemPageComponent(pageComponent) ? '__default' : bundle)));
|
|
86
|
-
}
|
|
87
|
-
await Promise.all(promises)
|
|
88
|
-
.then(() => {
|
|
69
|
+
try {
|
|
70
|
+
await pageRegistry.resolve(route);
|
|
71
|
+
await Promise.all(prefetchHandlers.map((handler) => handler(route)));
|
|
89
72
|
log.info({ event: 'prefetch-route-success', url });
|
|
90
|
-
}
|
|
91
|
-
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
92
75
|
log.warn({
|
|
93
76
|
event: 'prefetch-fail',
|
|
94
77
|
url,
|
|
95
78
|
error,
|
|
96
79
|
});
|
|
97
|
-
}
|
|
80
|
+
}
|
|
98
81
|
};
|
|
99
82
|
return {
|
|
100
83
|
prefetch: (url) => {
|
|
@@ -106,15 +89,12 @@ const prefetchProviders = [
|
|
|
106
89
|
deps: {
|
|
107
90
|
router: ROUTER_TOKEN,
|
|
108
91
|
routeTransform: routeTransformToken,
|
|
109
|
-
routeResolve:
|
|
110
|
-
token: ROUTE_RESOLVE_TOKEN,
|
|
111
|
-
optional: true,
|
|
112
|
-
},
|
|
113
|
-
componentRegistry: COMPONENT_REGISTRY_TOKEN,
|
|
114
|
-
bundleManager: BUNDLE_MANAGER_TOKEN,
|
|
92
|
+
routeResolve: optional(ROUTE_RESOLVE_TOKEN),
|
|
115
93
|
logger: LOGGER_TOKEN,
|
|
116
94
|
prefetchedLinksCache: PREFETCHED_LINKS_CACHE_TOKEN,
|
|
117
95
|
prefetchedLinksQueue: PREFETCHED_LINKS_QUEUE_TOKEN,
|
|
96
|
+
pageRegistry: PAGE_REGISTRY_TOKEN,
|
|
97
|
+
prefetchHandlers: optional(LINK_PREFETCH_HANDLER_TOKEN),
|
|
118
98
|
},
|
|
119
99
|
}),
|
|
120
100
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Route } from '@tinkoff/router';
|
|
1
2
|
export declare const prefetchProviders: (import("@tramvai/core").Provider<unknown, Set<string>> | import("@tramvai/core").Provider<unknown, {
|
|
2
3
|
add(run: () => Promise<void>): Promise<void>;
|
|
3
4
|
}> | import("@tramvai/core").Provider<{
|
|
@@ -11,13 +12,7 @@ export declare const prefetchProviders: (import("@tramvai/core").Provider<unknow
|
|
|
11
12
|
token: import("@tramvai/tokens-router").RouteResolve & {
|
|
12
13
|
__type?: "base token";
|
|
13
14
|
};
|
|
14
|
-
optional:
|
|
15
|
-
};
|
|
16
|
-
componentRegistry: import("@tramvai/tokens-common").ComponentRegistry & {
|
|
17
|
-
__type?: "base token";
|
|
18
|
-
};
|
|
19
|
-
bundleManager: import("@tramvai/tokens-common").BundleManager & {
|
|
20
|
-
__type?: "base token";
|
|
15
|
+
optional: true;
|
|
21
16
|
};
|
|
22
17
|
logger: import("@tramvai/tokens-common").Logger & ((configOrName: string | {
|
|
23
18
|
[key: string]: any;
|
|
@@ -33,6 +28,15 @@ export declare const prefetchProviders: (import("@tramvai/core").Provider<unknow
|
|
|
33
28
|
} & {
|
|
34
29
|
__type?: "base token";
|
|
35
30
|
};
|
|
31
|
+
pageRegistry: import("@tramvai/tokens-router").PageRegistry & {
|
|
32
|
+
__type?: "base token";
|
|
33
|
+
};
|
|
34
|
+
prefetchHandlers: {
|
|
35
|
+
token: ((route: Route) => Promise<void>) & {
|
|
36
|
+
__type?: "multi token";
|
|
37
|
+
};
|
|
38
|
+
optional: true;
|
|
39
|
+
};
|
|
36
40
|
}, {
|
|
37
41
|
prefetch: (url: string) => Promise<void>;
|
|
38
42
|
}>)[];
|