@tramvai/module-child-app 4.12.5 → 4.13.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/shared/di.browser.js +13 -2
- package/lib/shared/di.d.ts +7 -3
- package/lib/shared/di.es.js +13 -2
- package/lib/shared/di.js +13 -2
- package/lib/shared/isolatedDi.browser.js +8 -0
- package/lib/shared/isolatedDi.d.ts +4 -0
- package/lib/shared/isolatedDi.es.js +8 -0
- package/lib/shared/isolatedDi.js +12 -0
- package/lib/shared/providers.browser.js +4 -2
- package/lib/shared/providers.es.js +4 -2
- package/lib/shared/providers.js +2 -0
- package/lib/shared/singletonDi.browser.js +31 -11
- package/lib/shared/singletonDi.d.ts +7 -2
- package/lib/shared/singletonDi.es.js +31 -11
- package/lib/shared/singletonDi.js +31 -11
- package/package.json +11 -11
package/lib/shared/di.browser.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ChildContainer } from '@tinkoff/dippy';
|
|
2
2
|
import { getChildProviders } from './child/providers.browser.js';
|
|
3
|
+
import { shouldIsolateDi } from './isolatedDi.browser.js';
|
|
3
4
|
|
|
4
5
|
class DiManager {
|
|
5
|
-
constructor({ appDi, loader, singletonDiManager, }) {
|
|
6
|
+
constructor({ appDi, loader, singletonDiManager, rootDiAccessMode, }) {
|
|
6
7
|
this.cache = new Map();
|
|
7
8
|
this.appDi = appDi;
|
|
8
9
|
this.loader = loader;
|
|
9
10
|
this.singletonDiManager = singletonDiManager;
|
|
11
|
+
this.rootDiAccessMode = rootDiAccessMode;
|
|
10
12
|
}
|
|
11
13
|
getChildDi(config) {
|
|
12
14
|
const { key } = config;
|
|
@@ -31,7 +33,16 @@ class DiManager {
|
|
|
31
33
|
if (!singletonDi) {
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
|
-
const
|
|
36
|
+
const isolateDi = this.rootDiAccessMode
|
|
37
|
+
? shouldIsolateDi(config, this.rootDiAccessMode)
|
|
38
|
+
: false;
|
|
39
|
+
let di;
|
|
40
|
+
if (isolateDi) {
|
|
41
|
+
di = new ChildContainer(singletonDi);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
di = new ChildContainer(singletonDi, this.appDi);
|
|
45
|
+
}
|
|
35
46
|
'getLoadableStats' in this.loader ? this.loader.getLoadableStats(config) : undefined;
|
|
36
47
|
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
37
48
|
const childProviders = getChildProviders(this.appDi);
|
package/lib/shared/di.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import type { Container } from '@tinkoff/dippy';
|
|
1
|
+
import type { Container, ExtractDependencyType } from '@tinkoff/dippy';
|
|
2
2
|
import { ChildContainer } from '@tinkoff/dippy';
|
|
3
|
-
import type { ChildAppDiManager, ChildAppLoader, ChildAppFinalConfig } from '@tramvai/tokens-child-app';
|
|
3
|
+
import type { ChildAppDiManager, ChildAppLoader, ChildAppFinalConfig, CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN } from '@tramvai/tokens-child-app';
|
|
4
|
+
type RootDiAccessMode = ExtractDependencyType<typeof CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN>;
|
|
4
5
|
export declare class DiManager implements ChildAppDiManager {
|
|
5
6
|
private appDi;
|
|
6
7
|
private loader;
|
|
7
8
|
private singletonDiManager;
|
|
9
|
+
private rootDiAccessMode?;
|
|
8
10
|
private cache;
|
|
9
|
-
constructor({ appDi, loader, singletonDiManager, }: {
|
|
11
|
+
constructor({ appDi, loader, singletonDiManager, rootDiAccessMode, }: {
|
|
10
12
|
appDi: Container;
|
|
11
13
|
loader: ChildAppLoader;
|
|
12
14
|
singletonDiManager: ChildAppDiManager;
|
|
15
|
+
rootDiAccessMode?: RootDiAccessMode | null;
|
|
13
16
|
});
|
|
14
17
|
getChildDi(config: ChildAppFinalConfig): Container | ChildContainer | undefined;
|
|
15
18
|
forEachChildDi(cb: (di: Container) => void): void;
|
|
16
19
|
private resolveDi;
|
|
17
20
|
}
|
|
21
|
+
export {};
|
|
18
22
|
//# sourceMappingURL=di.d.ts.map
|
package/lib/shared/di.es.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ChildContainer } from '@tinkoff/dippy';
|
|
2
2
|
import { getChildProviders } from './child/providers.es.js';
|
|
3
|
+
import { shouldIsolateDi } from './isolatedDi.es.js';
|
|
3
4
|
|
|
4
5
|
class DiManager {
|
|
5
|
-
constructor({ appDi, loader, singletonDiManager, }) {
|
|
6
|
+
constructor({ appDi, loader, singletonDiManager, rootDiAccessMode, }) {
|
|
6
7
|
this.cache = new Map();
|
|
7
8
|
this.appDi = appDi;
|
|
8
9
|
this.loader = loader;
|
|
9
10
|
this.singletonDiManager = singletonDiManager;
|
|
11
|
+
this.rootDiAccessMode = rootDiAccessMode;
|
|
10
12
|
}
|
|
11
13
|
getChildDi(config) {
|
|
12
14
|
const { key } = config;
|
|
@@ -31,7 +33,16 @@ class DiManager {
|
|
|
31
33
|
if (!singletonDi) {
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
|
-
const
|
|
36
|
+
const isolateDi = this.rootDiAccessMode
|
|
37
|
+
? shouldIsolateDi(config, this.rootDiAccessMode)
|
|
38
|
+
: false;
|
|
39
|
+
let di;
|
|
40
|
+
if (isolateDi) {
|
|
41
|
+
di = new ChildContainer(singletonDi);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
di = new ChildContainer(singletonDi, this.appDi);
|
|
45
|
+
}
|
|
35
46
|
const statsLoadable = 'getLoadableStats' in this.loader ? this.loader.getLoadableStats(config) : undefined;
|
|
36
47
|
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
37
48
|
const childProviders = getChildProviders(this.appDi, statsLoadable);
|
package/lib/shared/di.js
CHANGED
|
@@ -4,13 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var dippy = require('@tinkoff/dippy');
|
|
6
6
|
var providers = require('./child/providers.js');
|
|
7
|
+
var isolatedDi = require('./isolatedDi.js');
|
|
7
8
|
|
|
8
9
|
class DiManager {
|
|
9
|
-
constructor({ appDi, loader, singletonDiManager, }) {
|
|
10
|
+
constructor({ appDi, loader, singletonDiManager, rootDiAccessMode, }) {
|
|
10
11
|
this.cache = new Map();
|
|
11
12
|
this.appDi = appDi;
|
|
12
13
|
this.loader = loader;
|
|
13
14
|
this.singletonDiManager = singletonDiManager;
|
|
15
|
+
this.rootDiAccessMode = rootDiAccessMode;
|
|
14
16
|
}
|
|
15
17
|
getChildDi(config) {
|
|
16
18
|
const { key } = config;
|
|
@@ -35,7 +37,16 @@ class DiManager {
|
|
|
35
37
|
if (!singletonDi) {
|
|
36
38
|
return;
|
|
37
39
|
}
|
|
38
|
-
const
|
|
40
|
+
const isolateDi = this.rootDiAccessMode
|
|
41
|
+
? isolatedDi.shouldIsolateDi(config, this.rootDiAccessMode)
|
|
42
|
+
: false;
|
|
43
|
+
let di;
|
|
44
|
+
if (isolateDi) {
|
|
45
|
+
di = new dippy.ChildContainer(singletonDi);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
di = new dippy.ChildContainer(singletonDi, this.appDi);
|
|
49
|
+
}
|
|
39
50
|
const statsLoadable = 'getLoadableStats' in this.loader ? this.loader.getLoadableStats(config) : undefined;
|
|
40
51
|
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
41
52
|
const childProviders = providers.getChildProviders(this.appDi, statsLoadable);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExtractDependencyType } from '@tinkoff/dippy';
|
|
2
|
+
import type { CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN, ChildAppFinalConfig } from '@tramvai/tokens-child-app';
|
|
3
|
+
export declare const shouldIsolateDi: (config: ChildAppFinalConfig, rootDiAccessMode: ExtractDependencyType<typeof CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN>) => boolean;
|
|
4
|
+
//# sourceMappingURL=isolatedDi.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const shouldIsolateDi = (config, rootDiAccessMode) => {
|
|
6
|
+
const { name } = config;
|
|
7
|
+
return rootDiAccessMode.mode === 'blacklist'
|
|
8
|
+
? rootDiAccessMode.list.includes(name)
|
|
9
|
+
: !rootDiAccessMode.list.includes(name);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.shouldIsolateDi = shouldIsolateDi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Scope, DI_TOKEN } from '@tinkoff/dippy';
|
|
1
|
+
import { Scope, DI_TOKEN, optional } from '@tinkoff/dippy';
|
|
2
2
|
import { provide, commandLineListTokens, COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
3
|
-
import { CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLUTION_CONFIGS_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_RESOLVE_BASE_URL_TOKEN, CHILD_APP_SINGLETON_DI_MANAGER_TOKEN, CHILD_APP_LOADER_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN } from '@tramvai/tokens-child-app';
|
|
3
|
+
import { CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLUTION_CONFIGS_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_RESOLVE_BASE_URL_TOKEN, CHILD_APP_SINGLETON_DI_MANAGER_TOKEN, CHILD_APP_LOADER_TOKEN, CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN } from '@tramvai/tokens-child-app';
|
|
4
4
|
import { COMBINE_REDUCERS, LOGGER_TOKEN, ENV_MANAGER_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, CLEAR_CACHE_TOKEN, ENV_USED_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { EXTEND_RENDER } from '@tramvai/tokens-render';
|
|
6
6
|
import { SingletonDiManager } from './singletonDi.browser.js';
|
|
@@ -117,6 +117,7 @@ const sharedProviders = [
|
|
|
117
117
|
logger: LOGGER_TOKEN,
|
|
118
118
|
appDi: DI_TOKEN,
|
|
119
119
|
loader: CHILD_APP_LOADER_TOKEN,
|
|
120
|
+
rootDiAccessMode: optional(CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN),
|
|
120
121
|
},
|
|
121
122
|
}),
|
|
122
123
|
provide({
|
|
@@ -126,6 +127,7 @@ const sharedProviders = [
|
|
|
126
127
|
appDi: DI_TOKEN,
|
|
127
128
|
loader: CHILD_APP_LOADER_TOKEN,
|
|
128
129
|
singletonDiManager: CHILD_APP_SINGLETON_DI_MANAGER_TOKEN,
|
|
130
|
+
rootDiAccessMode: optional(CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN),
|
|
129
131
|
},
|
|
130
132
|
}),
|
|
131
133
|
provide({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Scope, DI_TOKEN } from '@tinkoff/dippy';
|
|
1
|
+
import { Scope, DI_TOKEN, optional } from '@tinkoff/dippy';
|
|
2
2
|
import { provide, commandLineListTokens, COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
3
|
-
import { CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLUTION_CONFIGS_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_RESOLVE_BASE_URL_TOKEN, CHILD_APP_SINGLETON_DI_MANAGER_TOKEN, CHILD_APP_LOADER_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN } from '@tramvai/tokens-child-app';
|
|
3
|
+
import { CHILD_APP_RESOLUTION_CONFIG_MANAGER_TOKEN, CHILD_APP_RESOLUTION_CONFIGS_TOKEN, CHILD_APP_RESOLVE_CONFIG_TOKEN, CHILD_APP_RESOLVE_BASE_URL_TOKEN, CHILD_APP_SINGLETON_DI_MANAGER_TOKEN, CHILD_APP_LOADER_TOKEN, CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN, CHILD_APP_DI_MANAGER_TOKEN, CHILD_APP_COMMAND_LINE_RUNNER_TOKEN, CHILD_APP_PRELOAD_MANAGER_TOKEN, CHILD_APP_RENDER_MANAGER_TOKEN } from '@tramvai/tokens-child-app';
|
|
4
4
|
import { COMBINE_REDUCERS, LOGGER_TOKEN, ENV_MANAGER_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, CLEAR_CACHE_TOKEN, ENV_USED_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { EXTEND_RENDER } from '@tramvai/tokens-render';
|
|
6
6
|
import { SingletonDiManager } from './singletonDi.es.js';
|
|
@@ -117,6 +117,7 @@ const sharedProviders = [
|
|
|
117
117
|
logger: LOGGER_TOKEN,
|
|
118
118
|
appDi: DI_TOKEN,
|
|
119
119
|
loader: CHILD_APP_LOADER_TOKEN,
|
|
120
|
+
rootDiAccessMode: optional(CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN),
|
|
120
121
|
},
|
|
121
122
|
}),
|
|
122
123
|
provide({
|
|
@@ -126,6 +127,7 @@ const sharedProviders = [
|
|
|
126
127
|
appDi: DI_TOKEN,
|
|
127
128
|
loader: CHILD_APP_LOADER_TOKEN,
|
|
128
129
|
singletonDiManager: CHILD_APP_SINGLETON_DI_MANAGER_TOKEN,
|
|
130
|
+
rootDiAccessMode: optional(CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN),
|
|
129
131
|
},
|
|
130
132
|
}),
|
|
131
133
|
provide({
|
package/lib/shared/providers.js
CHANGED
|
@@ -121,6 +121,7 @@ const sharedProviders = [
|
|
|
121
121
|
logger: tokensCommon.LOGGER_TOKEN,
|
|
122
122
|
appDi: dippy.DI_TOKEN,
|
|
123
123
|
loader: tokensChildApp.CHILD_APP_LOADER_TOKEN,
|
|
124
|
+
rootDiAccessMode: dippy.optional(tokensChildApp.CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN),
|
|
124
125
|
},
|
|
125
126
|
}),
|
|
126
127
|
core.provide({
|
|
@@ -130,6 +131,7 @@ const sharedProviders = [
|
|
|
130
131
|
appDi: dippy.DI_TOKEN,
|
|
131
132
|
loader: tokensChildApp.CHILD_APP_LOADER_TOKEN,
|
|
132
133
|
singletonDiManager: tokensChildApp.CHILD_APP_SINGLETON_DI_MANAGER_TOKEN,
|
|
134
|
+
rootDiAccessMode: dippy.optional(tokensChildApp.CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN),
|
|
133
135
|
},
|
|
134
136
|
}),
|
|
135
137
|
core.provide({
|
|
@@ -5,13 +5,15 @@ import { CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_DI_TOKEN, CHILD_APP_INTER
|
|
|
5
5
|
import { getChildProviders } from './child/singletonProviders.browser.js';
|
|
6
6
|
import { commonModuleStubs } from './child/stubs.browser.js';
|
|
7
7
|
import { validateChildAppProvider } from './child/validate.browser.js';
|
|
8
|
+
import { shouldIsolateDi } from './isolatedDi.browser.js';
|
|
8
9
|
|
|
9
10
|
class SingletonDiManager {
|
|
10
|
-
constructor({ logger, appDi, loader, }) {
|
|
11
|
+
constructor({ logger, appDi, loader, rootDiAccessMode, }) {
|
|
11
12
|
this.cache = new Map();
|
|
12
13
|
this.log = logger('child-app:singleton-di-manager');
|
|
13
14
|
this.appDi = appDi;
|
|
14
15
|
this.loader = loader;
|
|
16
|
+
this.rootDiAccessMode = rootDiAccessMode;
|
|
15
17
|
}
|
|
16
18
|
getChildDi(config) {
|
|
17
19
|
const { key, tag } = config;
|
|
@@ -43,17 +45,35 @@ class SingletonDiManager {
|
|
|
43
45
|
if (!children) {
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
|
-
const di = new Container([
|
|
47
|
-
{
|
|
48
|
-
provide: CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
49
|
-
useValue: config,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
provide: IS_CHILD_APP_DI_TOKEN,
|
|
53
|
-
useValue: true,
|
|
54
|
-
},
|
|
55
|
-
], this.appDi);
|
|
56
48
|
const { modules = [], providers = [], actions = [] } = children;
|
|
49
|
+
const isolateDi = this.rootDiAccessMode
|
|
50
|
+
? shouldIsolateDi(config, this.rootDiAccessMode)
|
|
51
|
+
: false;
|
|
52
|
+
let di;
|
|
53
|
+
if (isolateDi) {
|
|
54
|
+
di = new Container([
|
|
55
|
+
{
|
|
56
|
+
provide: CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
57
|
+
useValue: config,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
provide: IS_CHILD_APP_DI_TOKEN,
|
|
61
|
+
useValue: true,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
di = new Container([
|
|
67
|
+
{
|
|
68
|
+
provide: CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
69
|
+
useValue: config,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
provide: IS_CHILD_APP_DI_TOKEN,
|
|
73
|
+
useValue: true,
|
|
74
|
+
},
|
|
75
|
+
], this.appDi);
|
|
76
|
+
}
|
|
57
77
|
// add providers on the Singleton Level to make it possible to reuse providers from the root-app Container
|
|
58
78
|
const childProviders = getChildProviders(this.appDi);
|
|
59
79
|
childProviders.forEach((provider) => {
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
import type { ExtractDependencyType } from '@tinkoff/dippy';
|
|
1
2
|
import { Container } from '@tinkoff/dippy';
|
|
2
|
-
import type { ChildAppDiManager, ChildAppFinalConfig, ChildAppLoader } from '@tramvai/tokens-child-app';
|
|
3
|
+
import type { CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN, ChildAppDiManager, ChildAppFinalConfig, ChildAppLoader } from '@tramvai/tokens-child-app';
|
|
3
4
|
import type { LOGGER_TOKEN } from '@tramvai/tokens-common';
|
|
5
|
+
type RootDiAccessMode = ExtractDependencyType<typeof CHILD_APP_ROOT_DI_ACCESS_MODE_TOKEN>;
|
|
4
6
|
export declare class SingletonDiManager implements ChildAppDiManager {
|
|
5
7
|
private readonly log;
|
|
6
8
|
private appDi;
|
|
7
9
|
private loader;
|
|
10
|
+
private rootDiAccessMode?;
|
|
8
11
|
private cache;
|
|
9
|
-
constructor({ logger, appDi, loader, }: {
|
|
12
|
+
constructor({ logger, appDi, loader, rootDiAccessMode, }: {
|
|
10
13
|
logger: typeof LOGGER_TOKEN;
|
|
11
14
|
appDi: Container;
|
|
12
15
|
loader: ChildAppLoader;
|
|
16
|
+
rootDiAccessMode?: RootDiAccessMode | null;
|
|
13
17
|
});
|
|
14
18
|
getChildDi(config: ChildAppFinalConfig): Container | undefined;
|
|
15
19
|
forEachChildDi(cb: (di: Container) => void): void;
|
|
16
20
|
private resolveDi;
|
|
17
21
|
}
|
|
22
|
+
export {};
|
|
18
23
|
//# sourceMappingURL=singletonDi.d.ts.map
|
|
@@ -5,13 +5,15 @@ import { CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_DI_TOKEN, CHILD_APP_INTER
|
|
|
5
5
|
import { getChildProviders } from './child/singletonProviders.es.js';
|
|
6
6
|
import { commonModuleStubs } from './child/stubs.es.js';
|
|
7
7
|
import { validateChildAppProvider } from './child/validate.es.js';
|
|
8
|
+
import { shouldIsolateDi } from './isolatedDi.es.js';
|
|
8
9
|
|
|
9
10
|
class SingletonDiManager {
|
|
10
|
-
constructor({ logger, appDi, loader, }) {
|
|
11
|
+
constructor({ logger, appDi, loader, rootDiAccessMode, }) {
|
|
11
12
|
this.cache = new Map();
|
|
12
13
|
this.log = logger('child-app:singleton-di-manager');
|
|
13
14
|
this.appDi = appDi;
|
|
14
15
|
this.loader = loader;
|
|
16
|
+
this.rootDiAccessMode = rootDiAccessMode;
|
|
15
17
|
}
|
|
16
18
|
getChildDi(config) {
|
|
17
19
|
const { key, tag } = config;
|
|
@@ -43,17 +45,35 @@ class SingletonDiManager {
|
|
|
43
45
|
if (!children) {
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
|
-
const di = new Container([
|
|
47
|
-
{
|
|
48
|
-
provide: CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
49
|
-
useValue: config,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
provide: IS_CHILD_APP_DI_TOKEN,
|
|
53
|
-
useValue: true,
|
|
54
|
-
},
|
|
55
|
-
], this.appDi);
|
|
56
48
|
const { modules = [], providers = [], actions = [] } = children;
|
|
49
|
+
const isolateDi = this.rootDiAccessMode
|
|
50
|
+
? shouldIsolateDi(config, this.rootDiAccessMode)
|
|
51
|
+
: false;
|
|
52
|
+
let di;
|
|
53
|
+
if (isolateDi) {
|
|
54
|
+
di = new Container([
|
|
55
|
+
{
|
|
56
|
+
provide: CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
57
|
+
useValue: config,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
provide: IS_CHILD_APP_DI_TOKEN,
|
|
61
|
+
useValue: true,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
di = new Container([
|
|
67
|
+
{
|
|
68
|
+
provide: CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
69
|
+
useValue: config,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
provide: IS_CHILD_APP_DI_TOKEN,
|
|
73
|
+
useValue: true,
|
|
74
|
+
},
|
|
75
|
+
], this.appDi);
|
|
76
|
+
}
|
|
57
77
|
// add providers on the Singleton Level to make it possible to reuse providers from the root-app Container
|
|
58
78
|
const childProviders = getChildProviders(this.appDi);
|
|
59
79
|
childProviders.forEach((provider) => {
|
|
@@ -9,17 +9,19 @@ var tokensChildApp = require('@tramvai/tokens-child-app');
|
|
|
9
9
|
var singletonProviders = require('./child/singletonProviders.js');
|
|
10
10
|
var stubs = require('./child/stubs.js');
|
|
11
11
|
var validate = require('./child/validate.js');
|
|
12
|
+
var isolatedDi = require('./isolatedDi.js');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
15
|
|
|
15
16
|
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
16
17
|
|
|
17
18
|
class SingletonDiManager {
|
|
18
|
-
constructor({ logger, appDi, loader, }) {
|
|
19
|
+
constructor({ logger, appDi, loader, rootDiAccessMode, }) {
|
|
19
20
|
this.cache = new Map();
|
|
20
21
|
this.log = logger('child-app:singleton-di-manager');
|
|
21
22
|
this.appDi = appDi;
|
|
22
23
|
this.loader = loader;
|
|
24
|
+
this.rootDiAccessMode = rootDiAccessMode;
|
|
23
25
|
}
|
|
24
26
|
getChildDi(config) {
|
|
25
27
|
const { key, tag } = config;
|
|
@@ -51,17 +53,35 @@ class SingletonDiManager {
|
|
|
51
53
|
if (!children) {
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
54
|
-
const di = new dippy.Container([
|
|
55
|
-
{
|
|
56
|
-
provide: tokensChildApp.CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
57
|
-
useValue: config,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
provide: tokensChildApp.IS_CHILD_APP_DI_TOKEN,
|
|
61
|
-
useValue: true,
|
|
62
|
-
},
|
|
63
|
-
], this.appDi);
|
|
64
56
|
const { modules = [], providers = [], actions = [] } = children;
|
|
57
|
+
const isolateDi = this.rootDiAccessMode
|
|
58
|
+
? isolatedDi.shouldIsolateDi(config, this.rootDiAccessMode)
|
|
59
|
+
: false;
|
|
60
|
+
let di;
|
|
61
|
+
if (isolateDi) {
|
|
62
|
+
di = new dippy.Container([
|
|
63
|
+
{
|
|
64
|
+
provide: tokensChildApp.CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
65
|
+
useValue: config,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
provide: tokensChildApp.IS_CHILD_APP_DI_TOKEN,
|
|
69
|
+
useValue: true,
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
di = new dippy.Container([
|
|
75
|
+
{
|
|
76
|
+
provide: tokensChildApp.CHILD_APP_INTERNAL_CONFIG_TOKEN,
|
|
77
|
+
useValue: config,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
provide: tokensChildApp.IS_CHILD_APP_DI_TOKEN,
|
|
81
|
+
useValue: true,
|
|
82
|
+
},
|
|
83
|
+
], this.appDi);
|
|
84
|
+
}
|
|
65
85
|
// add providers on the Singleton Level to make it possible to reuse providers from the root-app Container
|
|
66
86
|
const childProviders = singletonProviders.getChildProviders(this.appDi);
|
|
67
87
|
childProviders.forEach((provider) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-child-app",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "Module for child apps",
|
|
5
5
|
"browser": {
|
|
6
6
|
"./lib/server.js": "./lib/browser.js",
|
|
@@ -33,23 +33,23 @@
|
|
|
33
33
|
"@tinkoff/env-validators": "0.3.1",
|
|
34
34
|
"@tinkoff/module-loader-client": "0.6.3",
|
|
35
35
|
"@tinkoff/module-loader-server": "0.7.1",
|
|
36
|
-
"@tramvai/module-common": "4.
|
|
36
|
+
"@tramvai/module-common": "4.13.0",
|
|
37
37
|
"@tinkoff/url": "0.10.1",
|
|
38
|
-
"@tramvai/child-app-core": "4.
|
|
38
|
+
"@tramvai/child-app-core": "4.13.0",
|
|
39
39
|
"@tramvai/safe-strings": "0.7.1",
|
|
40
|
-
"@tramvai/tokens-child-app": "4.
|
|
40
|
+
"@tramvai/tokens-child-app": "4.13.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@tinkoff/dippy": "0.10.4",
|
|
45
|
-
"@tinkoff/router": "0.4.
|
|
45
|
+
"@tinkoff/router": "0.4.44",
|
|
46
46
|
"@tinkoff/utils": "^2.1.2",
|
|
47
|
-
"@tramvai/core": "4.
|
|
48
|
-
"@tramvai/state": "4.
|
|
49
|
-
"@tramvai/react": "4.
|
|
50
|
-
"@tramvai/tokens-common": "4.
|
|
51
|
-
"@tramvai/tokens-render": "4.
|
|
52
|
-
"@tramvai/tokens-router": "4.
|
|
47
|
+
"@tramvai/core": "4.13.0",
|
|
48
|
+
"@tramvai/state": "4.13.0",
|
|
49
|
+
"@tramvai/react": "4.13.0",
|
|
50
|
+
"@tramvai/tokens-common": "4.13.0",
|
|
51
|
+
"@tramvai/tokens-render": "4.13.0",
|
|
52
|
+
"@tramvai/tokens-router": "4.13.0",
|
|
53
53
|
"react": ">=16.14.0",
|
|
54
54
|
"react-dom": ">=16.14.0",
|
|
55
55
|
"object-assign": "^4.1.1",
|