@tramvai/state 3.37.7 → 3.37.10

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,4 +1,4 @@
1
- import type { DispatcherContext as DispatcherContextInterface } from '@tramvai/types-actions-state-context';
1
+ import type { DispatcherContext as DispatcherContextInterface, Reducer } from '@tramvai/types-actions-state-context';
2
2
  import type { Dispatcher } from './dispatcher';
3
3
  import type { StoreClass } from '../typings';
4
4
  import type { Middleware } from './dispatcher.h';
@@ -27,6 +27,8 @@ export declare class ChildDispatcherContext<TContext> extends DispatcherContext<
27
27
  store: T | string;
28
28
  optional: true;
29
29
  }): InstanceType<T> | null;
30
+ registerStore(store: Reducer<any>): void;
31
+ _getParentAllowedStore(storeName: string): InstanceType<StoreClass> | null;
30
32
  }
31
33
  export {};
32
34
  //# sourceMappingURL=childDispatcherContext.d.ts.map
@@ -28,19 +28,35 @@ class ChildDispatcherContext extends DispatcherContext {
28
28
  return super.getStore(storeClass);
29
29
  }
30
30
  if (this.allowedParentStores.has(storeName)) {
31
- // use just storeName to prevent store initialization on the root-app side
32
- const storeInstance = this.parentDispatcherContext.getStore({
33
- store: storeName,
34
- optional: true,
35
- });
36
- if (!storeInstance) {
37
- return null;
38
- }
39
- this.storeSubscribe(storeName, storeInstance);
40
- return storeInstance;
31
+ return this._getParentAllowedStore(storeName);
41
32
  }
42
33
  return super.getStore(storeClass);
43
34
  }
35
+ // prevent parent allowed store registration in current Child App dispatcher
36
+ registerStore(store) {
37
+ const { storeName } = store;
38
+ if (this.dispatcher.stores[storeName]) {
39
+ super.registerStore(store);
40
+ return;
41
+ }
42
+ if (this.allowedParentStores.has(storeName)) {
43
+ this._getParentAllowedStore(storeName);
44
+ return;
45
+ }
46
+ super.registerStore(store);
47
+ }
48
+ _getParentAllowedStore(storeName) {
49
+ // use just storeName to prevent store initialization on the root-app side
50
+ const storeInstance = this.parentDispatcherContext.getStore({
51
+ store: storeName,
52
+ optional: true,
53
+ });
54
+ if (!storeInstance) {
55
+ return null;
56
+ }
57
+ this.storeSubscribe(storeName, storeInstance);
58
+ return storeInstance;
59
+ }
44
60
  }
45
61
 
46
62
  export { ChildDispatcherContext };
@@ -32,19 +32,35 @@ class ChildDispatcherContext extends dispatcherContext.DispatcherContext {
32
32
  return super.getStore(storeClass);
33
33
  }
34
34
  if (this.allowedParentStores.has(storeName)) {
35
- // use just storeName to prevent store initialization on the root-app side
36
- const storeInstance = this.parentDispatcherContext.getStore({
37
- store: storeName,
38
- optional: true,
39
- });
40
- if (!storeInstance) {
41
- return null;
42
- }
43
- this.storeSubscribe(storeName, storeInstance);
44
- return storeInstance;
35
+ return this._getParentAllowedStore(storeName);
45
36
  }
46
37
  return super.getStore(storeClass);
47
38
  }
39
+ // prevent parent allowed store registration in current Child App dispatcher
40
+ registerStore(store) {
41
+ const { storeName } = store;
42
+ if (this.dispatcher.stores[storeName]) {
43
+ super.registerStore(store);
44
+ return;
45
+ }
46
+ if (this.allowedParentStores.has(storeName)) {
47
+ this._getParentAllowedStore(storeName);
48
+ return;
49
+ }
50
+ super.registerStore(store);
51
+ }
52
+ _getParentAllowedStore(storeName) {
53
+ // use just storeName to prevent store initialization on the root-app side
54
+ const storeInstance = this.parentDispatcherContext.getStore({
55
+ store: storeName,
56
+ optional: true,
57
+ });
58
+ if (!storeInstance) {
59
+ return null;
60
+ }
61
+ this.storeSubscribe(storeName, storeInstance);
62
+ return storeInstance;
63
+ }
48
64
  }
49
65
 
50
66
  exports.ChildDispatcherContext = ChildDispatcherContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/state",
3
- "version": "3.37.7",
3
+ "version": "3.37.10",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "@tinkoff/react-hooks": "0.2.1",
21
21
  "@tinkoff/utils": "^2.1.2",
22
- "@tramvai/types-actions-state-context": "3.37.7",
22
+ "@tramvai/types-actions-state-context": "3.37.10",
23
23
  "@types/hoist-non-react-statics": "^3.3.1",
24
24
  "invariant": "^2.2.4",
25
25
  "react-is": ">=17",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@reatom/core": "^1.1.5",
37
- "@tramvai/core": "3.37.7",
37
+ "@tramvai/core": "3.37.10",
38
38
  "@types/invariant": "^2.2.31",
39
39
  "@types/react-is": "^17.0.0",
40
40
  "@types/use-sync-external-store": "^0.0.3",