react-ui-basics 0.0.144 → 0.0.147
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/MaterialIcon.js +1 -1
- package/{types/Tools.d.ts → Tools.d.ts} +0 -0
- package/Tools.js +1 -1
- package/Tools.js.map +1 -1
- package/bundle.css +967 -967
- package/package.json +1 -1
- package/{types/store → store}/Store.d.ts +7 -4
- package/store/Store.js +15 -13
- package/store/Store.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
interface Stores {
|
|
2
|
-
[
|
|
2
|
+
[index: number]: any;
|
|
3
3
|
}
|
|
4
4
|
export declare class Store<T> {
|
|
5
5
|
private name;
|
|
6
6
|
private listeners;
|
|
7
7
|
private initialState;
|
|
8
8
|
private index;
|
|
9
|
-
constructor(initialState: T, name
|
|
9
|
+
constructor(initialState: T, name?: string);
|
|
10
10
|
get: () => T;
|
|
11
|
-
set: (mutator: (
|
|
11
|
+
set: (mutator: (oldState: T) => T) => void;
|
|
12
12
|
reset: () => void;
|
|
13
13
|
subscribe: (fn: () => void) => void;
|
|
14
14
|
unsubscribe: (fn: () => void) => void;
|
|
@@ -18,4 +18,7 @@ export default Store;
|
|
|
18
18
|
export declare function getGlobalState(): Stores;
|
|
19
19
|
export declare function resetGlobalState(): void;
|
|
20
20
|
export declare function replaceGlobalState(state: any): void;
|
|
21
|
-
export declare
|
|
21
|
+
export declare type Selector<T, R> = (t: T) => R;
|
|
22
|
+
export declare const defaultSelector: <T>(store: T) => T;
|
|
23
|
+
export declare function useStore<T, R>(store: Store<T>, selector: Selector<T, R>): R;
|
|
24
|
+
export declare function useStore<T>(store: Store<T>, selector?: undefined): T;
|
package/store/Store.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import { createProxy } from './ProxyTools.js';
|
|
3
3
|
|
|
4
|
-
let
|
|
4
|
+
let STORES = {};
|
|
5
5
|
let COUNTER = 0;
|
|
6
6
|
class Store {
|
|
7
7
|
constructor(initialState, name) {
|
|
8
8
|
this.listeners = [];
|
|
9
|
-
this.get = () =>
|
|
9
|
+
this.get = () => STORES[this.index];
|
|
10
10
|
this.set = (mutator) => {
|
|
11
|
-
const proxy = createProxy(
|
|
11
|
+
const proxy = createProxy(STORES[this.index]);
|
|
12
12
|
mutator(proxy);
|
|
13
|
-
|
|
13
|
+
STORES[this.index] = proxy.bake();
|
|
14
14
|
this.listeners.forEach(fn => fn());
|
|
15
15
|
};
|
|
16
16
|
this.reset = () => {
|
|
17
|
-
|
|
17
|
+
STORES[this.index] = this.initialState;
|
|
18
18
|
};
|
|
19
19
|
this.subscribe = (fn) => {
|
|
20
20
|
this.listeners.push(fn);
|
|
@@ -28,20 +28,22 @@ class Store {
|
|
|
28
28
|
that.initialState = initialState;
|
|
29
29
|
const index = COUNTER++;
|
|
30
30
|
that.index = index;
|
|
31
|
-
|
|
31
|
+
STORES[index] = initialState;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
function getGlobalState() {
|
|
35
|
-
return
|
|
35
|
+
return STORES;
|
|
36
36
|
}
|
|
37
37
|
function resetGlobalState() {
|
|
38
|
-
|
|
38
|
+
STORES = {};
|
|
39
39
|
}
|
|
40
40
|
function replaceGlobalState(state) {
|
|
41
|
-
|
|
41
|
+
STORES = state;
|
|
42
42
|
}
|
|
43
|
-
const defaultSelector = store => store;
|
|
44
|
-
|
|
43
|
+
const defaultSelector = (store) => store;
|
|
44
|
+
function useStore(store, selector) {
|
|
45
|
+
if (!selector)
|
|
46
|
+
selector = defaultSelector;
|
|
45
47
|
const [state, setState] = useState(selector(store.get()));
|
|
46
48
|
const updateState = () => {
|
|
47
49
|
setState(selector(store.get()));
|
|
@@ -51,7 +53,7 @@ const useStore = (store, selector = defaultSelector) => {
|
|
|
51
53
|
return () => store.unsubscribe(updateState);
|
|
52
54
|
});
|
|
53
55
|
return state;
|
|
54
|
-
}
|
|
56
|
+
}
|
|
55
57
|
|
|
56
|
-
export { Store, Store as default, getGlobalState, replaceGlobalState, resetGlobalState, useStore };
|
|
58
|
+
export { Store, Store as default, defaultSelector, getGlobalState, replaceGlobalState, resetGlobalState, useStore };
|
|
57
59
|
//# sourceMappingURL=Store.js.map
|
package/store/Store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Store.js","sources":["../../src/react-ui-basics/store/Store.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAOA,IAAI,
|
|
1
|
+
{"version":3,"file":"Store.js","sources":["../../src/src/react-ui-basics/store/Store.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAOA,IAAI,MAAM,GAAW,EAAE,CAAA;AACvB,IAAI,OAAO,GAAG,CAAC,CAAA;MAEF,KAAK,CAAA;IAMd,WAAY,CAAA,YAAe,EAAE,IAAa,EAAA;QAJlC,IAAS,CAAA,SAAA,GAAsB,EAAE,CAAA;QAazC,IAAG,CAAA,GAAA,GAAG,MAAS,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACjC,QAAA,IAAA,CAAA,GAAG,GAAG,CAAC,OAA2B,KAAI;YAClC,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9C,OAAO,CAAC,KAAK,CAAC,CAAA;YACd,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;AACjC,YAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;AACtC,SAAC,CAAA;QAED,IAAK,CAAA,KAAA,GAAG,MAAK;YACT,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,YAAY,CAAA;AAC1C,SAAC,CAAA;AAED,QAAA,IAAA,CAAA,SAAS,GAAG,CAAC,EAAc,KAAI;AAC3B,YAAA,IAAI,CAAC,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