@tramvai/module-child-app 1.72.2 → 1.73.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 +16 -41
- package/lib/server.browser.js +44 -8
- package/lib/server.es.js +44 -8
- package/lib/server.js +41 -5
- package/lib/shared/child/providers.d.ts +3 -0
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -126,66 +126,41 @@ State for child-apps will be dehydrated on server as separate variable in the re
|
|
|
126
126
|
|
|
127
127
|
:::warning
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
By default, child-app cannot read data from root-app stores, but the you can specify the set of root-app stores that might be used inside child-app.
|
|
130
130
|
|
|
131
|
-
It may be done using `
|
|
131
|
+
It may be done using `CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN` token.
|
|
132
132
|
|
|
133
|
-
This token is considered
|
|
133
|
+
This token is considered undesirable to use as it leads to high coupling with stores from root-app and this way stores in root-app might not change their public interface. But, in most cases, changes in stores ignore breaking change tracking and may breaks backward-compatibility. So **do not use this token if you can**, and if you should - use as little as possible from root-app and provide some fallback in case of wrong data.
|
|
134
134
|
|
|
135
|
-
[See how to do it](#
|
|
135
|
+
[See how to do it](#child_app_internal_root_state_allowed_store_token)
|
|
136
136
|
|
|
137
137
|
:::
|
|
138
138
|
|
|
139
139
|
## API
|
|
140
140
|
|
|
141
|
-
###
|
|
141
|
+
### CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
Defines the list of allowed root-app store names that might be used inside child-app.
|
|
144
144
|
|
|
145
|
-
1.
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
import { createReducer, createEvent } from '@tramvai/state';
|
|
149
|
-
|
|
150
|
-
interface State {
|
|
151
|
-
value: string;
|
|
152
|
-
}
|
|
153
|
-
export const setRootState = createEvent<string>('child-root set state');
|
|
154
|
-
|
|
155
|
-
export const rootStore = createReducer('child-root', { value: 'child' } as State).on(
|
|
156
|
-
setRootState,
|
|
157
|
-
(state, value) => {
|
|
158
|
-
return { value };
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
2. Add provider for the `CHILD_APP_INTERNAL_ROOT_STATE_SUBSCRIPTION_TOKEN` in order to subscribe to store. In subscription you can dispatch internal event from the child-app
|
|
145
|
+
1. Specify stores that might be used inside child-app
|
|
164
146
|
|
|
165
147
|
```ts
|
|
166
148
|
provide({
|
|
167
|
-
provide:
|
|
149
|
+
provide: CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
168
150
|
multi: true,
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
stores: ['root'],
|
|
172
|
-
listener: (state: Record<string, any>) => {
|
|
173
|
-
return context.dispatch(setRootState(`root ${state.root.value}`));
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
deps: {
|
|
178
|
-
context: CONTEXT_TOKEN,
|
|
179
|
-
},
|
|
151
|
+
useValue: [MediaStore, AuthenticateStore],
|
|
180
152
|
});
|
|
181
153
|
```
|
|
182
154
|
|
|
183
|
-
|
|
155
|
+
2. Use the specified root-app stores the same way as usual stores
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import React from 'react';
|
|
159
|
+
import { useSelector } from '@tramvai/state';
|
|
184
160
|
|
|
185
|
-
```tsx
|
|
186
161
|
export const StateCmp = () => {
|
|
187
|
-
const value = useSelector([
|
|
188
|
-
return state
|
|
162
|
+
const value = useSelector(['root'], (state) => {
|
|
163
|
+
return state.root.value;
|
|
189
164
|
});
|
|
190
165
|
|
|
191
166
|
return <div id="child-state">Current Value from Root Store: {value}</div>;
|
package/lib/server.browser.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { provide, COMMAND_LINE_RUNNER_TOKEN, walkOfModules, getModuleParameters, commandLineListTokens as commandLineListTokens$1, Module } from '@tramvai/core';
|
|
3
3
|
import { Container, ChildContainer, Scope, DI_TOKEN } from '@tinkoff/dippy';
|
|
4
|
-
import { commandLineListTokens, CHILD_APP_INTERNAL_ROOT_STATE_SUBSCRIPTION_TOKEN, CHILD_APP_INTERNAL_ACTION_TOKEN, CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_DI_TOKEN, CHILD_APP_INTERNAL_ROOT_DI_BORROW_TOKEN, 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, CHILD_APP_COMMON_INITIAL_STATE_TOKEN, CHILD_APP_INTERNAL_RENDER_TOKEN } from '@tramvai/tokens-child-app';
|
|
4
|
+
import { commandLineListTokens, CHILD_APP_INTERNAL_ROOT_STATE_SUBSCRIPTION_TOKEN, CHILD_APP_INTERNAL_ACTION_TOKEN, CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_DI_TOKEN, CHILD_APP_INTERNAL_ROOT_DI_BORROW_TOKEN, CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN, 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, CHILD_APP_COMMON_INITIAL_STATE_TOKEN, CHILD_APP_INTERNAL_RENDER_TOKEN } from '@tramvai/tokens-child-app';
|
|
5
5
|
export * from '@tramvai/tokens-child-app';
|
|
6
|
-
import { ACTION_PAGE_RUNNER_TOKEN, CONTEXT_TOKEN, LOGGER_TOKEN, DISPATCHER_TOKEN, STORE_TOKEN, COMBINE_REDUCERS, ENV_MANAGER_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, CLEAR_CACHE_TOKEN, ENV_USED_TOKEN } from '@tramvai/tokens-common';
|
|
6
|
+
import { ACTION_PAGE_RUNNER_TOKEN, CONTEXT_TOKEN, LOGGER_TOKEN, DISPATCHER_TOKEN, STORE_TOKEN, DISPATCHER_CONTEXT_TOKEN, STORE_MIDDLEWARE, INITIAL_APP_STATE_TOKEN, COMBINE_REDUCERS, ENV_MANAGER_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, CLEAR_CACHE_TOKEN, ENV_USED_TOKEN } from '@tramvai/tokens-common';
|
|
7
7
|
import { RENDER_SLOTS, EXTEND_RENDER } from '@tramvai/tokens-render';
|
|
8
8
|
import { PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
|
|
9
9
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
10
|
-
import { Subscription, createEvent, createReducer } from '@tramvai/state';
|
|
10
|
+
import { Subscription, ChildDispatcherContext, createEvent, createReducer } from '@tramvai/state';
|
|
11
11
|
import React, { createContext, useContext, useMemo, useState, useEffect, createElement } from 'react';
|
|
12
12
|
import applyOrReturn from '@tinkoff/utils/function/applyOrReturn';
|
|
13
13
|
import { loadModule } from '@tinkoff/module-loader-client';
|
|
14
14
|
import noop from '@tinkoff/utils/function/noop';
|
|
15
15
|
import { useDi } from '@tramvai/react';
|
|
16
16
|
|
|
17
|
-
const getChildProviders$
|
|
17
|
+
const getChildProviders$2 = (appDi) => {
|
|
18
18
|
const context = appDi.get(CONTEXT_TOKEN);
|
|
19
19
|
return [
|
|
20
20
|
{
|
|
@@ -56,7 +56,7 @@ const getChildProviders$1 = (appDi) => {
|
|
|
56
56
|
];
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
const getChildProviders = (appDi) => {
|
|
59
|
+
const getChildProviders$1 = (appDi) => {
|
|
60
60
|
const logger = appDi.get(LOGGER_TOKEN);
|
|
61
61
|
return [
|
|
62
62
|
provide({
|
|
@@ -70,7 +70,7 @@ const getChildProviders = (appDi) => {
|
|
|
70
70
|
multi: true,
|
|
71
71
|
useValue: [],
|
|
72
72
|
}),
|
|
73
|
-
...getChildProviders$
|
|
73
|
+
...getChildProviders$2(appDi),
|
|
74
74
|
];
|
|
75
75
|
};
|
|
76
76
|
|
|
@@ -137,7 +137,8 @@ class SingletonDiManager {
|
|
|
137
137
|
},
|
|
138
138
|
], this.appDi);
|
|
139
139
|
const { modules = [], providers = [], actions = [] } = children;
|
|
140
|
-
|
|
140
|
+
// add providers on the Singleton Level to make it possible to reuse providers from the root-app Container
|
|
141
|
+
const childProviders = getChildProviders$1(this.appDi);
|
|
141
142
|
childProviders.forEach((provider) => {
|
|
142
143
|
di.register(provider);
|
|
143
144
|
});
|
|
@@ -171,6 +172,35 @@ class SingletonDiManager {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
const getChildProviders = (appDi) => {
|
|
176
|
+
const parentDispatcherContext = appDi.get(DISPATCHER_CONTEXT_TOKEN);
|
|
177
|
+
return [
|
|
178
|
+
provide({
|
|
179
|
+
provide: DISPATCHER_CONTEXT_TOKEN,
|
|
180
|
+
useFactory: ({ dispatcher, middlewares, initialState, parentAllowedStores }) => {
|
|
181
|
+
return new ChildDispatcherContext({
|
|
182
|
+
dispatcher,
|
|
183
|
+
// context will be set later by the CONTEXT_TOKEN
|
|
184
|
+
context: {},
|
|
185
|
+
initialState,
|
|
186
|
+
middlewares: flatten(middlewares || []),
|
|
187
|
+
parentDispatcherContext,
|
|
188
|
+
parentAllowedStores: flatten(parentAllowedStores || []),
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
deps: {
|
|
192
|
+
dispatcher: DISPATCHER_TOKEN,
|
|
193
|
+
middlewares: { token: STORE_MIDDLEWARE, optional: true },
|
|
194
|
+
initialState: { token: INITIAL_APP_STATE_TOKEN, optional: true },
|
|
195
|
+
parentAllowedStores: {
|
|
196
|
+
token: CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
197
|
+
optional: true,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
];
|
|
202
|
+
};
|
|
203
|
+
|
|
174
204
|
class DiManager {
|
|
175
205
|
constructor({ appDi, loader, singletonDiManager, }) {
|
|
176
206
|
this.cache = new Map();
|
|
@@ -201,7 +231,13 @@ class DiManager {
|
|
|
201
231
|
if (!singletonDi) {
|
|
202
232
|
return;
|
|
203
233
|
}
|
|
204
|
-
|
|
234
|
+
const di = new ChildContainer(singletonDi, this.appDi);
|
|
235
|
+
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
236
|
+
const childProviders = getChildProviders(this.appDi);
|
|
237
|
+
childProviders.forEach((provider) => {
|
|
238
|
+
di.register(provider);
|
|
239
|
+
});
|
|
240
|
+
return di;
|
|
205
241
|
}
|
|
206
242
|
}
|
|
207
243
|
|
package/lib/server.es.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { provide, COMMAND_LINE_RUNNER_TOKEN, walkOfModules, getModuleParameters, commandLineListTokens as commandLineListTokens$1, Module } from '@tramvai/core';
|
|
3
3
|
import { Container, ChildContainer, Scope, DI_TOKEN } from '@tinkoff/dippy';
|
|
4
|
-
import { commandLineListTokens, CHILD_APP_INTERNAL_ACTION_TOKEN, CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_DI_TOKEN, CHILD_APP_INTERNAL_ROOT_DI_BORROW_TOKEN, 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, CHILD_APP_INTERNAL_ROOT_STATE_SUBSCRIPTION_TOKEN, CHILD_APP_STATE_MANAGER_TOKEN, CHILD_APP_INTERNAL_RENDER_TOKEN } from '@tramvai/tokens-child-app';
|
|
4
|
+
import { commandLineListTokens, CHILD_APP_INTERNAL_ACTION_TOKEN, CHILD_APP_INTERNAL_CONFIG_TOKEN, IS_CHILD_APP_DI_TOKEN, CHILD_APP_INTERNAL_ROOT_DI_BORROW_TOKEN, CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN, 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, CHILD_APP_INTERNAL_ROOT_STATE_SUBSCRIPTION_TOKEN, CHILD_APP_STATE_MANAGER_TOKEN, CHILD_APP_INTERNAL_RENDER_TOKEN } from '@tramvai/tokens-child-app';
|
|
5
5
|
export * from '@tramvai/tokens-child-app';
|
|
6
|
-
import { ACTION_PAGE_RUNNER_TOKEN, LOGGER_TOKEN, DISPATCHER_TOKEN, STORE_TOKEN, CONTEXT_TOKEN, COMBINE_REDUCERS, ENV_MANAGER_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, CLEAR_CACHE_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
|
|
6
|
+
import { ACTION_PAGE_RUNNER_TOKEN, LOGGER_TOKEN, DISPATCHER_TOKEN, STORE_TOKEN, CONTEXT_TOKEN, DISPATCHER_CONTEXT_TOKEN, STORE_MIDDLEWARE, INITIAL_APP_STATE_TOKEN, COMBINE_REDUCERS, ENV_MANAGER_TOKEN, REGISTER_CLEAR_CACHE_TOKEN, CLEAR_CACHE_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
|
|
7
7
|
import { RENDER_SLOTS, EXTEND_RENDER, ResourceType, ResourceSlot, RESOURCES_REGISTRY } from '@tramvai/tokens-render';
|
|
8
8
|
import { PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
|
|
9
9
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
10
|
-
import { createEvent, createReducer } from '@tramvai/state';
|
|
10
|
+
import { ChildDispatcherContext, createEvent, createReducer } from '@tramvai/state';
|
|
11
11
|
import React, { createContext, useContext, useMemo, useState, useEffect, createElement } from 'react';
|
|
12
12
|
import applyOrReturn from '@tinkoff/utils/function/applyOrReturn';
|
|
13
13
|
import { combineValidators, isUrl, endsWith } from '@tinkoff/env-validators';
|
|
@@ -16,7 +16,7 @@ import { ServerLoader as ServerLoader$1 } from '@tinkoff/module-loader-server';
|
|
|
16
16
|
import noop from '@tinkoff/utils/function/noop';
|
|
17
17
|
import { useDi } from '@tramvai/react';
|
|
18
18
|
|
|
19
|
-
const getChildProviders$
|
|
19
|
+
const getChildProviders$2 = (appDi) => {
|
|
20
20
|
return [
|
|
21
21
|
provide({
|
|
22
22
|
provide: commandLineListTokens.resolvePageDeps,
|
|
@@ -34,7 +34,7 @@ const getChildProviders$1 = (appDi) => {
|
|
|
34
34
|
];
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const getChildProviders = (appDi) => {
|
|
37
|
+
const getChildProviders$1 = (appDi) => {
|
|
38
38
|
const logger = appDi.get(LOGGER_TOKEN);
|
|
39
39
|
return [
|
|
40
40
|
provide({
|
|
@@ -48,7 +48,7 @@ const getChildProviders = (appDi) => {
|
|
|
48
48
|
multi: true,
|
|
49
49
|
useValue: [],
|
|
50
50
|
}),
|
|
51
|
-
...getChildProviders$
|
|
51
|
+
...getChildProviders$2(),
|
|
52
52
|
];
|
|
53
53
|
};
|
|
54
54
|
|
|
@@ -115,7 +115,8 @@ class SingletonDiManager {
|
|
|
115
115
|
},
|
|
116
116
|
], this.appDi);
|
|
117
117
|
const { modules = [], providers = [], actions = [] } = children;
|
|
118
|
-
|
|
118
|
+
// add providers on the Singleton Level to make it possible to reuse providers from the root-app Container
|
|
119
|
+
const childProviders = getChildProviders$1(this.appDi);
|
|
119
120
|
childProviders.forEach((provider) => {
|
|
120
121
|
di.register(provider);
|
|
121
122
|
});
|
|
@@ -149,6 +150,35 @@ class SingletonDiManager {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
|
153
|
+
const getChildProviders = (appDi) => {
|
|
154
|
+
const parentDispatcherContext = appDi.get(DISPATCHER_CONTEXT_TOKEN);
|
|
155
|
+
return [
|
|
156
|
+
provide({
|
|
157
|
+
provide: DISPATCHER_CONTEXT_TOKEN,
|
|
158
|
+
useFactory: ({ dispatcher, middlewares, initialState, parentAllowedStores }) => {
|
|
159
|
+
return new ChildDispatcherContext({
|
|
160
|
+
dispatcher,
|
|
161
|
+
// context will be set later by the CONTEXT_TOKEN
|
|
162
|
+
context: {},
|
|
163
|
+
initialState,
|
|
164
|
+
middlewares: flatten(middlewares || []),
|
|
165
|
+
parentDispatcherContext,
|
|
166
|
+
parentAllowedStores: flatten(parentAllowedStores || []),
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
deps: {
|
|
170
|
+
dispatcher: DISPATCHER_TOKEN,
|
|
171
|
+
middlewares: { token: STORE_MIDDLEWARE, optional: true },
|
|
172
|
+
initialState: { token: INITIAL_APP_STATE_TOKEN, optional: true },
|
|
173
|
+
parentAllowedStores: {
|
|
174
|
+
token: CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
175
|
+
optional: true,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
];
|
|
180
|
+
};
|
|
181
|
+
|
|
152
182
|
class DiManager {
|
|
153
183
|
constructor({ appDi, loader, singletonDiManager, }) {
|
|
154
184
|
this.cache = new Map();
|
|
@@ -179,7 +209,13 @@ class DiManager {
|
|
|
179
209
|
if (!singletonDi) {
|
|
180
210
|
return;
|
|
181
211
|
}
|
|
182
|
-
|
|
212
|
+
const di = new ChildContainer(singletonDi, this.appDi);
|
|
213
|
+
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
214
|
+
const childProviders = getChildProviders(this.appDi);
|
|
215
|
+
childProviders.forEach((provider) => {
|
|
216
|
+
di.register(provider);
|
|
217
|
+
});
|
|
218
|
+
return di;
|
|
183
219
|
}
|
|
184
220
|
}
|
|
185
221
|
|
package/lib/server.js
CHANGED
|
@@ -26,7 +26,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
26
26
|
var applyOrReturn__default = /*#__PURE__*/_interopDefaultLegacy(applyOrReturn);
|
|
27
27
|
var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
|
|
28
28
|
|
|
29
|
-
const getChildProviders$
|
|
29
|
+
const getChildProviders$2 = (appDi) => {
|
|
30
30
|
return [
|
|
31
31
|
core.provide({
|
|
32
32
|
provide: tokensChildApp.commandLineListTokens.resolvePageDeps,
|
|
@@ -44,7 +44,7 @@ const getChildProviders$1 = (appDi) => {
|
|
|
44
44
|
];
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
const getChildProviders = (appDi) => {
|
|
47
|
+
const getChildProviders$1 = (appDi) => {
|
|
48
48
|
const logger = appDi.get(tokensCommon.LOGGER_TOKEN);
|
|
49
49
|
return [
|
|
50
50
|
core.provide({
|
|
@@ -58,7 +58,7 @@ const getChildProviders = (appDi) => {
|
|
|
58
58
|
multi: true,
|
|
59
59
|
useValue: [],
|
|
60
60
|
}),
|
|
61
|
-
...getChildProviders$
|
|
61
|
+
...getChildProviders$2(),
|
|
62
62
|
];
|
|
63
63
|
};
|
|
64
64
|
|
|
@@ -125,7 +125,8 @@ class SingletonDiManager {
|
|
|
125
125
|
},
|
|
126
126
|
], this.appDi);
|
|
127
127
|
const { modules = [], providers = [], actions = [] } = children;
|
|
128
|
-
|
|
128
|
+
// add providers on the Singleton Level to make it possible to reuse providers from the root-app Container
|
|
129
|
+
const childProviders = getChildProviders$1(this.appDi);
|
|
129
130
|
childProviders.forEach((provider) => {
|
|
130
131
|
di.register(provider);
|
|
131
132
|
});
|
|
@@ -159,6 +160,35 @@ class SingletonDiManager {
|
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
|
|
163
|
+
const getChildProviders = (appDi) => {
|
|
164
|
+
const parentDispatcherContext = appDi.get(tokensCommon.DISPATCHER_CONTEXT_TOKEN);
|
|
165
|
+
return [
|
|
166
|
+
core.provide({
|
|
167
|
+
provide: tokensCommon.DISPATCHER_CONTEXT_TOKEN,
|
|
168
|
+
useFactory: ({ dispatcher, middlewares, initialState, parentAllowedStores }) => {
|
|
169
|
+
return new state.ChildDispatcherContext({
|
|
170
|
+
dispatcher,
|
|
171
|
+
// context will be set later by the CONTEXT_TOKEN
|
|
172
|
+
context: {},
|
|
173
|
+
initialState,
|
|
174
|
+
middlewares: flatten__default["default"](middlewares || []),
|
|
175
|
+
parentDispatcherContext,
|
|
176
|
+
parentAllowedStores: flatten__default["default"](parentAllowedStores || []),
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
deps: {
|
|
180
|
+
dispatcher: tokensCommon.DISPATCHER_TOKEN,
|
|
181
|
+
middlewares: { token: tokensCommon.STORE_MIDDLEWARE, optional: true },
|
|
182
|
+
initialState: { token: tokensCommon.INITIAL_APP_STATE_TOKEN, optional: true },
|
|
183
|
+
parentAllowedStores: {
|
|
184
|
+
token: tokensChildApp.CHILD_APP_INTERNAL_ROOT_STATE_ALLOWED_STORE_TOKEN,
|
|
185
|
+
optional: true,
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
}),
|
|
189
|
+
];
|
|
190
|
+
};
|
|
191
|
+
|
|
162
192
|
class DiManager {
|
|
163
193
|
constructor({ appDi, loader, singletonDiManager, }) {
|
|
164
194
|
this.cache = new Map();
|
|
@@ -189,7 +219,13 @@ class DiManager {
|
|
|
189
219
|
if (!singletonDi) {
|
|
190
220
|
return;
|
|
191
221
|
}
|
|
192
|
-
|
|
222
|
+
const di = new dippy.ChildContainer(singletonDi, this.appDi);
|
|
223
|
+
// add providers on the Request Level to make it possible to reuse providers from the root-app ChildContainer
|
|
224
|
+
const childProviders = getChildProviders(this.appDi);
|
|
225
|
+
childProviders.forEach((provider) => {
|
|
226
|
+
di.register(provider);
|
|
227
|
+
});
|
|
228
|
+
return di;
|
|
193
229
|
}
|
|
194
230
|
}
|
|
195
231
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-child-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.73.0",
|
|
4
4
|
"description": "Module for child apps",
|
|
5
5
|
"browser": {
|
|
6
6
|
"./lib/server.js": "./lib/browser.js",
|
|
7
7
|
"./lib/server/child/singletonProviders.js": "./lib/browser/child/singletonProviders.js",
|
|
8
|
+
"./lib/server/child/providers.js": "./lib/browser/child/providers.js",
|
|
8
9
|
"./lib/server.es.js": "./lib/server.browser.js"
|
|
9
10
|
},
|
|
10
11
|
"main": "lib/server.js",
|
|
@@ -30,20 +31,20 @@
|
|
|
30
31
|
"@tinkoff/env-validators": "0.0.3",
|
|
31
32
|
"@tinkoff/module-loader-client": "0.3.25",
|
|
32
33
|
"@tinkoff/module-loader-server": "0.4.41",
|
|
33
|
-
"@tramvai/child-app-core": "1.
|
|
34
|
+
"@tramvai/child-app-core": "1.73.0",
|
|
34
35
|
"@tramvai/safe-strings": "0.4.3",
|
|
35
|
-
"@tramvai/tokens-child-app": "1.
|
|
36
|
+
"@tramvai/tokens-child-app": "1.73.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {},
|
|
38
39
|
"peerDependencies": {
|
|
39
40
|
"@tinkoff/dippy": "0.7.38",
|
|
40
41
|
"@tinkoff/utils": "^2.1.2",
|
|
41
|
-
"@tramvai/core": "1.
|
|
42
|
-
"@tramvai/state": "1.
|
|
43
|
-
"@tramvai/react": "1.
|
|
44
|
-
"@tramvai/tokens-common": "1.
|
|
45
|
-
"@tramvai/tokens-render": "1.
|
|
46
|
-
"@tramvai/tokens-router": "1.
|
|
42
|
+
"@tramvai/core": "1.73.0",
|
|
43
|
+
"@tramvai/state": "1.73.0",
|
|
44
|
+
"@tramvai/react": "1.73.0",
|
|
45
|
+
"@tramvai/tokens-common": "1.73.0",
|
|
46
|
+
"@tramvai/tokens-render": "1.73.0",
|
|
47
|
+
"@tramvai/tokens-router": "1.73.0",
|
|
47
48
|
"react": ">=16.8.0",
|
|
48
49
|
"react-dom": ">=16.8.0",
|
|
49
50
|
"object-assign": "^4.1.1",
|