react-app-store-manager 2.0.2 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Provider.d.ts +3 -3
- package/dist/Store.d.ts +8 -7
- package/dist/Store.js +1 -1
- package/dist/createStore.d.ts +1 -1
- package/dist/isEqual.js +9 -14
- package/dist/useStore.d.ts +1 -1
- package/package.json +1 -1
package/dist/Provider.d.ts
CHANGED
@@ -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<
|
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,22 +2,23 @@ import React, { Context } from "react";
|
|
2
2
|
interface ListenerInterface {
|
3
3
|
onUpdate(): void;
|
4
4
|
}
|
5
|
-
export interface StoreInterface<Value,
|
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:
|
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,
|
14
|
+
export declare class Store<Value, Actions> implements StoreInterface<Value, Actions> {
|
14
15
|
context: React.Context<Value>;
|
15
16
|
value: Value;
|
16
|
-
|
17
|
+
readonly actions: Actions;
|
17
18
|
private listeners;
|
18
|
-
constructor(value: Value, actions
|
19
|
+
constructor(value: Value, actions: Actions);
|
19
20
|
update(callback: any): void;
|
20
|
-
action(callback: any):
|
21
|
+
action(callback: any): any;
|
21
22
|
subscribe(listener: ListenerInterface): void;
|
22
23
|
unsubscribe(listener: ListenerInterface): void;
|
23
24
|
}
|
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);
|
package/dist/createStore.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
import { StoreInterface } from "./Store";
|
2
|
-
export declare function createStore<
|
2
|
+
export declare function createStore<V, A extends object | undefined = 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 (
|
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
|
-
|
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
|
-
|
29
|
-
return false;
|
24
|
+
return newValue === oldValue;
|
30
25
|
}
|
31
26
|
return true;
|
32
27
|
}
|
package/dist/useStore.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
import { StoreInterface } from "./Store";
|
2
|
-
export declare function useStore<T>(store: StoreInterface<T,
|
2
|
+
export declare function useStore<T, A = undefined>(store: StoreInterface<T, A>): T;
|