@lomray/react-mobx-manager 1.0.0-beta.7 → 1.0.0-beta.9
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 +18 -0
- package/lib/context.d.ts +15 -1
- package/lib/context.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/manager.d.ts +37 -11
- package/lib/manager.js +1 -1
- package/lib/on-change-listener.d.ts +1 -1
- package/lib/storages/async-storage.d.ts +42 -0
- package/lib/storages/async-storage.js +1 -0
- package/lib/storages/local-storage.d.ts +1 -1
- package/lib/{types-4732bbd2.d.ts → types-5b099751.d.ts} +11 -2
- package/lib/wakeup.d.ts +1 -1
- package/lib/with-stores.d.ts +2 -2
- package/lib/with-stores.js +1 -1
- package/package.json +5 -7
- package/tsconfig.checks.json +6 -0
package/README.md
CHANGED
|
@@ -28,6 +28,24 @@ The React-mobx-manager package is distributed using [npm](https://www.npmjs.com/
|
|
|
28
28
|
npm i --save @lomray/react-mobx-manager
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
Configure your bundler for keep classnames and function names in production OR use `id` for each store:
|
|
32
|
+
|
|
33
|
+
**React:** (craco or webpack config, terser options)
|
|
34
|
+
```bash
|
|
35
|
+
terserOptions.keep_classnames = true;
|
|
36
|
+
terserOptions.keep_fnames = true;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**React Native:** (metro bundler config)
|
|
40
|
+
```
|
|
41
|
+
transformer: {
|
|
42
|
+
minifierConfig: {
|
|
43
|
+
keep_classnames: true,
|
|
44
|
+
keep_fnames: true,
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
31
49
|
Import `Manager, StoreManagerProvider` from `@lomray/react-mobx-manager` into your index file after wrap `<App/>` with `<StoreManagerProvider/>`
|
|
32
50
|
|
|
33
51
|
```jsx
|
package/lib/context.d.ts
CHANGED
|
@@ -8,14 +8,28 @@ interface IStoreManagerProvider {
|
|
|
8
8
|
fallback?: ReactElement;
|
|
9
9
|
children?: React.ReactNode;
|
|
10
10
|
}
|
|
11
|
+
interface IStoreManagerParentProvider {
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
parentId: string;
|
|
14
|
+
}
|
|
11
15
|
/**
|
|
12
16
|
* Mobx store manager context
|
|
13
17
|
*/
|
|
14
18
|
declare const StoreManagerContext: React.Context<Manager>;
|
|
19
|
+
/**
|
|
20
|
+
* To spread relationships
|
|
21
|
+
*/
|
|
22
|
+
declare const StoreManagerParentContext: React.Context<IStoreManagerParentProvider>;
|
|
23
|
+
/**
|
|
24
|
+
* Mobx store manager parent provider
|
|
25
|
+
* @constructor
|
|
26
|
+
*/
|
|
27
|
+
declare const StoreManagerParentProvider: FC<Omit<IStoreManagerParentProvider, 'contextId'>>;
|
|
15
28
|
/**
|
|
16
29
|
* Mobx store manager provider
|
|
17
30
|
* @constructor
|
|
18
31
|
*/
|
|
19
32
|
declare const StoreManagerProvider: FC<IStoreManagerProvider>;
|
|
20
33
|
declare const useStoreManagerContext: () => Manager;
|
|
21
|
-
|
|
34
|
+
declare const useStoreManagerParentContext: () => Omit<IStoreManagerParentProvider, 'children'>;
|
|
35
|
+
export { StoreManagerProvider, StoreManagerContext, StoreManagerParentContext, useStoreManagerContext, StoreManagerParentProvider, useStoreManagerParentContext };
|
package/lib/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e);const a=r.default.createContext({});exports.StoreManagerContext=a,exports.StoreManagerProvider=({children:t,storeManager:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e);const a=r.default.createContext({}),n=r.default.createContext({parentId:"root"}),o=({children:t,parentId:a})=>{const o=e.useMemo((()=>({parentId:a})),[a]);return r.default.createElement(n.Provider,{value:o,children:t})};exports.StoreManagerContext=a,exports.StoreManagerParentContext=n,exports.StoreManagerParentProvider=o,exports.StoreManagerProvider=({children:t,storeManager:n,fallback:u,shouldInit:s=!1})=>{const[d,l]=e.useState(!s);return e.useEffect((()=>{s&&n.init().then((()=>l(!0))).catch((e=>{console.error("Failed initialized store manager: ",e)}))}),[s,n]),r.default.createElement(a.Provider,{value:n},r.default.createElement(o,{parentId:"root"},d?t:u||t))},exports.useStoreManagerContext=()=>e.useContext(a),exports.useStoreManagerParentContext=()=>e.useContext(n);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export * from "./types-
|
|
1
|
+
export * from "./types-5b099751";
|
|
2
2
|
export * from "./context";
|
|
3
3
|
export { default as Manager } from "./manager";
|
|
4
4
|
export { default as onChangeListener } from "./on-change-listener";
|
|
5
5
|
export { default as wakeup } from "./wakeup";
|
|
6
6
|
export { default as withStores } from "./with-stores";
|
|
7
7
|
export { default as MobxLocalStorage } from "./storages/local-storage";
|
|
8
|
+
export { default as MobxAsyncStorage } from "./storages/async-storage";
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./context.js"),r=require("./manager.js"),t=require("./on-change-listener.js"),o=require("./wakeup.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./context.js"),r=require("./manager.js"),t=require("./on-change-listener.js"),o=require("./wakeup.js"),a=require("./with-stores.js"),s=require("./storages/local-storage.js"),n=require("./storages/async-storage.js");exports.StoreManagerContext=e.StoreManagerContext,exports.StoreManagerParentContext=e.StoreManagerParentContext,exports.StoreManagerParentProvider=e.StoreManagerParentProvider,exports.StoreManagerProvider=e.StoreManagerProvider,exports.useStoreManagerContext=e.useStoreManagerContext,exports.useStoreManagerParentContext=e.useStoreManagerParentContext,exports.Manager=r,exports.onChangeListener=t,exports.wakeup=o,exports.withStores=a,exports.MobxLocalStorage=s,exports.MobxAsyncStorage=n;
|
package/lib/manager.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IConstructableStore, IManagerParams, IStorage, IStore, TStoreDefinition, IManagerOptions, TStores, TInitStore } from "./types-
|
|
1
|
+
import { IConstructableStore, IManagerParams, IStorage, IStore, TStoreDefinition, IManagerOptions, TStores, IStoreLifecycle, TInitStore, IStoreParams } from "./types-5b099751";
|
|
2
2
|
/**
|
|
3
3
|
* Mobx stores manager
|
|
4
4
|
*/
|
|
@@ -10,12 +10,15 @@ declare class Manager {
|
|
|
10
10
|
/**
|
|
11
11
|
* Created stores
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
protected readonly stores: Map<string, TInitStore<IStore>>;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
15
|
+
* Relations between stores
|
|
16
|
+
* @protected
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
protected readonly storesRelations: Map<string, {
|
|
19
|
+
ids: Set<string>;
|
|
20
|
+
parentId: string | null;
|
|
21
|
+
}>;
|
|
19
22
|
/**
|
|
20
23
|
* Save persisted stores identities
|
|
21
24
|
* @private
|
|
@@ -28,7 +31,6 @@ declare class Manager {
|
|
|
28
31
|
protected readonly initState: Record<string, any>;
|
|
29
32
|
/**
|
|
30
33
|
* Storage for persisted stores
|
|
31
|
-
* @private
|
|
32
34
|
*/
|
|
33
35
|
readonly storage: IStorage | undefined;
|
|
34
36
|
/**
|
|
@@ -43,7 +45,6 @@ declare class Manager {
|
|
|
43
45
|
protected readonly storesParams: IManagerParams['storesParams'];
|
|
44
46
|
/**
|
|
45
47
|
* Manager options
|
|
46
|
-
* @private
|
|
47
48
|
*/
|
|
48
49
|
readonly options: IManagerOptions;
|
|
49
50
|
/**
|
|
@@ -75,14 +76,30 @@ declare class Manager {
|
|
|
75
76
|
* Get store identity
|
|
76
77
|
* @protected
|
|
77
78
|
*/
|
|
78
|
-
protected
|
|
79
|
+
protected getStoreId<T>(store: IConstructableStore<T> | TInitStore, params?: IStoreParams): string;
|
|
80
|
+
/**
|
|
81
|
+
* Generate new context id
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
* Generate new context id
|
|
85
|
+
*/
|
|
86
|
+
createContextId(id?: string): string;
|
|
79
87
|
/**
|
|
80
88
|
* Get exist store
|
|
81
89
|
*/
|
|
82
90
|
/**
|
|
83
91
|
* Get exist store
|
|
84
92
|
*/
|
|
85
|
-
getStore<T>(store: IConstructableStore<T>,
|
|
93
|
+
getStore<T>(store: IConstructableStore<T>, params?: IStoreParams): T | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Lookup store
|
|
96
|
+
* @protected
|
|
97
|
+
*/
|
|
98
|
+
/**
|
|
99
|
+
* Lookup store
|
|
100
|
+
* @protected
|
|
101
|
+
*/
|
|
102
|
+
protected lookupStore<T>(id: string, params: IStoreParams): TInitStore<T> | undefined;
|
|
86
103
|
/**
|
|
87
104
|
* Create new store instance
|
|
88
105
|
* @protected
|
|
@@ -91,14 +108,23 @@ declare class Manager {
|
|
|
91
108
|
* Create new store instance
|
|
92
109
|
* @protected
|
|
93
110
|
*/
|
|
94
|
-
protected createStore<T>(store: IConstructableStore<T>,
|
|
111
|
+
protected createStore<T>(store: IConstructableStore<T>, params: Omit<Required<IStoreParams>, 'key'>): T;
|
|
95
112
|
/**
|
|
96
113
|
* Create stores for component
|
|
97
114
|
*/
|
|
98
115
|
/**
|
|
99
116
|
* Create stores for component
|
|
100
117
|
*/
|
|
101
|
-
createStores(map: [string, TStoreDefinition][]): TStores;
|
|
118
|
+
createStores(map: [string, TStoreDefinition][], parentId: string, contextId: string): TStores;
|
|
119
|
+
/**
|
|
120
|
+
* Prepare store before usage
|
|
121
|
+
* @protected
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* Prepare store before usage
|
|
125
|
+
* @protected
|
|
126
|
+
*/
|
|
127
|
+
protected prepareStore(store: TStores[string]): Required<IStoreLifecycle>['onDestroy'][];
|
|
102
128
|
/**
|
|
103
129
|
* Mount stores to component
|
|
104
130
|
*/
|
package/lib/manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("mobx"),t=require("./on-change-listener.js"),s=require("./wakeup.js");class r{constructor({initState:e,storesParams:t,storage:s,options:i}={}){Object.defineProperty(this,"stores",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"
|
|
1
|
+
"use strict";var e=require("mobx"),t=require("./on-change-listener.js"),s=require("./wakeup.js");class r{constructor({initState:e,storesParams:t,storage:s,options:i}={}){Object.defineProperty(this,"stores",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"storesRelations",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"initState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"persistData",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"storesParams",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:{shouldDisablePersist:!1,shouldRemoveInitState:!0,isSSR:!1}}),this.initState=e||{},this.storesParams=t||{},this.storage=s,Object.assign(this.options,i||{}),r.instance=this}async init(){return this.storage&&(this.persistData=await this.storage.get()||{}),this}static get(){if(!r.instance)throw new Error("Store manager is not initialized.");return r.instance}getStoreId(e,t={}){const{id:s,contextId:r,key:i}=t;if(s)return s;if(e.id)return e.id;let o=e.name||e.constructor.name;return e.isSingleton?o:(o=`${o}--${r}`,i?`${o}--${i}`:o)}createContextId(e){return`ctx${e||this.storesRelations.size+1}`}getStore(e,t={}){const s=this.getStoreId(e,t);return this.stores.has(s)?this.stores.get(s):e.isSingleton?this.createStore(e,{id:s,contextId:"singleton",parentId:"root"}):this.lookupStore(s,t)}lookupStore(e,t){var s,r;const{contextId:i,parentId:o}=t,n=null===(s=e.split("--"))||void 0===s?void 0:s[0],{ids:a,parentId:l}=null!==(r=this.storesRelations.get(i))&&void 0!==r?r:{ids:new Set,parentId:o},d=[...a].filter((e=>e.startsWith(`${n}--`)));if(1===d.length)return this.stores.get(d[0]);if(d.length>1)console.error("Parent context has multiple stores with the same id, please pass key to getStore function.");else if(l&&"root"!==l)return this.lookupStore(e,{contextId:l})}createStore(e,t){var s,i;const{isSSR:o}=this.options,{id:n,contextId:a,parentId:l}=t;if((e.isSingleton||o)&&this.stores.has(n))return this.stores.get(n);const d=new e({storeManager:this,getStore:(e,t={contextId:a,parentId:l})=>this.getStore(e,t),...this.storesParams});d.id=n,d.isSingleton=e.isSingleton,d.contextId=e.isSingleton?"singleton":a,d.parentId=e.isSingleton||!l||l===a?"root":l;const c=this.initState[n],u=this.persistData[n];return c&&Object.assign(d,c),"wakeup"in d&&r.persistedStores.has(n)&&(null===(s=d.wakeup)||void 0===s||s.call(d,d,{initState:c,persistedState:u})),null===(i=d.init)||void 0===i||i.call(d),(d.isSingleton||o)&&this.prepareStore(d),d}createStores(e,t,s){return e.reduce(((e,[r,i])=>{const[o,n]="store"in i?[i.store,i.id]:[i,this.getStoreId(i,{key:r,contextId:s})];return{...e,[r]:this.createStore(o,{id:n,contextId:s,parentId:t})}}),{})}prepareStore(e){const{shouldRemoveInitState:t}=this.options,s=e.id,i=e.contextId,o=[];this.storesRelations.has(i)||this.storesRelations.set(i,{ids:new Set,parentId:e.parentId&&e.parentId!==i?e.parentId:"root"});const{ids:n}=this.storesRelations.get(i);return r.persistedStores.has(s)&&"addOnChangeListener"in e&&o.push(e.addOnChangeListener(e,this)),t&&this.initState[s]&&delete this.initState[s],this.stores.has(s)||(this.stores.set(s,e),n.add(s)),o}mountStores(e){const t=[];return Object.values(e).forEach((e=>{var s;if(t.push(...this.prepareStore(e)),"onMount"in e){const r=null===(s=e.onMount)||void 0===s?void 0:s.call(e);"function"==typeof r&&t.push(r)}"onDestroy"in e&&t.push((()=>{var t;return null===(t=e.onDestroy)||void 0===t?void 0:t.call(e)}))})),()=>{t.forEach((e=>e())),Object.values(e).forEach((e=>{var t;const s=e.id;if(!e.isSingleton){const{ids:r}=null!==(t=this.storesRelations.get(e.contextId))&&void 0!==t?t:{ids:new Set};this.stores.delete(s),r.delete(s),r.size||this.storesRelations.delete(e.contextId)}}))}}toJSON(){var e,t;const s={};for(const[i,o]of this.stores.entries())s[i]=null!==(t=null===(e=o.toJSON)||void 0===e?void 0:e.call(o))&&void 0!==t?t:r.getObservableProps(o);return s}toPersistedJSON(){var e,t;const s={};for(const i of r.persistedStores){const o=this.stores.get(i);o&&(s[i]=null!==(t=null===(e=o.toJSON)||void 0===e?void 0:e.call(o))&&void 0!==t?t:r.getObservableProps(o))}return s}static getObservableProps(t){const s=e.toJS(t);return Object.entries(s).reduce(((s,[r,i])=>({...s,...e.isObservableProp(t,r)?{[r]:i}:{}})),{})}static persistStore(e,i){return r.persistedStores.has(i)?(console.error(`Duplicate serializable store key: ${i}`),e):(r.persistedStores.add(i),e.id=i,"wakeup"in e.prototype||(e.prototype.wakeup=s),"addOnChangeListener"in e.prototype||(e.prototype.addOnChangeListener=t),e)}}Object.defineProperty(r,"persistedStores",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),module.exports=r;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IStorage } from "../types-5b099751";
|
|
2
|
+
interface IAsyncStorage {
|
|
3
|
+
getItem: (key: string) => Promise<string | null>;
|
|
4
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
5
|
+
removeItem: (key: string) => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
declare class AsyncStorage implements IStorage {
|
|
8
|
+
globalKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* @protected
|
|
11
|
+
*/
|
|
12
|
+
protected storage: IAsyncStorage;
|
|
13
|
+
/**
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @constructor
|
|
18
|
+
*/
|
|
19
|
+
constructor(AsyncStoragePackage: IAsyncStorage);
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
get(): Promise<Record<string, any> | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
flush(): Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
set(value: Record<string, any> | undefined): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export { AsyncStorage as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";module.exports=class{constructor(e){Object.defineProperty(this,"globalKey",{enumerable:!0,configurable:!0,writable:!0,value:"stores"}),Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.storage=e}async get(){try{return JSON.parse(await this.storage.getItem(this.globalKey)||"{}")}catch(e){return{}}}flush(){return this.storage.removeItem(this.globalKey)}set(e){return this.storage.setItem(this.globalKey,JSON.stringify(e||"{}"))}};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Manager from "./manager";
|
|
2
2
|
interface IConstructorParams {
|
|
3
3
|
storeManager: Manager;
|
|
4
|
+
getStore: <T>(store: IConstructableStore<T>, params?: Partial<IStoreParams>) => T | undefined;
|
|
4
5
|
}
|
|
5
6
|
interface IStoreLifecycle {
|
|
6
7
|
onDestroy?: () => void;
|
|
@@ -8,6 +9,8 @@ interface IStoreLifecycle {
|
|
|
8
9
|
}
|
|
9
10
|
interface IStore extends IStoreLifecycle {
|
|
10
11
|
id?: string;
|
|
12
|
+
contextId?: string;
|
|
13
|
+
parentId?: string;
|
|
11
14
|
isSingleton?: boolean;
|
|
12
15
|
init?: () => void;
|
|
13
16
|
toJSON?: () => Record<string, any>;
|
|
@@ -29,7 +32,7 @@ type TStoreDefinition<TSto extends IStore | IStorePersisted = any> = IConstructa
|
|
|
29
32
|
} & IStoreConfig);
|
|
30
33
|
type TMapStores = Record<string, TStoreDefinition>;
|
|
31
34
|
interface IManagerParams {
|
|
32
|
-
storesParams?: Omit<IConstructorParams, 'storeManager'>;
|
|
35
|
+
storesParams?: Omit<IConstructorParams, 'storeManager' | 'getStore'>;
|
|
33
36
|
storage?: IStorage;
|
|
34
37
|
options?: IManagerOptions;
|
|
35
38
|
initState?: Record<string, any>;
|
|
@@ -63,4 +66,10 @@ type ClassReturnType<T> = T extends new (...args: any) => infer R ? R : T extend
|
|
|
63
66
|
type StoresType<TSt> = {
|
|
64
67
|
[keys in keyof TSt]: ClassReturnType<TSt[keys]>;
|
|
65
68
|
};
|
|
66
|
-
|
|
69
|
+
interface IStoreParams {
|
|
70
|
+
id?: string;
|
|
71
|
+
key?: string;
|
|
72
|
+
contextId?: string;
|
|
73
|
+
parentId?: string;
|
|
74
|
+
}
|
|
75
|
+
export { IConstructorParams, IStoreLifecycle, IStore, IStorePersisted, TInitStore, IConstructableStore, IStoreConfig, TStoreDefinition, TMapStores, IManagerParams, TWakeup, IStorage, IManagerOptions, TStores, ClassReturnType, StoresType, IStoreParams };
|
package/lib/wakeup.d.ts
CHANGED
package/lib/with-stores.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { TMapStores } from "./types-
|
|
2
|
+
import { TMapStores } from "./types-5b099751";
|
|
3
3
|
/**
|
|
4
4
|
* Make component observable and pass stores as props
|
|
5
5
|
*/
|
|
6
|
-
declare const withStores: <T extends Record<string, any>, TS extends TMapStores>(Component: FC<T>, stores: TS) => FC<Omit<T, keyof TS>>;
|
|
6
|
+
declare const withStores: <T extends Record<string, any>, TS extends TMapStores>(Component: FC<T>, stores: TS, customContextId?: string) => FC<Omit<T, keyof TS>>;
|
|
7
7
|
export { withStores as default };
|
package/lib/with-stores.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("hoist-non-react-statics"),t=require("mobx-react-lite"),r=require("react"),a=require("./context.js");function
|
|
1
|
+
"use strict";var e=require("hoist-non-react-statics"),t=require("mobx-react-lite"),r=require("react"),a=require("./context.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),u=n(r);module.exports=(e,n,s)=>{const c=t.observer(e),d=s||e.contextId,i=({...e})=>{var t;const o=a.useStoreManagerContext(),{parentId:s}=a.useStoreManagerParentContext(),i=null===(t=u.default.useId)||void 0===t?void 0:t.call(u.default),[{contextId:l,initStores:f}]=r.useState((()=>{const e=o.createContextId(d||i);return{contextId:e,initStores:o.createStores(Object.entries(n),s,e)}}));return r.useEffect((()=>o.mountStores(f)),[f,o]),u.default.createElement(a.StoreManagerParentProvider,{parentId:l},u.default.createElement(c,{...f,...e}))};return o.default(i,e),i.displayName=`Mobx(${e.displayName||e.name})`,i};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lomray/react-mobx-manager",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "This package provides Mobx stores manager for react.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -33,11 +33,9 @@
|
|
|
33
33
|
"build": "rollup -c",
|
|
34
34
|
"build:dev": "rollup -c --environment BUILD:development",
|
|
35
35
|
"build:watch": "rollup -c -w --environment BUILD:development",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"lint:format": "eslint --fix --ext '.ts,.tsx' 'src/**/*.{ts,tsx,*.ts,*tsx}'",
|
|
40
|
-
"ts:check": "tsc --project ./tsconfig.json --skipLibCheck --noemit",
|
|
36
|
+
"lint:check": "eslint --ext \".ts,.tsx\" \"src/**/*.{ts,tsx,*.ts,*tsx}\"",
|
|
37
|
+
"lint:format": "eslint --fix --ext \".ts,.tsx\" \"src/**/*.{ts,tsx,*.ts,*tsx}\"",
|
|
38
|
+
"ts:check": "tsc --project ./tsconfig.checks.json --skipLibCheck --noemit",
|
|
41
39
|
"prepare": "husky install"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
@@ -54,7 +52,7 @@
|
|
|
54
52
|
"husky": "^8.0.1",
|
|
55
53
|
"lint-staged": "^13.0.3",
|
|
56
54
|
"prettier": "^2.7.1",
|
|
57
|
-
"rollup": "^2.79.
|
|
55
|
+
"rollup": "^2.79.1",
|
|
58
56
|
"rollup-plugin-terser": "^7.0.2",
|
|
59
57
|
"rollup-plugin-ts": "^3.0.2",
|
|
60
58
|
"semantic-release": "^19.0.5",
|