react-app-store-manager 2.0.1 → 2.1.0
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/dist/Provider.d.ts +3 -3
- package/dist/Store.d.ts +9 -7
- package/dist/Store.js +4 -1
- package/dist/createStore.d.ts +1 -1
- package/dist/isEqual.js +9 -14
- 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,23 +2,25 @@ 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;
|
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;
|
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>(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
|
}
|