react-global-state-hooks 10.2.0 → 11.0.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/GlobalStore.d.ts +1 -1
- package/GlobalStore.js +50 -1
- package/GlobalStoreAbstract.d.ts +1 -1
- package/GlobalStoreAbstract.js +35 -1
- package/README.md +5 -5
- package/bundle.js +62 -1
- package/createContext.d.ts +1 -1
- package/createContext.js +35 -1
- package/createGlobalState.d.ts +132 -6
- package/createGlobalState.js +49 -1
- package/getLocalStorageItem.js +43 -1
- package/index.d.ts +3 -6
- package/isRecord.js +35 -1
- package/package.json +5 -18
- package/setLocalStorageItem.js +43 -1
- package/shallowCompare.js +35 -1
- package/throwWrongKeyOnActionCollectionConfig.js +35 -1
- package/types.d.ts +1 -1
- package/types.js +4 -1
- package/uniqueId.js +35 -1
- package/webpack.config.js +5 -6
- package/createCustomGlobalState.d.ts +0 -23
- package/createCustomGlobalState.js +0 -1
- package/generateStackHash.d.ts +0 -1
- package/generateStackHash.js +0 -1
- package/useStableState.d.ts +0 -1
- package/useStableState.js +0 -1
package/GlobalStore.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ActionCollectionConfig, BaseMetadata, GlobalStoreCallbacks, StateChanges, StoreTools } from 'react-hooks-global-states/types';
|
|
2
2
|
import { GlobalStoreAbstract } from 'react-hooks-global-states/GlobalStoreAbstract';
|
|
3
3
|
import { LocalStorageConfig } from './types';
|
|
4
|
-
export declare class GlobalStore<State, Metadata extends BaseMetadata
|
|
4
|
+
export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | undefined | unknown> extends GlobalStoreAbstract<State, Metadata, ActionsConfig> {
|
|
5
5
|
protected localStorage: LocalStorageConfig | null;
|
|
6
6
|
constructor(state: State);
|
|
7
7
|
constructor(state: State, args: {
|
package/GlobalStore.js
CHANGED
|
@@ -1 +1,50 @@
|
|
|
1
|
-
var t,e;t=this,e=(t,e,o)
|
|
1
|
+
var t,e;t=this,e=(t,e,o)=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var r={
|
|
4
|
+
/***/266:
|
|
5
|
+
/***/e=>{e.exports=t;
|
|
6
|
+
/***/},
|
|
7
|
+
/***/683:
|
|
8
|
+
/***/t=>{t.exports=e;
|
|
9
|
+
/***/},
|
|
10
|
+
/***/959:
|
|
11
|
+
/***/t=>{t.exports=o;
|
|
12
|
+
/***/}
|
|
13
|
+
/******/},a={};
|
|
14
|
+
/************************************************************************/
|
|
15
|
+
/******/
|
|
16
|
+
/******/
|
|
17
|
+
/******/
|
|
18
|
+
/******/
|
|
19
|
+
/******/function n(t){
|
|
20
|
+
/******/
|
|
21
|
+
/******/var e=a[t];
|
|
22
|
+
/******/if(void 0!==e)
|
|
23
|
+
/******/return e.exports;
|
|
24
|
+
/******/
|
|
25
|
+
/******/
|
|
26
|
+
/******/var o=a[t]={
|
|
27
|
+
/******/
|
|
28
|
+
/******/
|
|
29
|
+
/******/exports:{}
|
|
30
|
+
/******/};
|
|
31
|
+
/******/
|
|
32
|
+
/******/
|
|
33
|
+
/******/
|
|
34
|
+
/******/
|
|
35
|
+
/******/
|
|
36
|
+
/******/return r[t](o,o.exports,n),o.exports;
|
|
37
|
+
/******/}
|
|
38
|
+
/******/
|
|
39
|
+
/************************************************************************/var l={};
|
|
40
|
+
/******/return(()=>{var t=l;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function o(t,o){if(o&&("object"==e(o)||"function"==typeof o))return o;if(void 0!==o)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function r(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(r=function(){return!!t})()}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var i=n(266),u=n(959),s=n(683),f=function(t){function e(t){var n,l,c,i,f,b=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{metadata:{}};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),c=this,f=[t,b],i=a(i=e),(n=o(c,r()?Reflect.construct(i,f||[],a(c).constructor):i.apply(c,f))).localStorage=null,n.isLocalStorageAvailable=function(t){return Boolean((null==t?void 0:t.key)&&(null===globalThis||void 0===globalThis?void 0:globalThis.localStorage))},n._onInitialize=function(t){var e=t.setState,o=t.getState;if(n.isLocalStorageAvailable(n.localStorage)){var r=(0,u.getLocalStorageItem)(n.localStorage);if(null===r){var a=o();return(0,s.setLocalStorageItem)(a,n.localStorage)}e(r)}},n._onChange=function(t){var e=t.getState;n.isLocalStorageAvailable(n.localStorage)&&(0,s.setLocalStorageItem)(e(),n.localStorage)},
|
|
41
|
+
/**
|
|
42
|
+
* We set it to null so the instances of the GlobalStoreAbstract can override it.
|
|
43
|
+
*/
|
|
44
|
+
n.onInitialize=null,n.onChange=null,
|
|
45
|
+
/**
|
|
46
|
+
* Instead of calling onInitialize and onChange directly, we call the _onInitialize and _onChange
|
|
47
|
+
* This allows the concat the logic of the GlobalStore with the logic of the extension class.
|
|
48
|
+
*/
|
|
49
|
+
n.onInit=function(t){var e;null===(e=n._onInitialize)||void 0===e||e.call(n,t)},n.onStateChanged=function(t){var e;null===(e=n._onChange)||void 0===e||e.call(n,t)},n.localStorage=null!==(l=b.localStorage)&&void 0!==l?l:null,n.constructor!==e?o(n):(n.initialize(),n)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}(e,t),n=e,Object.defineProperty(n,"prototype",{writable:!1}),n;var n}(i.GlobalStoreAbstract);t.GlobalStore=f,t.default=f})(),l;
|
|
50
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/GlobalStoreAbstract"),require("./setLocalStorageItem.js"),require("./getLocalStorageItem.js")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/GlobalStoreAbstract","./setLocalStorageItem.js","./getLocalStorageItem.js"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/GlobalStoreAbstract"),require("./setLocalStorageItem.js"),require("./getLocalStorageItem.js")):t["react-global-state-hooks"]=e(t["react-hooks-global-states/GlobalStoreAbstract"],t["./setLocalStorageItem.js"],t["./getLocalStorageItem.js"]);
|
package/GlobalStoreAbstract.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionCollectionConfig, BaseMetadata, StateChanges, StoreTools } from 'react-hooks-global-states/types';
|
|
2
2
|
import { GlobalStore } from './GlobalStore';
|
|
3
|
-
export declare abstract class GlobalStoreAbstract<State, Metadata extends BaseMetadata
|
|
3
|
+
export declare abstract class GlobalStoreAbstract<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | unknown> extends GlobalStore<State, Metadata, ActionsConfig> {
|
|
4
4
|
protected onInit: (args: StoreTools<State, Metadata>) => void;
|
|
5
5
|
onStateChanged: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
|
|
6
6
|
protected abstract onInitialize: (args: StoreTools<State, Metadata>) => void;
|
package/GlobalStoreAbstract.js
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
var t;t=t
|
|
1
|
+
var t;t=t=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var e={
|
|
4
|
+
/***/778:
|
|
5
|
+
/***/e=>{e.exports=t;
|
|
6
|
+
/***/}
|
|
7
|
+
/******/},o={};
|
|
8
|
+
/************************************************************************/
|
|
9
|
+
/******/
|
|
10
|
+
/******/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/function r(t){
|
|
14
|
+
/******/
|
|
15
|
+
/******/var n=o[t];
|
|
16
|
+
/******/if(void 0!==n)
|
|
17
|
+
/******/return n.exports;
|
|
18
|
+
/******/
|
|
19
|
+
/******/
|
|
20
|
+
/******/var i=o[t]={
|
|
21
|
+
/******/
|
|
22
|
+
/******/
|
|
23
|
+
/******/exports:{}
|
|
24
|
+
/******/};
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/
|
|
28
|
+
/******/
|
|
29
|
+
/******/
|
|
30
|
+
/******/return e[t](i,i.exports,r),i.exports;
|
|
31
|
+
/******/}
|
|
32
|
+
/******/
|
|
33
|
+
/************************************************************************/var n={};
|
|
34
|
+
/******/return(()=>{var t=n;function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(o=function(){return!!t})()}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStoreAbstract=void 0;var u=function(t){function r(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),(t=function(t,r,n){return r=i(r),function(t,o){if(o&&("object"==e(o)||"function"==typeof o))return o;if(void 0!==o)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,o()?Reflect.construct(r,n||[],i(t).constructor):r.apply(t,n))}(this,r,arguments)).onInit=function(e){var o;t._onInitialize(e),null===(o=t.onInitialize)||void 0===o||o.call(t,e)},t.onStateChanged=function(e){var o;t._onInitialize(e),null===(o=t.onChange)||void 0===o||o.call(t,e)},t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}(r,t),n=r,Object.defineProperty(n,"prototype",{writable:!1}),n;var n}(r(778).GlobalStore);t.GlobalStoreAbstract=u,t.default=u})(),n;
|
|
35
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./GlobalStore.js")):"function"==typeof define&&define.amd?define(["./GlobalStore.js"],t):"object"==typeof exports?exports["react-global-state-hooks"]=t(require("./GlobalStore.js")):this["react-global-state-hooks"]=t(this["./GlobalStore.js"]);
|
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ You can also add **dependencies** to a selector. This is useful when you want to
|
|
|
101
101
|
```tsx
|
|
102
102
|
const [contacts] = useContacts(
|
|
103
103
|
(state) => state.entities.filter((item) => item.name.includes(filter)),
|
|
104
|
-
[filter]
|
|
104
|
+
[filter],
|
|
105
105
|
);
|
|
106
106
|
```
|
|
107
107
|
|
|
@@ -141,7 +141,7 @@ You can still **use dependencies** inside a selector hook:
|
|
|
141
141
|
```tsx
|
|
142
142
|
const [filteredContacts] = useContactsArray(
|
|
143
143
|
(contacts) => contacts.filter((c) => c.name.includes(filter)),
|
|
144
|
-
[filter]
|
|
144
|
+
[filter],
|
|
145
145
|
);
|
|
146
146
|
```
|
|
147
147
|
|
|
@@ -179,7 +179,7 @@ export const useContacts = createGlobalState(
|
|
|
179
179
|
};
|
|
180
180
|
},
|
|
181
181
|
},
|
|
182
|
-
}
|
|
182
|
+
},
|
|
183
183
|
);
|
|
184
184
|
```
|
|
185
185
|
|
|
@@ -218,7 +218,7 @@ const useSelectedContact = createGlobalState(null, {
|
|
|
218
218
|
(state) => state.contacts,
|
|
219
219
|
(contacts) => {
|
|
220
220
|
if (!contacts.has(getState())) setState(null);
|
|
221
|
-
}
|
|
221
|
+
},
|
|
222
222
|
);
|
|
223
223
|
},
|
|
224
224
|
},
|
|
@@ -325,7 +325,7 @@ const useData = createGlobalState(
|
|
|
325
325
|
return state.value === previousState.value;
|
|
326
326
|
},
|
|
327
327
|
},
|
|
328
|
-
}
|
|
328
|
+
},
|
|
329
329
|
);
|
|
330
330
|
```
|
|
331
331
|
|
package/bundle.js
CHANGED
|
@@ -1 +1,62 @@
|
|
|
1
|
-
var e,t;e=this,t=(e,t,r,o,a,n,
|
|
1
|
+
var e,t;e=this,t=(e,t,r,o,a,n,l,s,i,c)=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var u={
|
|
4
|
+
/***/78:
|
|
5
|
+
/***/t=>{t.exports=e;
|
|
6
|
+
/***/},
|
|
7
|
+
/***/361:
|
|
8
|
+
/***/e=>{e.exports=t;
|
|
9
|
+
/***/},
|
|
10
|
+
/***/487:
|
|
11
|
+
/***/e=>{e.exports=r;
|
|
12
|
+
/***/},
|
|
13
|
+
/***/623:
|
|
14
|
+
/***/e=>{e.exports=o;
|
|
15
|
+
/***/},
|
|
16
|
+
/***/670:
|
|
17
|
+
/***/e=>{e.exports=a;
|
|
18
|
+
/***/},
|
|
19
|
+
/***/673:
|
|
20
|
+
/***/e=>{e.exports=n;
|
|
21
|
+
/***/},
|
|
22
|
+
/***/683:
|
|
23
|
+
/***/e=>{e.exports=l;
|
|
24
|
+
/***/},
|
|
25
|
+
/***/778:
|
|
26
|
+
/***/e=>{e.exports=s;
|
|
27
|
+
/***/},
|
|
28
|
+
/***/804:
|
|
29
|
+
/***/e=>{e.exports=i;
|
|
30
|
+
/***/},
|
|
31
|
+
/***/959:
|
|
32
|
+
/***/e=>{e.exports=c;
|
|
33
|
+
/***/}
|
|
34
|
+
/******/},b={};
|
|
35
|
+
/************************************************************************/
|
|
36
|
+
/******/
|
|
37
|
+
/******/
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/function j(e){
|
|
41
|
+
/******/
|
|
42
|
+
/******/var t=b[e];
|
|
43
|
+
/******/if(void 0!==t)
|
|
44
|
+
/******/return t.exports;
|
|
45
|
+
/******/
|
|
46
|
+
/******/
|
|
47
|
+
/******/var r=b[e]={
|
|
48
|
+
/******/
|
|
49
|
+
/******/
|
|
50
|
+
/******/exports:{}
|
|
51
|
+
/******/};
|
|
52
|
+
/******/
|
|
53
|
+
/******/
|
|
54
|
+
/******/
|
|
55
|
+
/******/
|
|
56
|
+
/******/
|
|
57
|
+
/******/return u[e](r,r.exports,j),r.exports;
|
|
58
|
+
/******/}
|
|
59
|
+
/******/
|
|
60
|
+
/************************************************************************/var g={};
|
|
61
|
+
/******/return(()=>{var e=g;Object.defineProperty(e,"__esModule",{value:!0}),e.setLocalStorageItem=e.getLocalStorageItem=e.createGlobalState=e.GlobalStoreAbstract=e.GlobalStore=e.createContext=e.isRecord=e.throwWrongKeyOnActionCollectionConfig=e.uniqueId=e.shallowCompare=void 0;var t=j(673);Object.defineProperty(e,"shallowCompare",{enumerable:!0,get:function(){return t.shallowCompare}});var r=j(78);Object.defineProperty(e,"uniqueId",{enumerable:!0,get:function(){return r.uniqueId}});var o=j(361);Object.defineProperty(e,"throwWrongKeyOnActionCollectionConfig",{enumerable:!0,get:function(){return o.throwWrongKeyOnActionCollectionConfig}});var a=j(487);Object.defineProperty(e,"isRecord",{enumerable:!0,get:function(){return a.isRecord}});var n=j(623);Object.defineProperty(e,"createContext",{enumerable:!0,get:function(){return n.createContext}});var l=j(778);Object.defineProperty(e,"GlobalStore",{enumerable:!0,get:function(){return l.GlobalStore}});var s=j(804);Object.defineProperty(e,"GlobalStoreAbstract",{enumerable:!0,get:function(){return s.GlobalStoreAbstract}});var i=j(670);Object.defineProperty(e,"createGlobalState",{enumerable:!0,get:function(){return i.createGlobalState}});var c=j(959);Object.defineProperty(e,"getLocalStorageItem",{enumerable:!0,get:function(){return c.getLocalStorageItem}});var u=j(683);Object.defineProperty(e,"setLocalStorageItem",{enumerable:!0,get:function(){return u.setLocalStorageItem}})})(),g;
|
|
62
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./uniqueId.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./isRecord.js"),require("./createContext.js"),require("./createGlobalState.js"),require("./shallowCompare.js"),require("./setLocalStorageItem.js"),require("./GlobalStore.js"),require("./GlobalStoreAbstract.js"),require("./getLocalStorageItem.js")):"function"==typeof define&&define.amd?define(["./uniqueId.js","./throwWrongKeyOnActionCollectionConfig.js","./isRecord.js","./createContext.js","./createGlobalState.js","./shallowCompare.js","./setLocalStorageItem.js","./GlobalStore.js","./GlobalStoreAbstract.js","./getLocalStorageItem.js"],t):"object"==typeof exports?exports["react-global-state-hooks"]=t(require("./uniqueId.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./isRecord.js"),require("./createContext.js"),require("./createGlobalState.js"),require("./shallowCompare.js"),require("./setLocalStorageItem.js"),require("./GlobalStore.js"),require("./GlobalStoreAbstract.js"),require("./getLocalStorageItem.js")):e["react-global-state-hooks"]=t(e["./uniqueId.js"],e["./throwWrongKeyOnActionCollectionConfig.js"],e["./isRecord.js"],e["./createContext.js"],e["./createGlobalState.js"],e["./shallowCompare.js"],e["./setLocalStorageItem.js"],e["./GlobalStore.js"],e["./GlobalStoreAbstract.js"],e["./getLocalStorageItem.js"]);
|
package/createContext.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type
|
|
1
|
+
export { type ContextApi, type ContextProvider, type ContextHook, type InferContextApi, createContext, default, } from 'react-hooks-global-states/createContext';
|
package/createContext.js
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
var e;e=e
|
|
1
|
+
var e;e=e=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var t={
|
|
4
|
+
/***/407:
|
|
5
|
+
/***/t=>{t.exports=e;
|
|
6
|
+
/***/}
|
|
7
|
+
/******/},o={};
|
|
8
|
+
/************************************************************************/
|
|
9
|
+
/******/
|
|
10
|
+
/******/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/function r(e){
|
|
14
|
+
/******/
|
|
15
|
+
/******/var a=o[e];
|
|
16
|
+
/******/if(void 0!==a)
|
|
17
|
+
/******/return a.exports;
|
|
18
|
+
/******/
|
|
19
|
+
/******/
|
|
20
|
+
/******/var s=o[e]={
|
|
21
|
+
/******/
|
|
22
|
+
/******/
|
|
23
|
+
/******/exports:{}
|
|
24
|
+
/******/};
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/
|
|
28
|
+
/******/
|
|
29
|
+
/******/
|
|
30
|
+
/******/return t[e](s,s.exports,r),s.exports;
|
|
31
|
+
/******/}
|
|
32
|
+
/******/
|
|
33
|
+
/************************************************************************/var a={};
|
|
34
|
+
/******/return(()=>{var e=a;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.createContext=void 0;var t=r(407);Object.defineProperty(e,"createContext",{enumerable:!0,get:function(){return t.createContext}}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return(e=t,e&&e.__esModule?e:{default:e}).default;var e}})})(),a;
|
|
35
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/createContext")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/createContext"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/createContext")):this["react-global-state-hooks"]=e(this["react-hooks-global-states/createContext"]);
|
package/createGlobalState.d.ts
CHANGED
|
@@ -1,22 +1,148 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { StateHook, BaseMetadata, ActionCollectionConfig, ActionCollectionResult, GlobalStoreCallbacks } from 'react-hooks-global-states/types';
|
|
2
3
|
export type { InferActionsType } from 'react-hooks-global-states/createGlobalState';
|
|
3
4
|
import { LocalStorageConfig } from './types';
|
|
4
5
|
export interface CreateGlobalState {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Creates a global state hook.
|
|
8
|
+
* @param state initial state value
|
|
9
|
+
* @returns a state hook for your components
|
|
10
|
+
* @example
|
|
11
|
+
* const useCounter = createGlobalState(0);
|
|
12
|
+
*
|
|
13
|
+
* function Counter() {
|
|
14
|
+
* const [count, setCount] = useCounter();
|
|
15
|
+
* return (
|
|
16
|
+
* <div>
|
|
17
|
+
* <p>Count: {count}</p>
|
|
18
|
+
* <button onClick={() =>
|
|
19
|
+
* setCount(prev => prev + 1)
|
|
20
|
+
* }>Increment</button>
|
|
21
|
+
* </div>
|
|
22
|
+
* );
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
<State>(state: State): StateHook<State, React.Dispatch<React.SetStateAction<State>>, React.Dispatch<React.SetStateAction<State>>, BaseMetadata>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a global state hook that you can use across your application
|
|
28
|
+
* @param state initial state value
|
|
29
|
+
* @param args additional configuration for the global state
|
|
30
|
+
* @param args.name optional name for debugging purposes
|
|
31
|
+
* @param args.metadata optional non-reactive metadata associated with the state
|
|
32
|
+
* @param args.callbacks optional lifecycle callbacks for the global state
|
|
33
|
+
* @param args.actions optional actions to restrict state mutations [if provided `setState` will be nullified]
|
|
34
|
+
* @param args.localStorage optional configuration to persist the state in local storage
|
|
35
|
+
* @returns a state hook that you can use in your components
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* const useCounter = createGlobalState(0, {
|
|
40
|
+
* actions: {
|
|
41
|
+
* increase() {
|
|
42
|
+
* return ({ setState }) => {
|
|
43
|
+
* setState((c) => c + 1);
|
|
44
|
+
* };
|
|
45
|
+
* },
|
|
46
|
+
* decrease(amount: number) {
|
|
47
|
+
* return ({ setState }) => {
|
|
48
|
+
* setState((c) => c - amount);
|
|
49
|
+
* };
|
|
50
|
+
* },
|
|
51
|
+
* },
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* function Counter() {
|
|
55
|
+
* const [count, {
|
|
56
|
+
* increase,
|
|
57
|
+
* decrease
|
|
58
|
+
* }] = useCounter();
|
|
59
|
+
*
|
|
60
|
+
* return (
|
|
61
|
+
* <div>
|
|
62
|
+
* <p>Count: {count}</p>
|
|
63
|
+
* <button onClick={increase}>
|
|
64
|
+
* Increment
|
|
65
|
+
* </button>
|
|
66
|
+
* <button onClick={() => {
|
|
67
|
+
* decrease(1);
|
|
68
|
+
* }}>
|
|
69
|
+
* Decrement
|
|
70
|
+
* </button>
|
|
71
|
+
* </div>
|
|
72
|
+
* );
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>, StateDispatch = React.Dispatch<React.SetStateAction<State>>>(state: State, args: {
|
|
7
77
|
name?: string;
|
|
8
78
|
metadata?: Metadata;
|
|
9
79
|
callbacks?: GlobalStoreCallbacks<State, Metadata>;
|
|
10
80
|
actions?: ActionsConfig;
|
|
11
81
|
localStorage?: LocalStorageConfig;
|
|
12
|
-
}): StateHook<State, PublicStateMutator, Metadata>;
|
|
13
|
-
|
|
82
|
+
}): StateHook<State, StateDispatch, PublicStateMutator, Metadata>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a global state hook that you can use across your application
|
|
85
|
+
* @param state initial state value
|
|
86
|
+
* @param args additional configuration for the global state
|
|
87
|
+
* @param args.name optional name for debugging purposes
|
|
88
|
+
* @param args.metadata optional non-reactive metadata associated with the state
|
|
89
|
+
* @param args.callbacks optional lifecycle callbacks for the global state
|
|
90
|
+
* @param args.actions optional actions to restrict state mutations [if provided `setState` will be nullified]
|
|
91
|
+
* @param args.localStorage optional configuration to persist the state in local storage
|
|
92
|
+
* @returns a state hook that you can use in your components
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* const useCounter = createGlobalState(0, {
|
|
97
|
+
* actions: {
|
|
98
|
+
* increase() {
|
|
99
|
+
* return ({ setState }) => {
|
|
100
|
+
* setState((c) => c + 1);
|
|
101
|
+
* };
|
|
102
|
+
* },
|
|
103
|
+
* decrease(amount: number) {
|
|
104
|
+
* return ({ setState }) => {
|
|
105
|
+
* setState((c) => c - amount);
|
|
106
|
+
* };
|
|
107
|
+
* },
|
|
108
|
+
* },
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* function Counter() {
|
|
112
|
+
* const [count, {
|
|
113
|
+
* increase,
|
|
114
|
+
* decrease
|
|
115
|
+
* }] = useCounter();
|
|
116
|
+
*
|
|
117
|
+
* return (
|
|
118
|
+
* <div>
|
|
119
|
+
* <p>Count: {count}</p>
|
|
120
|
+
* <button onClick={increase}>
|
|
121
|
+
* Increment
|
|
122
|
+
* </button>
|
|
123
|
+
* <button onClick={() => {
|
|
124
|
+
* decrease(1);
|
|
125
|
+
* }}>
|
|
126
|
+
* Decrement
|
|
127
|
+
* </button>
|
|
128
|
+
* </div>
|
|
129
|
+
* );
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata>, StateDispatch = React.Dispatch<React.SetStateAction<State>>>(state: State, args: {
|
|
14
134
|
name?: string;
|
|
15
135
|
metadata?: Metadata;
|
|
16
136
|
callbacks?: GlobalStoreCallbacks<State, Metadata>;
|
|
17
137
|
actions: ActionsConfig;
|
|
18
138
|
localStorage?: LocalStorageConfig;
|
|
19
|
-
}): StateHook<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
|
|
139
|
+
}): StateHook<State, StateDispatch, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
|
|
20
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a global state hook.
|
|
143
|
+
* @param state - The initial state value.
|
|
144
|
+
* @param args - Optional configuration arguments.
|
|
145
|
+
* @returns A state hook for managing the global state, the hook also embeds the state api methods.
|
|
146
|
+
*/
|
|
21
147
|
export declare const createGlobalState: CreateGlobalState;
|
|
22
148
|
export default createGlobalState;
|
package/createGlobalState.js
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
var e;e=e
|
|
1
|
+
var e;e=e=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var t={
|
|
4
|
+
/***/778:
|
|
5
|
+
/***/t=>{t.exports=e;
|
|
6
|
+
/***/},
|
|
7
|
+
/***/840:
|
|
8
|
+
/***/(e,t,o)=>{function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(n=function(){return!!e})()}Object.defineProperty(t,"__esModule",{value:!0}),t.createGlobalState=void 0;var a=o(778);
|
|
9
|
+
/**
|
|
10
|
+
* Creates a global state hook.
|
|
11
|
+
* @param state - The initial state value.
|
|
12
|
+
* @param args - Optional configuration arguments.
|
|
13
|
+
* @returns A state hook for managing the global state, the hook also embeds the state api methods.
|
|
14
|
+
*/t.createGlobalState=function(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];return function(e,t,o){if(n())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,t);var l=new(e.bind.apply(e,a));return o&&r(l,o.prototype),l}(a.GlobalStore,t).use},t.default=t.createGlobalState}
|
|
15
|
+
/******/},o={};
|
|
16
|
+
/************************************************************************/
|
|
17
|
+
/******/
|
|
18
|
+
/******/
|
|
19
|
+
/******/
|
|
20
|
+
/******/
|
|
21
|
+
/******/
|
|
22
|
+
/******/
|
|
23
|
+
/******/return function e(r){
|
|
24
|
+
/******/
|
|
25
|
+
/******/var n=o[r];
|
|
26
|
+
/******/if(void 0!==n)
|
|
27
|
+
/******/return n.exports;
|
|
28
|
+
/******/
|
|
29
|
+
/******/
|
|
30
|
+
/******/var a=o[r]={
|
|
31
|
+
/******/
|
|
32
|
+
/******/
|
|
33
|
+
/******/exports:{}
|
|
34
|
+
/******/};
|
|
35
|
+
/******/
|
|
36
|
+
/******/
|
|
37
|
+
/******/
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/return t[r](a,a.exports,e),a.exports;
|
|
41
|
+
/******/}
|
|
42
|
+
/******/
|
|
43
|
+
/************************************************************************/
|
|
44
|
+
/******/
|
|
45
|
+
/******/
|
|
46
|
+
/******/
|
|
47
|
+
/******/
|
|
48
|
+
/******/(840);
|
|
49
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./GlobalStore.js")):"function"==typeof define&&define.amd?define(["./GlobalStore.js"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("./GlobalStore.js")):this["react-global-state-hooks"]=e(this["./GlobalStore.js"]);
|
package/getLocalStorageItem.js
CHANGED
|
@@ -1 +1,43 @@
|
|
|
1
|
-
var t;t=t
|
|
1
|
+
var t;t=t=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var e={
|
|
4
|
+
/***/330:
|
|
5
|
+
/***/e=>{e.exports=t;
|
|
6
|
+
/***/},
|
|
7
|
+
/***/527:
|
|
8
|
+
/***/(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getLocalStorageItem=void 0;var o=r(330);e.getLocalStorageItem=function(t){var e=t.key;if(!e)return null;var r="function"==typeof e?e():e,a=localStorage.getItem(r);if(null===a)return null;var n=t.decrypt||t.encrypt?"function"==typeof t.decrypt?t.decrypt(a):atob(a):a;return(0,o.formatFromStore)(n,{jsonParse:!0})},e.default=e.getLocalStorageItem}
|
|
9
|
+
/******/},r={};
|
|
10
|
+
/************************************************************************/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/
|
|
14
|
+
/******/
|
|
15
|
+
/******/
|
|
16
|
+
/******/
|
|
17
|
+
/******/return function t(o){
|
|
18
|
+
/******/
|
|
19
|
+
/******/var a=r[o];
|
|
20
|
+
/******/if(void 0!==a)
|
|
21
|
+
/******/return a.exports;
|
|
22
|
+
/******/
|
|
23
|
+
/******/
|
|
24
|
+
/******/var n=r[o]={
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/exports:{}
|
|
28
|
+
/******/};
|
|
29
|
+
/******/
|
|
30
|
+
/******/
|
|
31
|
+
/******/
|
|
32
|
+
/******/
|
|
33
|
+
/******/
|
|
34
|
+
/******/return e[o](n,n.exports,t),n.exports;
|
|
35
|
+
/******/}
|
|
36
|
+
/******/
|
|
37
|
+
/************************************************************************/
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/
|
|
41
|
+
/******/
|
|
42
|
+
/******/(527);
|
|
43
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("json-storage-formatter/formatFromStore")):"function"==typeof define&&define.amd?define(["json-storage-formatter/formatFromStore"],t):"object"==typeof exports?exports["react-global-state-hooks"]=t(require("json-storage-formatter/formatFromStore")):this["react-global-state-hooks"]=t(this["json-storage-formatter/formatFromStore"]);
|
package/index.d.ts
CHANGED
|
@@ -2,18 +2,15 @@
|
|
|
2
2
|
* By handling the same structure as the original library,
|
|
3
3
|
* We can add the specific overrides for web while keeping the modularity of the library.
|
|
4
4
|
*/
|
|
5
|
-
export type {
|
|
5
|
+
export type { StateApi, ObservableFragment, MetadataSetter, StateChanges, StoreTools, ActionCollectionResult, GlobalStoreCallbacks, UseHookConfig, UnsubscribeCallback, SubscribeCallbackConfig, SubscribeCallback, BaseMetadata, MetadataGetter, SelectorCallback, SubscriberParameters, SubscriptionCallback, StateHook, ActionCollectionConfig, } from './types';
|
|
6
6
|
export { shallowCompare } from './shallowCompare';
|
|
7
7
|
export { uniqueId } from './uniqueId';
|
|
8
8
|
export { throwWrongKeyOnActionCollectionConfig } from './throwWrongKeyOnActionCollectionConfig';
|
|
9
9
|
export { isRecord } from './isRecord';
|
|
10
|
-
export {
|
|
11
|
-
export { type Context, type ContextProvider, type ContextHook, type CreateContext, type InferContextType, createContext, } from './createContext';
|
|
10
|
+
export { type ContextApi, type ContextProvider, type ContextHook, type InferContextApi, createContext, } from './createContext';
|
|
12
11
|
export { type LocalStorageConfig } from './types';
|
|
13
12
|
export { GlobalStore } from './GlobalStore';
|
|
14
13
|
export { GlobalStoreAbstract } from './GlobalStoreAbstract';
|
|
15
|
-
export {
|
|
16
|
-
export { createCustomGlobalState, CustomCreateGlobalState } from './createCustomGlobalState';
|
|
14
|
+
export { createGlobalState, type InferActionsType } from './createGlobalState';
|
|
17
15
|
export { getLocalStorageItem } from './getLocalStorageItem';
|
|
18
16
|
export { setLocalStorageItem } from './setLocalStorageItem';
|
|
19
|
-
export { generateStackHash } from './generateStackHash';
|
package/isRecord.js
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
var e;e=e
|
|
1
|
+
var e;e=e=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var t={
|
|
4
|
+
/***/93:
|
|
5
|
+
/***/t=>{t.exports=e;
|
|
6
|
+
/***/}
|
|
7
|
+
/******/},o={};
|
|
8
|
+
/************************************************************************/
|
|
9
|
+
/******/
|
|
10
|
+
/******/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/function r(e){
|
|
14
|
+
/******/
|
|
15
|
+
/******/var s=o[e];
|
|
16
|
+
/******/if(void 0!==s)
|
|
17
|
+
/******/return s.exports;
|
|
18
|
+
/******/
|
|
19
|
+
/******/
|
|
20
|
+
/******/var a=o[e]={
|
|
21
|
+
/******/
|
|
22
|
+
/******/
|
|
23
|
+
/******/exports:{}
|
|
24
|
+
/******/};
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/
|
|
28
|
+
/******/
|
|
29
|
+
/******/
|
|
30
|
+
/******/return t[e](a,a.exports,r),a.exports;
|
|
31
|
+
/******/}
|
|
32
|
+
/******/
|
|
33
|
+
/************************************************************************/var s={};
|
|
34
|
+
/******/return(()=>{var e=s;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.isRecord=void 0;var t=r(93);Object.defineProperty(e,"isRecord",{enumerable:!0,get:function(){return t.isRecord}}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return(e=t,e&&e.__esModule?e:{default:e}).default;var e}})})(),s;
|
|
35
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/isRecord")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/isRecord"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/isRecord")):this["react-global-state-hooks"]=e(this["react-hooks-global-states/isRecord"]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-global-state-hooks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "This is a package to easily handling global-state across your react components No-redux, No-context.",
|
|
5
5
|
"main": "./bundle.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -26,11 +26,6 @@
|
|
|
26
26
|
"require": "./GlobalStoreAbstract.js",
|
|
27
27
|
"types": "./GlobalStoreAbstract.d.ts"
|
|
28
28
|
},
|
|
29
|
-
"./createCustomGlobalState": {
|
|
30
|
-
"import": "./createCustomGlobalState.js",
|
|
31
|
-
"require": "./createCustomGlobalState.js",
|
|
32
|
-
"types": "./createCustomGlobalState.d.ts"
|
|
33
|
-
},
|
|
34
29
|
"./createGlobalState": {
|
|
35
30
|
"import": "./createGlobalState.js",
|
|
36
31
|
"require": "./createGlobalState.js",
|
|
@@ -70,16 +65,6 @@
|
|
|
70
65
|
"import": "./uniqueId.js",
|
|
71
66
|
"require": "./uniqueId.js",
|
|
72
67
|
"types": "./uniqueId.d.ts"
|
|
73
|
-
},
|
|
74
|
-
"./useStableState": {
|
|
75
|
-
"import": "./useStableState.js",
|
|
76
|
-
"require": "./useStableState.js",
|
|
77
|
-
"types": "./useStableState.d.ts"
|
|
78
|
-
},
|
|
79
|
-
"./generateStackHash": {
|
|
80
|
-
"import": "./generateStackHash.js",
|
|
81
|
-
"require": "./generateStackHash.js",
|
|
82
|
-
"types": "./generateStackHash.d.ts"
|
|
83
68
|
}
|
|
84
69
|
},
|
|
85
70
|
"files": [
|
|
@@ -94,7 +79,8 @@
|
|
|
94
79
|
"prepare": "npm run build",
|
|
95
80
|
"version": "npm run format && git add -A src",
|
|
96
81
|
"postversion": "git push && git push --tags",
|
|
97
|
-
"clean": "find . -maxdepth 1 -type f \\( -name '*.js' -o -name '*.d.ts' \\) ! -name 'webpack.config.js' -exec rm {} +"
|
|
82
|
+
"clean": "find . -maxdepth 1 -type f \\( -name '*.js' -o -name '*.d.ts' \\) ! -name 'webpack.config.js' -exec rm {} +",
|
|
83
|
+
"format": "prettier --write ."
|
|
98
84
|
},
|
|
99
85
|
"repository": {
|
|
100
86
|
"type": "git",
|
|
@@ -147,6 +133,7 @@
|
|
|
147
133
|
"jest": "^29.7.0",
|
|
148
134
|
"jest-environment-jsdom": "^30.0.4",
|
|
149
135
|
"json-storage-formatter": "^2.0.9",
|
|
136
|
+
"prettier": "^3.6.2",
|
|
150
137
|
"react": "^18.2.0",
|
|
151
138
|
"react-dom": "^18.2.0",
|
|
152
139
|
"ts-jest": "^29.1.1",
|
|
@@ -161,6 +148,6 @@
|
|
|
161
148
|
"react": ">=18.0.0"
|
|
162
149
|
},
|
|
163
150
|
"dependencies": {
|
|
164
|
-
"react-hooks-global-states": "^
|
|
151
|
+
"react-hooks-global-states": "^11.0.0"
|
|
165
152
|
}
|
|
166
153
|
}
|
package/setLocalStorageItem.js
CHANGED
|
@@ -1 +1,43 @@
|
|
|
1
|
-
var t;t=t
|
|
1
|
+
var t;t=t=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var e={
|
|
4
|
+
/***/339:
|
|
5
|
+
/***/(t,e,o)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.setLocalStorageItem=void 0;var r=o(413);e.setLocalStorageItem=function(t,e){var o=e.key;if(o){var a="function"==typeof o?o():o,s=(0,r.formatToStore)(t,{stringify:!0,excludeTypes:["function"]}),f=e.encrypt?"function"==typeof e.encrypt?e.encrypt(s):btoa(s):s;localStorage.setItem(a,f)}},e.default=e.setLocalStorageItem},
|
|
6
|
+
/***/413:
|
|
7
|
+
/***/e=>{e.exports=t;
|
|
8
|
+
/***/}
|
|
9
|
+
/******/},o={};
|
|
10
|
+
/************************************************************************/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/
|
|
14
|
+
/******/
|
|
15
|
+
/******/
|
|
16
|
+
/******/
|
|
17
|
+
/******/return function t(r){
|
|
18
|
+
/******/
|
|
19
|
+
/******/var a=o[r];
|
|
20
|
+
/******/if(void 0!==a)
|
|
21
|
+
/******/return a.exports;
|
|
22
|
+
/******/
|
|
23
|
+
/******/
|
|
24
|
+
/******/var s=o[r]={
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/exports:{}
|
|
28
|
+
/******/};
|
|
29
|
+
/******/
|
|
30
|
+
/******/
|
|
31
|
+
/******/
|
|
32
|
+
/******/
|
|
33
|
+
/******/
|
|
34
|
+
/******/return e[r](s,s.exports,t),s.exports;
|
|
35
|
+
/******/}
|
|
36
|
+
/******/
|
|
37
|
+
/************************************************************************/
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/
|
|
41
|
+
/******/
|
|
42
|
+
/******/(339);
|
|
43
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("json-storage-formatter/formatToStore")):"function"==typeof define&&define.amd?define(["json-storage-formatter/formatToStore"],t):"object"==typeof exports?exports["react-global-state-hooks"]=t(require("json-storage-formatter/formatToStore")):this["react-global-state-hooks"]=t(this["json-storage-formatter/formatToStore"]);
|
package/shallowCompare.js
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
var e;e=e
|
|
1
|
+
var e;e=e=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var o={
|
|
4
|
+
/***/859:
|
|
5
|
+
/***/o=>{o.exports=e;
|
|
6
|
+
/***/}
|
|
7
|
+
/******/},t={};
|
|
8
|
+
/************************************************************************/
|
|
9
|
+
/******/
|
|
10
|
+
/******/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/function r(e){
|
|
14
|
+
/******/
|
|
15
|
+
/******/var a=t[e];
|
|
16
|
+
/******/if(void 0!==a)
|
|
17
|
+
/******/return a.exports;
|
|
18
|
+
/******/
|
|
19
|
+
/******/
|
|
20
|
+
/******/var s=t[e]={
|
|
21
|
+
/******/
|
|
22
|
+
/******/
|
|
23
|
+
/******/exports:{}
|
|
24
|
+
/******/};
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/
|
|
28
|
+
/******/
|
|
29
|
+
/******/
|
|
30
|
+
/******/return o[e](s,s.exports,r),s.exports;
|
|
31
|
+
/******/}
|
|
32
|
+
/******/
|
|
33
|
+
/************************************************************************/var a={};
|
|
34
|
+
/******/return(()=>{var e=a;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.shallowCompare=void 0;var o=r(859);Object.defineProperty(e,"shallowCompare",{enumerable:!0,get:function(){return o.shallowCompare}}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return(e=o,e&&e.__esModule?e:{default:e}).default;var e}})})(),a;
|
|
35
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/shallowCompare")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/shallowCompare"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/shallowCompare")):this["react-global-state-hooks"]=e(this["react-hooks-global-states/shallowCompare"]);
|
|
@@ -1 +1,35 @@
|
|
|
1
|
-
var e;e=e
|
|
1
|
+
var e;e=e=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var o={
|
|
4
|
+
/***/637:
|
|
5
|
+
/***/o=>{o.exports=e;
|
|
6
|
+
/***/}
|
|
7
|
+
/******/},t={};
|
|
8
|
+
/************************************************************************/
|
|
9
|
+
/******/
|
|
10
|
+
/******/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/function r(e){
|
|
14
|
+
/******/
|
|
15
|
+
/******/var n=t[e];
|
|
16
|
+
/******/if(void 0!==n)
|
|
17
|
+
/******/return n.exports;
|
|
18
|
+
/******/
|
|
19
|
+
/******/
|
|
20
|
+
/******/var i=t[e]={
|
|
21
|
+
/******/
|
|
22
|
+
/******/
|
|
23
|
+
/******/exports:{}
|
|
24
|
+
/******/};
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/
|
|
28
|
+
/******/
|
|
29
|
+
/******/
|
|
30
|
+
/******/return o[e](i,i.exports,r),i.exports;
|
|
31
|
+
/******/}
|
|
32
|
+
/******/
|
|
33
|
+
/************************************************************************/var n={};
|
|
34
|
+
/******/return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.throwWrongKeyOnActionCollectionConfig=void 0;var o=r(637);Object.defineProperty(e,"throwWrongKeyOnActionCollectionConfig",{enumerable:!0,get:function(){return o.throwWrongKeyOnActionCollectionConfig}}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return(e=o,e&&e.__esModule?e:{default:e}).default;var e}})})(),n;
|
|
35
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/throwWrongKeyOnActionCollectionConfig")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/throwWrongKeyOnActionCollectionConfig"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/throwWrongKeyOnActionCollectionConfig")):this["react-global-state-hooks"]=e(this["react-hooks-global-states/throwWrongKeyOnActionCollectionConfig"]);
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { StateApi, ObservableFragment, MetadataSetter, StateChanges, StoreTools, ActionCollectionResult, GlobalStoreCallbacks, UseHookConfig, UnsubscribeCallback, SubscribeCallbackConfig, SubscribeCallback, BaseMetadata, MetadataGetter, SelectorCallback, SubscriberParameters, SubscriptionCallback, StateHook, ActionCollectionConfig, } from 'react-hooks-global-states/types';
|
|
2
2
|
export type LocalStorageConfig = {
|
|
3
3
|
key: string | (() => string);
|
|
4
4
|
/**
|
package/types.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
var e;e=()
|
|
1
|
+
var e;e=()=>/******/(()=>{
|
|
2
|
+
/******/"use strict";var e={};
|
|
3
|
+
/******/return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0})})(),e;
|
|
4
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["react-global-state-hooks"]=e():this["react-global-state-hooks"]=e();
|
package/uniqueId.js
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
var e;e=e
|
|
1
|
+
var e;e=e=>/******/(()=>{
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var t={
|
|
4
|
+
/***/366:
|
|
5
|
+
/***/t=>{t.exports=e;
|
|
6
|
+
/***/}
|
|
7
|
+
/******/},o={};
|
|
8
|
+
/************************************************************************/
|
|
9
|
+
/******/
|
|
10
|
+
/******/
|
|
11
|
+
/******/
|
|
12
|
+
/******/
|
|
13
|
+
/******/function r(e){
|
|
14
|
+
/******/
|
|
15
|
+
/******/var u=o[e];
|
|
16
|
+
/******/if(void 0!==u)
|
|
17
|
+
/******/return u.exports;
|
|
18
|
+
/******/
|
|
19
|
+
/******/
|
|
20
|
+
/******/var a=o[e]={
|
|
21
|
+
/******/
|
|
22
|
+
/******/
|
|
23
|
+
/******/exports:{}
|
|
24
|
+
/******/};
|
|
25
|
+
/******/
|
|
26
|
+
/******/
|
|
27
|
+
/******/
|
|
28
|
+
/******/
|
|
29
|
+
/******/
|
|
30
|
+
/******/return t[e](a,a.exports,r),a.exports;
|
|
31
|
+
/******/}
|
|
32
|
+
/******/
|
|
33
|
+
/************************************************************************/var u={};
|
|
34
|
+
/******/return(()=>{var e=u;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.uniqueId=void 0;var t=r(366);Object.defineProperty(e,"uniqueId",{enumerable:!0,get:function(){return t.uniqueId}}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return(e=t,e&&e.__esModule?e:{default:e}).default;var e}})})(),u;
|
|
35
|
+
/******/})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/uniqueId")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/uniqueId"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/uniqueId")):this["react-global-state-hooks"]=e(this["react-hooks-global-states/uniqueId"]);
|
package/webpack.config.js
CHANGED
|
@@ -6,20 +6,16 @@ const individualEntries = {
|
|
|
6
6
|
createContext: './src/createContext.ts',
|
|
7
7
|
GlobalStore: './src/GlobalStore.ts',
|
|
8
8
|
GlobalStoreAbstract: './src/GlobalStoreAbstract.ts',
|
|
9
|
-
createCustomGlobalState: './src/createCustomGlobalState.ts',
|
|
10
9
|
createGlobalState: './src/createGlobalState.ts',
|
|
11
10
|
types: './src/types.ts',
|
|
12
11
|
isRecord: './src/isRecord.ts',
|
|
13
12
|
shallowCompare: './src/shallowCompare.ts',
|
|
14
13
|
throwWrongKeyOnActionCollectionConfig: './src/throwWrongKeyOnActionCollectionConfig.ts',
|
|
15
14
|
uniqueId: './src/uniqueId.ts',
|
|
16
|
-
useStableState: './src/useStableState.ts',
|
|
17
|
-
generateStackHash: './src/generateStackHash.ts',
|
|
18
15
|
|
|
19
16
|
// extras
|
|
20
17
|
getLocalStorageItem: './src/getLocalStorageItem.ts',
|
|
21
18
|
setLocalStorageItem: './src/setLocalStorageItem.ts',
|
|
22
|
-
generateStackHash: './src/generateStackHash.ts',
|
|
23
19
|
};
|
|
24
20
|
|
|
25
21
|
const getExternalsForEntries = () => {
|
|
@@ -125,8 +121,11 @@ module.exports = {
|
|
|
125
121
|
toplevel: true,
|
|
126
122
|
properties: false,
|
|
127
123
|
},
|
|
128
|
-
|
|
129
|
-
comments
|
|
124
|
+
output: {
|
|
125
|
+
// Keep only JSDoc-style comments (/** ... */)
|
|
126
|
+
comments: (_node, comment) => {
|
|
127
|
+
return comment.type === 'comment2' && comment.value.startsWith('*');
|
|
128
|
+
},
|
|
130
129
|
},
|
|
131
130
|
},
|
|
132
131
|
}),
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { BaseMetadata, StateHook, StateSetter, ActionCollectionConfig, ActionCollectionResult, GlobalStoreCallbacks, CustomGlobalHookBuilderParams } from 'react-hooks-global-states/types';
|
|
2
|
-
import { LocalStorageConfig } from './types';
|
|
3
|
-
export interface CustomCreateGlobalState<TCustomConfig extends BaseMetadata | unknown, InheritMetadata extends BaseMetadata | unknown = BaseMetadata> {
|
|
4
|
-
<State>(state: State): StateHook<State, StateSetter<State>, BaseMetadata>;
|
|
5
|
-
<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, InheritMetadata & Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, InheritMetadata & Metadata, NonNullable<ActionsConfig>>>(state: State, args: {
|
|
6
|
-
name?: string;
|
|
7
|
-
metadata?: Metadata;
|
|
8
|
-
callbacks?: GlobalStoreCallbacks<State, InheritMetadata & Metadata>;
|
|
9
|
-
actions?: ActionsConfig;
|
|
10
|
-
config?: TCustomConfig;
|
|
11
|
-
localStorage?: LocalStorageConfig;
|
|
12
|
-
}): StateHook<State, PublicStateMutator, InheritMetadata & Metadata>;
|
|
13
|
-
<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends Readonly<ActionCollectionConfig<State, InheritMetadata & Metadata>>>(state: State, args: {
|
|
14
|
-
name?: string;
|
|
15
|
-
metadata?: Metadata;
|
|
16
|
-
callbacks?: GlobalStoreCallbacks<State, InheritMetadata & Metadata>;
|
|
17
|
-
actions: ActionsConfig;
|
|
18
|
-
config?: TCustomConfig;
|
|
19
|
-
localStorage?: LocalStorageConfig;
|
|
20
|
-
}): StateHook<State, ActionCollectionResult<State, InheritMetadata & Metadata, ActionsConfig>, InheritMetadata & Metadata>;
|
|
21
|
-
}
|
|
22
|
-
export declare const createCustomGlobalState: <TCustomConfig extends BaseMetadata | unknown, InheritMetadata extends BaseMetadata | unknown = BaseMetadata>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<TCustomConfig, InheritMetadata>) => CustomCreateGlobalState<TCustomConfig, InheritMetadata>;
|
|
23
|
-
export default createCustomGlobalState;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e;e=e=>(()=>{"use strict";var t={670:t=>{t.exports=e},773:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createCustomGlobalState=void 0;var a=o(670);t.createCustomGlobalState=function(e){var t=e.onInitialize,o=e.onChange;return function(e){var l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=l.callbacks,r=function(e,t){var o={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(o[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(a=Object.getOwnPropertySymbols(e);l<a.length;l++)t.indexOf(a[l])<0&&Object.prototype.propertyIsEnumerable.call(e,a[l])&&(o[a[l]]=e[a[l]])}return o}(l,["callbacks"]);return(0,a.createGlobalState)(e,Object.assign(Object.assign({},r),{callbacks:Object.assign(Object.assign({},null!=n?n:{}),{onInit:function(e){var o;null==t||t(e,null==r?void 0:r.config),null===(o=null==n?void 0:n.onInit)||void 0===o||o.call(n,e)},onStateChanged:function(e){var t;null==o||o(e,null==r?void 0:r.config),null===(t=null==n?void 0:n.onStateChanged)||void 0===t||t.call(n,e)}})}))}},t.default=t.createCustomGlobalState}},o={};return function e(a){var l=o[a];if(void 0!==l)return l.exports;var n=o[a]={exports:{}};return t[a](n,n.exports,e),n.exports}(773)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./createGlobalState.js")):"function"==typeof define&&define.amd?define(["./createGlobalState.js"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("./createGlobalState.js")):this["react-global-state-hooks"]=e(this["./createGlobalState.js"]);
|
package/generateStackHash.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { generateStackHash, default } from 'react-hooks-global-states/generateStackHash';
|
package/generateStackHash.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e;e=e=>(()=>{"use strict";var t={225:t=>{t.exports=e}},a={};function r(e){var o=a[e];if(void 0!==o)return o.exports;var s=a[e]={exports:{}};return t[e](s,s.exports,r),s.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.generateStackHash=void 0;var t=r(225);Object.defineProperty(e,"generateStackHash",{enumerable:!0,get:function(){return t.generateStackHash}}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return(e=t,e&&e.__esModule?e:{default:e}).default;var e}})})(),o})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/generateStackHash")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/generateStackHash"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/generateStackHash")):this["react-global-state-hooks"]=e(this["react-hooks-global-states/generateStackHash"]);
|
package/useStableState.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useStableState, default } from 'react-hooks-global-states/useStableState';
|
package/useStableState.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e;e=e=>(()=>{"use strict";var t={525:t=>{t.exports=e}},a={};function o(e){var r=a[e];if(void 0!==r)return r.exports;var s=a[e]={exports:{}};return t[e](s,s.exports,o),s.exports}var r={};return(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.useStableState=void 0;var t=o(525);Object.defineProperty(e,"useStableState",{enumerable:!0,get:function(){return t.useStableState}}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return(e=t,e&&e.__esModule?e:{default:e}).default;var e}})})(),r})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/useStableState")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/useStableState"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/useStableState")):this["react-global-state-hooks"]=e(this["react-hooks-global-states/useStableState"]);
|