@lomray/react-mobx-manager 2.0.0 → 2.0.1-beta.1
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/context.d.ts +1 -1
- package/lib/events.d.ts +4 -5
- package/lib/events.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/manager.d.ts +1 -1
- package/lib/manager.js +1 -1
- package/lib/on-change-listener.d.ts +1 -1
- package/lib/storages/async-storage.d.ts +1 -1
- package/lib/storages/local-storage.d.ts +1 -1
- package/lib/suspense-query.d.ts +1 -1
- package/lib/{types-a8f9023c.d.ts → types-199a1271.d.ts} +16 -1
- package/lib/wakeup.d.ts +1 -1
- package/lib/with-stores.d.ts +1 -1
- package/package.json +4 -4
- package/typing/@lomray/event-manager.d.ts +5 -0
package/lib/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { FC, ReactElement } from "react";
|
|
4
4
|
import Manager from "./manager.js";
|
|
5
|
-
import { TStores } from "./types-
|
|
5
|
+
import { TStores } from "./types-199a1271.js";
|
|
6
6
|
interface IStoreManagerProvider {
|
|
7
7
|
storeManager: Manager;
|
|
8
8
|
shouldInit?: boolean;
|
package/lib/events.d.ts
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Store manager events
|
|
3
3
|
*/
|
|
4
4
|
declare enum Events {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
UNMOUNT_STORE = "unmount-store"
|
|
5
|
+
CREATE_STORE = "mobx-manager:store-create",
|
|
6
|
+
MOUNT_STORE = "mobx-manager:store-mount",
|
|
7
|
+
UNMOUNT_STORE = "mobx-manager:store-unmount",
|
|
8
|
+
DELETE_STORE = "mobx-manager:store-delete"
|
|
10
9
|
}
|
|
11
10
|
export { Events as default };
|
package/lib/events.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e;!function(e){e.
|
|
1
|
+
"use strict";var e;!function(e){e.CREATE_STORE="mobx-manager:store-create",e.MOUNT_STORE="mobx-manager:store-mount",e.UNMOUNT_STORE="mobx-manager:store-unmount",e.DELETE_STORE="mobx-manager:store-delete"}(e||(e={}));var o=e;module.exports=o;
|
package/lib/index.d.ts
CHANGED
package/lib/manager.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import StoreStatus from "./store-status.js";
|
|
2
|
-
import { IConstructableStore, IManagerOptions, IManagerParams, IStorage, IStore, IStoreParams, TInitStore, TStoreDefinition, TStores } from "./types-
|
|
2
|
+
import { IConstructableStore, IManagerOptions, IManagerParams, IStorage, IStore, IStoreParams, TInitStore, TStoreDefinition, TStores } from "./types-199a1271.js";
|
|
3
3
|
/**
|
|
4
4
|
* Mobx stores manager
|
|
5
5
|
*/
|
package/lib/manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@lomray/event-manager"),t=require("mobx"),s=require("./events.js"),r=require("./on-change-listener.js"),o=require("./store-status.js"),i=require("./wakeup.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=n(e);class l{constructor({initState:e,storesParams:t,storage:s,options:r}={}){if(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}}),Object.defineProperty(this,"suspenseRelations",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"pushInitState",{enumerable:!0,configurable:!0,writable:!0,value:(e={})=>{for(const[t,s]of Object.entries(e))this.initState[t]=s}}),this.initState=e||{},this.storesParams=t||{},this.storage=s,Object.assign(this.options,r||{}),l.instance=this,"undefined"!=typeof window){const e=window.mbxM;window.mbxM={push:this.pushInitState},(Array.isArray(e)?e:[]).forEach(this.pushInitState)}}async init(){return this.storage&&(this.persistData=await this.storage.get()||{}),this}static get(){if(!l.instance)throw new Error("Store manager is not initialized.");return l.instance}getStores(){return this.stores}getStoresRelations(){return this.storesRelations}getSuspenseRelations(){return this.suspenseRelations}static getPersistedStoresIds(){return l.persistedStores}getStoreId(e,t={}){const{id:s,contextId:r,key:o}=t;if(s)return s;if(e.libStoreId)return e.libStoreId;let i=e.id||e.name||e.constructor.name;return e.isGlobal?i:(i=`${i}--${r}`,o?`${i}--${o}`:i)}getStore(e,t={}){const s=this.getStoreId(e,t);return this.stores.has(s)?this.stores.get(s):e.isGlobal?this.createStore(e,{id:s,contextId:"global",parentId:"root",suspenseId:"",componentName:"root-app",componentProps:{}}):this.lookupStore(s,t)}lookupStore(e,t){var s,r;const{contextId:o,parentId:i}=t,n=null===(s=e.split("--"))||void 0===s?void 0:s[0],{ids:a,parentId:l}=null!==(r=this.storesRelations.get(o))&&void 0!==r?r:{ids:new Set,parentId:i},u=[...a].filter((e=>e.startsWith(`${n}--`)));if(1===u.length)return this.stores.get(u[0]);if(u.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){const{id:r,contextId:i,parentId:n,suspenseId:l,componentName:u,componentProps:d}=t;if(this.stores.has(r))return this.stores.get(r);const h=new e({...this.storesParams,storeManager:this,getStore:(e,t={contextId:i,parentId:n})=>this.getStore(e,t),componentProps:d});return h.libStoreId=r,h.isGlobal=e.isGlobal,h.libStoreContextId=e.isGlobal?"global":i,h.libStoreParentId=e.isGlobal||!n||n===i?"root":n,h.libStoreSuspenseId=l,h.libStoreComponentName=u,this.setStoreStatus(h,e.isGlobal?o.inUse:o.init),this.prepareStore(h),a.default.publish(s.CREATE_STORE,{store:e}),h}createStores(e,t,s,r,o,i={}){return e.reduce(((e,[n,a])=>{const[l,u]="store"in a?[a.store,a.id]:[a,this.getStoreId(a,{key:n,contextId:s})];return{...e,[n]:this.createStore(l,{id:u,contextId:s,parentId:t,suspenseId:r,componentName:o,componentProps:i})}}),{})}prepareStore(e){var t,r
|
|
1
|
+
"use strict";var e=require("@lomray/event-manager"),t=require("mobx"),s=require("./events.js"),r=require("./on-change-listener.js"),o=require("./store-status.js"),i=require("./wakeup.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=n(e);class l{constructor({initState:e,storesParams:t,storage:s,options:r}={}){if(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}}),Object.defineProperty(this,"suspenseRelations",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"pushInitState",{enumerable:!0,configurable:!0,writable:!0,value:(e={})=>{for(const[t,s]of Object.entries(e))this.initState[t]=s}}),this.initState=e||{},this.storesParams=t||{},this.storage=s,Object.assign(this.options,r||{}),l.instance=this,"undefined"!=typeof window){const e=window.mbxM;window.mbxM={push:this.pushInitState},(Array.isArray(e)?e:[]).forEach(this.pushInitState)}}async init(){return this.storage&&(this.persistData=await this.storage.get()||{}),this}static get(){if(!l.instance)throw new Error("Store manager is not initialized.");return l.instance}getStores(){return this.stores}getStoresRelations(){return this.storesRelations}getSuspenseRelations(){return this.suspenseRelations}static getPersistedStoresIds(){return l.persistedStores}getStoreId(e,t={}){const{id:s,contextId:r,key:o}=t;if(s)return s;if(e.libStoreId)return e.libStoreId;let i=e.id||e.name||e.constructor.name;return e.isGlobal?i:(i=`${i}--${r}`,o?`${i}--${o}`:i)}getStore(e,t={}){const s=this.getStoreId(e,t);return this.stores.has(s)?this.stores.get(s):e.isGlobal?this.createStore(e,{id:s,contextId:"global",parentId:"root",suspenseId:"",componentName:"root-app",componentProps:{}}):this.lookupStore(s,t)}lookupStore(e,t){var s,r;const{contextId:o,parentId:i}=t,n=null===(s=e.split("--"))||void 0===s?void 0:s[0],{ids:a,parentId:l}=null!==(r=this.storesRelations.get(o))&&void 0!==r?r:{ids:new Set,parentId:i},u=[...a].filter((e=>e.startsWith(`${n}--`)));if(1===u.length)return this.stores.get(u[0]);if(u.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){const{id:r,contextId:i,parentId:n,suspenseId:l,componentName:u,componentProps:d}=t;if(this.stores.has(r))return this.stores.get(r);const h=new e({...this.storesParams,storeManager:this,getStore:(e,t={contextId:i,parentId:n})=>this.getStore(e,t),componentProps:d});return h.libStoreId=r,h.isGlobal=e.isGlobal,h.libStoreContextId=e.isGlobal?"global":i,h.libStoreParentId=e.isGlobal||!n||n===i?"root":n,h.libStoreSuspenseId=l,h.libStoreComponentName=u,this.setStoreStatus(h,e.isGlobal?o.inUse:o.init),this.prepareStore(h),a.default.publish(s.CREATE_STORE,{store:e}),h}createStores(e,t,s,r,o,i={}){return e.reduce(((e,[n,a])=>{const[l,u]="store"in a?[a.store,a.id]:[a,this.getStoreId(a,{key:n,contextId:s})];return{...e,[n]:this.createStore(l,{id:u,contextId:s,parentId:t,suspenseId:r,componentName:o,componentProps:i})}}),{})}prepareStore(e){var t,s,r;const o=e.libStoreId,i=e.libStoreContextId,n=e.libStoreSuspenseId,a=this.initState[o],u=this.persistData[o];if(this.stores.has(o))return;if(a&&Object.assign(e,a),"wakeup"in e&&l.persistedStores.has(o)&&(null===(t=e.wakeup)||void 0===t||t.call(e,{initState:a,persistedState:u})),l.persistedStores.has(o)&&"addOnChangeListener"in e){const t=null===(s=e.onDestroy)||void 0===s?void 0:s.bind(e),r=e.addOnChangeListener(e,this);e.onDestroy=()=>{null==r||r(),null==t||t()}}null===(r=e.init)||void 0===r||r.call(e),this.storesRelations.has(i)||this.storesRelations.set(i,{ids:new Set,parentId:e.libStoreParentId&&e.libStoreParentId!==i?e.libStoreParentId:"root",componentName:e.libStoreComponentName}),this.suspenseRelations.has(n)||this.suspenseRelations.set(n,new Set);const{ids:d}=this.storesRelations.get(i);this.stores.set(o,e),d.add(o),this.suspenseRelations.get(n).add(o)}removeStore(e){var t,r,o;const i=e.libStoreId,n=e.libStoreSuspenseId,{ids:l}=null!==(t=this.storesRelations.get(e.libStoreContextId))&&void 0!==t?t:{ids:new Set};this.stores.has(i)&&(this.stores.delete(i),l.delete(i),n&&(null===(r=this.suspenseRelations.get(n))||void 0===r?void 0:r.has(i))&&this.suspenseRelations.get(n).delete(i),l.size||this.storesRelations.delete(e.libStoreContextId),"onDestroy"in e&&(null===(o=e.onDestroy)||void 0===o||o.call(e)),a.default.publish(s.DELETE_STORE,{store:e}))}mountStores(e){const{shouldRemoveInitState:t}=this.options;return Object.values(e).forEach((e=>{const r=e.libStoreId;t&&this.initState[r]&&delete this.initState[r],this.setStoreStatus(e,o.inUse),a.default.publish(s.MOUNT_STORE,{store:e})})),()=>{Object.values(e).forEach((e=>{e.isGlobal||(this.setStoreStatus(e,o.unused),a.default.publish(s.UNMOUNT_STORE,{store:e}))}))}}touchedStores(e){Object.values(e).forEach((e=>{e.libStoreStatus!==o.init||e.isGlobal||this.setStoreStatus(e,o.touched)}))}setStoreStatus(e,t){const{destroyTimers:{init:s=500,touched:r=1e4,unused:i=1e3}={}}=this.options;e.libStoreStatus=t,clearTimeout(e.libDestroyTimer);let n=0;switch(t){case o.init:n=s;break;case o.touched:n=r;break;case o.unused:n=i}n&&(e.libDestroyTimer=setTimeout((()=>this.removeStore(e)),n))}toJSON(e){var t,s,r;const o={},i=null!==(t=null==e?void 0:e.reduce(((e,t)=>(this.stores.has(t)&&e.set(t,this.stores.get(t)),e)),new Map))&&void 0!==t?t:this.stores;for(const[e,t]of i.entries())o[e]=null!==(r=null===(s=t.toJSON)||void 0===s?void 0:s.call(t))&&void 0!==r?r:l.getObservableProps(t);return o}toPersistedJSON(){var e,t;const s={};for(const r of l.persistedStores){const o=this.stores.get(r);o&&(s[r]=null!==(t=null===(e=o.toJSON)||void 0===e?void 0:e.call(o))&&void 0!==t?t:l.getObservableProps(o))}return s}static getObservableProps(e){const s=t.toJS(e);return Object.entries(s).reduce(((s,[r,o])=>({...s,...t.isObservableProp(e,r)?{[r]:o}:{}})),{})}static persistStore(e,t){return l.persistedStores.has(t)?(console.warn(`Duplicate serializable store key: ${t}`),e):(l.persistedStores.add(t),e.libStoreId=t,"wakeup"in e.prototype||(e.prototype.wakeup=i.bind(e)),"addOnChangeListener"in e.prototype||(e.prototype.addOnChangeListener=r),e)}}Object.defineProperty(l,"persistedStores",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),module.exports=l;
|
package/lib/suspense-query.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import Events from "./events.js";
|
|
2
3
|
import Manager from "./manager.js";
|
|
3
4
|
import StoreStatus from "./store-status.js";
|
|
4
5
|
interface IWindowManager {
|
|
@@ -96,4 +97,18 @@ interface IStoreParams {
|
|
|
96
97
|
interface IWithStoreOptions {
|
|
97
98
|
customContextId?: string;
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
+
interface IMobxManagerEvents {
|
|
101
|
+
[Events.CREATE_STORE]: {
|
|
102
|
+
store: IConstructableStore;
|
|
103
|
+
};
|
|
104
|
+
[Events.MOUNT_STORE]: {
|
|
105
|
+
store: IStorePersisted | IStore;
|
|
106
|
+
};
|
|
107
|
+
[Events.UNMOUNT_STORE]: {
|
|
108
|
+
store: IStorePersisted | IStore;
|
|
109
|
+
};
|
|
110
|
+
[Events.DELETE_STORE]: {
|
|
111
|
+
store: IStorePersisted | IStore;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export { IWindowManager, IConstructorParams, IStoreLifecycle, IStore, IStorePersisted, TInitStore, IConstructableStore, IStoreConfig, TStoreDefinition, TMapStores, IManagerParams, TWakeup, IStorage, IManagerOptions, TStores, ClassReturnType, StoresType, IStoreParams, IWithStoreOptions, IMobxManagerEvents };
|
package/lib/wakeup.d.ts
CHANGED
package/lib/with-stores.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lomray/react-mobx-manager",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1-beta.1",
|
|
4
4
|
"description": "This package provides Mobx stores manager for react.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@lomray/consistent-suspense": "^1.3.0",
|
|
55
|
-
"@lomray/event-manager": "^
|
|
55
|
+
"@lomray/event-manager": "^2.0.2"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@commitlint/cli": "^17.
|
|
59
|
-
"@commitlint/config-conventional": "^17.
|
|
58
|
+
"@commitlint/cli": "^17.7.1",
|
|
59
|
+
"@commitlint/config-conventional": "^17.7.0",
|
|
60
60
|
"@lomray/eslint-config-react": "^3.0.0",
|
|
61
61
|
"@lomray/prettier-config": "^1.2.0",
|
|
62
62
|
"@rollup/plugin-terser": "^0.4.3",
|