@lomray/react-mobx-manager 1.0.0-beta.2 → 1.0.0-beta.3
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 +3 -3
- package/lib/context.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/manager.d.ts +2 -2
- package/lib/manager.js +3 -3
- package/lib/on-change-listener.d.ts +1 -1
- package/lib/storages/local-storage.d.ts +1 -1
- package/lib/{types-8055671c.d.ts → types-f2f6b0e4.d.ts} +12 -2
- package/lib/wakeup.d.ts +1 -1
- package/lib/with-stores.d.ts +3 -3
- package/lib/with-stores.js +2 -2
- package/package.json +2 -1
- package/lib/fc-with-children-874c53fb.d.ts +0 -6
package/lib/context.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { ReactElement } from "react";
|
|
4
|
-
import { FCC } from "./fc-with-children-874c53fb";
|
|
3
|
+
import { FC, ReactElement } from "react";
|
|
5
4
|
import Manager from "./manager";
|
|
6
5
|
interface IStoreManagerProvider {
|
|
7
6
|
storeManager: Manager;
|
|
8
7
|
shouldInit?: boolean;
|
|
9
8
|
fallback?: ReactElement;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Mobx store manager context
|
|
@@ -16,6 +16,6 @@ declare const StoreManagerContext: React.Context<Manager>;
|
|
|
16
16
|
* Mobx store manager provider
|
|
17
17
|
* @constructor
|
|
18
18
|
*/
|
|
19
|
-
declare const StoreManagerProvider:
|
|
19
|
+
declare const StoreManagerProvider: FC<IStoreManagerProvider>;
|
|
20
20
|
declare const useStoreManagerContext: () => Manager;
|
|
21
21
|
export { StoreManagerProvider, StoreManagerContext, useStoreManagerContext };
|
package/lib/context.js
CHANGED
|
@@ -26,7 +26,7 @@ const StoreManagerProvider = ({ children, storeManager, fallback, shouldInit = f
|
|
|
26
26
|
.init()
|
|
27
27
|
.then(() => setInit(true))
|
|
28
28
|
.catch((e) => {
|
|
29
|
-
console.error('Failed
|
|
29
|
+
console.error('Failed initialized store manager: ', e);
|
|
30
30
|
});
|
|
31
31
|
}, [shouldInit, storeManager]);
|
|
32
32
|
return (React__default["default"].createElement(StoreManagerContext.Provider, { value: storeManager, children: isInit ? children : fallback || children }));
|
package/lib/index.d.ts
CHANGED
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, TInitStore } from "./types-f2f6b0e4";
|
|
2
2
|
/**
|
|
3
3
|
* Mobx stores manager
|
|
4
4
|
*/
|
|
@@ -47,7 +47,7 @@ declare class Manager {
|
|
|
47
47
|
/**
|
|
48
48
|
* @constructor
|
|
49
49
|
*/
|
|
50
|
-
constructor({ initState, storesParams, storage, options }
|
|
50
|
+
constructor({ initState, storesParams, storage, options }?: IManagerParams);
|
|
51
51
|
/**
|
|
52
52
|
* Init store manager
|
|
53
53
|
*/
|
package/lib/manager.js
CHANGED
|
@@ -52,11 +52,11 @@ class Manager {
|
|
|
52
52
|
/**
|
|
53
53
|
* @constructor
|
|
54
54
|
*/
|
|
55
|
-
constructor({ initState, storesParams, storage, options }) {
|
|
55
|
+
constructor({ initState, storesParams, storage, options } = {}) {
|
|
56
56
|
this.initState = initState || {};
|
|
57
|
-
this.storesParams = storesParams;
|
|
57
|
+
this.storesParams = storesParams || {};
|
|
58
58
|
this.storage = storage;
|
|
59
|
-
Object.assign(this.options, options);
|
|
59
|
+
Object.assign(this.options, options || {});
|
|
60
60
|
Manager.instance = this;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
@@ -24,7 +24,7 @@ type TStoreDefinition<TSto extends IStore | IStorePersisted = any> = IConstructa
|
|
|
24
24
|
};
|
|
25
25
|
type TMapStores = Record<string, TStoreDefinition>;
|
|
26
26
|
interface IManagerParams {
|
|
27
|
-
storesParams
|
|
27
|
+
storesParams?: Omit<IConstructorParams, 'storeManager'>;
|
|
28
28
|
storage?: IStorage;
|
|
29
29
|
options?: IManagerOptions;
|
|
30
30
|
initState?: Record<string, any>;
|
|
@@ -45,4 +45,14 @@ interface IManagerOptions {
|
|
|
45
45
|
type TStores = {
|
|
46
46
|
[storeKey: string]: IStore | IStorePersisted;
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Convert class type to class constructor
|
|
50
|
+
*/
|
|
51
|
+
type ClassReturnType<T> = T extends new (...args: any) => infer R ? R : never;
|
|
52
|
+
/**
|
|
53
|
+
* Stores map to type
|
|
54
|
+
*/
|
|
55
|
+
type StoresType<TSt> = {
|
|
56
|
+
[keys in keyof TSt]: ClassReturnType<TSt[keys]>;
|
|
57
|
+
};
|
|
58
|
+
export { IConstructorParams, IStoreLifecycle, IStore, IStorePersisted, TInitStore, IConstructableStore, TStoreDefinition, TMapStores, IManagerParams, TWakeup, IStorage, IManagerOptions, TStores, ClassReturnType, StoresType };
|
package/lib/wakeup.d.ts
CHANGED
package/lib/with-stores.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TMapStores } from "./types-
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { TMapStores } from "./types-f2f6b0e4";
|
|
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:
|
|
6
|
+
declare const withStores: <T extends Record<string, any>, TS extends TMapStores>(Component: FC<T>, stores: TS) => FC<Omit<T, keyof TS>>;
|
|
7
7
|
export { withStores as default };
|
package/lib/with-stores.js
CHANGED
|
@@ -17,7 +17,7 @@ const withStores = (Component, stores) => {
|
|
|
17
17
|
const storesMap = Object.entries(stores);
|
|
18
18
|
const ObservableComponent = mobxReactLite.observer(Component);
|
|
19
19
|
const componentName = Component.displayName || Component.name;
|
|
20
|
-
const Element = React__default["default"].memo(({
|
|
20
|
+
const Element = React__default["default"].memo(({ ...props }) => {
|
|
21
21
|
const storeManager = context.useStoreManagerContext();
|
|
22
22
|
const [initStores] = React.useState(() => storeManager.createStores(storesMap));
|
|
23
23
|
/**
|
|
@@ -25,7 +25,7 @@ const withStores = (Component, stores) => {
|
|
|
25
25
|
* - Check if store has 'onDestroy' method (call if exist)
|
|
26
26
|
*/
|
|
27
27
|
React.useEffect(() => storeManager.mountStores(initStores), [initStores, storeManager]);
|
|
28
|
-
return React__default["default"].createElement(ObservableComponent, {
|
|
28
|
+
return React__default["default"].createElement(ObservableComponent, { ...initStores, ...props });
|
|
29
29
|
});
|
|
30
30
|
hoistNonReactStatics__default["default"](Element, Component);
|
|
31
31
|
Element.displayName = `Mobx(${componentName})`;
|
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.3",
|
|
4
4
|
"description": "This package provides Mobx stores manager for react.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"homepage": "https://github.com/Lomray-Software/react-mobx-manager",
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "rollup -c",
|
|
34
|
+
"build:watch": "rollup -c -w --environment BUILD:development",
|
|
34
35
|
"prettier:format": "prettier --write 'src/**/*.{ts,tsx,*.ts,*tsx}'",
|
|
35
36
|
"prettier:check": "prettier --check --debug-check 'src/**/*.{ts,tsx,*.ts,*tsx}'",
|
|
36
37
|
"lint:check": "eslint --ext '.ts,.tsx' 'src/**/*.{ts,tsx,*.ts,*tsx}'",
|