react-app-store-manager 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { StoreInterface } from "./Store";
3
- interface Props {
3
+ interface Props<V, E> {
4
4
  children?: ReactNode;
5
- store: StoreInterface<any, any>;
5
+ store: StoreInterface<V, E>;
6
6
  }
7
- export declare function Provider({ store, children }: Props): JSX.Element;
7
+ export declare function Provider<V, E>({ store, children }: Props<V, E>): JSX.Element;
8
8
  export {};
package/dist/Store.d.ts CHANGED
@@ -2,23 +2,25 @@ import React, { Context } from "react";
2
2
  interface ListenerInterface {
3
3
  onUpdate(): void;
4
4
  }
5
- export interface StoreInterface<Value, Action> {
6
- context: Context<Value>;
5
+ export interface StoreInterface<Value, Actions> {
7
6
  value: Value;
7
+ actions: Actions;
8
8
  update(store: (store: Value) => Value): void;
9
- action(actions: (action: Action) => any): void;
9
+ action(actions: (action: Actions) => any): any;
10
+ context: Context<Value>;
10
11
  subscribe(listener: ListenerInterface): void;
11
12
  unsubscribe(listener: ListenerInterface): void;
12
13
  }
13
- export declare class Store<Value, Action> implements StoreInterface<Value, Action> {
14
+ export declare class Store<Value, Actions> implements StoreInterface<Value, Actions> {
14
15
  context: React.Context<Value>;
15
16
  value: Value;
16
- private readonly actions?;
17
+ readonly actions: Actions;
17
18
  private listeners;
18
- constructor(value: Value, actions?: Action);
19
+ constructor(value: Value, actions: Actions);
19
20
  update(callback: any): void;
20
- action(callback: any): void;
21
+ action(callback: any): any;
21
22
  subscribe(listener: ListenerInterface): void;
22
23
  unsubscribe(listener: ListenerInterface): void;
24
+ __getContext(): React.Context<Value>;
23
25
  }
24
26
  export {};
package/dist/Store.js CHANGED
@@ -21,7 +21,7 @@ var Store = /** @class */ (function () {
21
21
  }
22
22
  };
23
23
  Store.prototype.action = function (callback) {
24
- callback(this.actions);
24
+ return callback.bind(this, this.actions);
25
25
  };
26
26
  Store.prototype.subscribe = function (listener) {
27
27
  this.listeners.push(listener);
@@ -29,6 +29,9 @@ var Store = /** @class */ (function () {
29
29
  Store.prototype.unsubscribe = function (listener) {
30
30
  this.listeners = this.listeners.filter(function (l) { return l !== listener; });
31
31
  };
32
+ Store.prototype.__getContext = function () {
33
+ return this.context;
34
+ };
32
35
  return Store;
33
36
  }());
34
37
  exports.Store = Store;
@@ -1,2 +1,2 @@
1
1
  import { StoreInterface } from "./Store";
2
- export declare function createStore<Value>(value: any, actions?: any): StoreInterface<Value, typeof actions>;
2
+ export declare function createStore<V, A extends object | undefined>(value: any, actions: A): StoreInterface<V, A>;
package/dist/isEqual.js CHANGED
@@ -4,29 +4,24 @@ exports.isEqual = void 0;
4
4
  function isEqual(newValue, oldValue) {
5
5
  switch (typeof (newValue)) {
6
6
  case 'object':
7
- if (newValue === null || oldValue === null) {
7
+ if (newValue === null || oldValue === null)
8
8
  return newValue === oldValue;
9
+ if (newValue instanceof Date) {
10
+ return String(newValue) === String(oldValue);
9
11
  }
10
- if (newValue instanceof Date && oldValue instanceof Date && String(newValue) !== String(oldValue))
11
- return false;
12
12
  for (var prop in newValue) {
13
- if (newValue.hasOwnProperty(prop) !== (oldValue === null || oldValue === void 0 ? void 0 : oldValue.hasOwnProperty(prop)))
14
- return false;
15
- if (!isEqual(newValue === null || newValue === void 0 ? void 0 : newValue[prop], oldValue === null || oldValue === void 0 ? void 0 : oldValue[prop]))
13
+ if (!(oldValue === null || oldValue === void 0 ? void 0 : oldValue.hasOwnProperty(prop)))
16
14
  return false;
17
- }
18
- for (var prop in oldValue) {
19
- if (typeof (newValue[prop]) == 'undefined')
15
+ if (!isEqual(newValue[prop], oldValue[prop]))
20
16
  return false;
21
17
  }
22
- break;
23
- case 'function':
24
- if (typeof (oldValue) !== 'function' || (newValue.toString() !== oldValue.toString()))
18
+ if (Object.keys(oldValue).length !== Object.keys(newValue).length)
25
19
  return false;
26
20
  break;
21
+ case 'function':
22
+ return typeof (oldValue) === 'function' && newValue.toString() === oldValue.toString();
27
23
  default:
28
- if (newValue !== oldValue)
29
- return false;
24
+ return newValue === oldValue;
30
25
  }
31
26
  return true;
32
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-app-store-manager",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "tsc --declaration"