@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 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: FCC<IStoreManagerProvider>;
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 initiated store manager: ', e);
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
@@ -1,4 +1,4 @@
1
- export * from "./types-8055671c";
1
+ export * from "./types-f2f6b0e4";
2
2
  export * from "./context";
3
3
  export { default as Manager } from "./manager";
4
4
  export { default as onChangeListener } from "./on-change-listener";
package/lib/manager.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IConstructableStore, IManagerParams, IStorage, IStore, TStoreDefinition, IManagerOptions, TStores, TInitStore } from "./types-8055671c";
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 }: IManagerParams);
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
  /**
@@ -1,4 +1,4 @@
1
- import { IStorePersisted } from "./types-8055671c";
1
+ import { IStorePersisted } from "./types-f2f6b0e4";
2
2
  /**
3
3
  * Listen persist store changes
4
4
  */
@@ -1,4 +1,4 @@
1
- import { IStorage } from "../types-8055671c";
1
+ import { IStorage } from "../types-f2f6b0e4";
2
2
  declare class LocalStorage implements IStorage {
3
3
  globalKey: string;
4
4
  /**
@@ -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: Omit<IConstructorParams, 'storeManager'>;
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
- export { IConstructorParams, IStoreLifecycle, IStore, IStorePersisted, TInitStore, IConstructableStore, TStoreDefinition, TMapStores, IManagerParams, TWakeup, IStorage, IManagerOptions, TStores };
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
@@ -1,4 +1,4 @@
1
- import { IStorePersisted } from "./types-8055671c";
1
+ import { IStorePersisted } from "./types-f2f6b0e4";
2
2
  /**
3
3
  * Restore store state from initial state
4
4
  */
@@ -1,7 +1,7 @@
1
- import { FCC } from "./fc-with-children-874c53fb";
2
- import { TMapStores } from "./types-8055671c";
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: FCC<T>, stores: TS) => FCC<Omit<T, keyof TS>>;
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 };
@@ -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(({ children, ...props }) => {
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, { children: children, ...initStores, ...props });
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.2",
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}'",
@@ -1,6 +0,0 @@
1
- import { FC, PropsWithChildren } from 'react';
2
- /**
3
- * Custom Type for a React functional component with props AND CHILDREN
4
- */
5
- type FCC<TP extends object = any> = FC<PropsWithChildren<TP>>;
6
- export { FCC };