react-native-global-state-hooks 2.1.18 → 2.1.20

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/README.md CHANGED
@@ -4,6 +4,8 @@ This is a package to easily handling global-state across your react-native-compo
4
4
 
5
5
  This utility uses the **useState** hook within a subscription pattern and **HOFs** to create a more intuitive, atomic and easy way of sharing state between components... You can see the introduction video [here!](https://www.youtube.com/watch?v=WfoMhO1zZ04&t=8s)
6
6
 
7
+ To see TODO-LIST with the hooks and async storage take a look here: [todo-list-with-global-hooks](https://github.com/johnny-quesada-developer/todo-list-with-global-hooks.git)
8
+
7
9
  For seen a running example of the hooks, you can check the following link: [react-global-state-hooks-example](https://johnny-quesada-developer.github.io/react-global-state-hooks-example/)
8
10
 
9
11
  ...
@@ -189,4 +189,3 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
189
189
  invokerSetState?: React.Dispatch<React.SetStateAction<TState>>;
190
190
  }) => ActionCollectionResult<TState, TMetadata, TStateSetter>;
191
191
  }
192
- //# sourceMappingURL=GlobalStore.d.ts.map
@@ -106,4 +106,3 @@ export type GlobalStoreConfig<TState, TMetadata, TStateSetter extends ActionColl
106
106
  onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
107
107
  computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TStateSetter>) => boolean;
108
108
  } | null;
109
- //# sourceMappingURL=GlobalStore.types.d.ts.map
package/lib/bundle.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see bundle.js.LICENSE.txt */
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["react-native-global-state-hooks"]=e():t["react-native-global-state-hooks"]=e()}(this,(()=>(()=>{"use strict";var t={774:(t,e,r)=>{function n(t){return n="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},n(t)}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}function i(t){var e=function(t,e){if("object"!==n(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===n(e)?e:String(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStore=e.formatToStore=e.formatFromStore=void 0;var u=r(789);Object.defineProperty(e,"formatFromStore",{enumerable:!0,get:function(){return u.formatFromStore}}),Object.defineProperty(e,"formatToStore",{enumerable:!0,get:function(){return u.formatToStore}});var s=r(789),c=r(294),l=function(){function t(e){var r=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.state=e,this.setterConfig=a,this.subscribers=new Set,this.config={metadata:null},this.onInit=null,this.onStateChanged=null,this.onSubscribed=null,this.computePreventStateChange=null,this.onInitializeStore=function(){var t=r.onInit,e=r.config.onInit;if(t||e){var n=r.getConfigCallbackParam({});null==t||t(n),null==e||e(n)}},this.getStateClone=function(){return(0,s.clone)(r.state)},this.getMetadataClone=function(){var t,e;return(0,s.clone)(null!==(e=null===(t=r.config)||void 0===t?void 0:t.metadata)&&void 0!==e?e:null)},this.setState=function(t){var e=t.invokerSetState,n=t.state;r.state=n,null==e||e(n),r.subscribers.forEach((function(t){t!==e&&t(n)}))},this.setMetadata=function(t){var e,n="function"==typeof t?t(r.getMetadataClone()):t;r.config=Object.assign(Object.assign({},null!==(e=r.config)&&void 0!==e?e:{}),{metadata:n})},this.getConfigCallbackParam=function(t){var e=t.invokerSetState;return{setMetadata:r.setMetadata,getMetadata:r.getMetadataClone,getState:r.getStateClone,setState:r.getSetStateWrapper({invokerSetState:e}),actions:r.getStoreActionsMap({})}},this.getHook=function(){return function(){var t,e,n=(t=(0,c.useState)((function(){return r.state})),e=2,function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,a,i,u=[],s=!0,c=!1;try{if(a=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=a.call(r)).done)&&(u.push(n.value),u.length!==e);s=!0);}catch(t){c=!0,o=t}finally{try{if(!s&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),a=n[0],i=n[1];return(0,c.useEffect)((function(){r.subscribers.add(i);var t=r.onSubscribed,e=r.config.onSubscribed;if(t||e){var n=r.getConfigCallbackParam({invokerSetState:i});null==t||t(n),null==e||e(n)}return function(){r.subscribers.delete(i)}}),[]),[a,r.getStateOrchestrator(i),r.getMetadataClone()]}},this.getHookDecoupled=function(){var t=r.getStateClone,e=r.getMetadataClone;return[t,r.getStateOrchestrator(),e]},this.getSetStateWrapper=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;return function(e){r.computeSetState({invokerSetState:t,setter:e})}},this.hasStateCallbacks=function(){var t=r.computePreventStateChange,e=r.onStateChanged,n=r.config,o=n.computePreventStateChange,a=n.onStateChanged;return!!(t||o||e||a)},this.computeSetState=function(t){var e=t.setter,n=t.invokerSetState,o="function"==typeof e,a=r.getStateClone(),i=o?e(a):e,u=r.hasStateCallbacks(),s=u&&r.getStoreActionsMap({}),c=u&&r.getSetStateWrapper({invokerSetState:n}),l={setMetadata:r.setMetadata,getMetadata:r.getMetadataClone,setState:c,getState:r.getStateClone,actions:s,previousState:a,state:i},f=r.computePreventStateChange,p=r.config.computePreventStateChange;if(!f&&!p||!(null==f?void 0:f(l))&&!(null==p?void 0:p(l))){r.setState({invokerSetState:n,state:i});var y=r.onStateChanged,d=r.config.onStateChanged;(y||d)&&(null==y||y(l),null==d||d(l))}},this.getStoreActionsMap=function(t){var e=t.invokerSetState;if(!r.setterConfig)return null;var n=r.setterConfig,o=r.setMetadata,a=n,u=Object.keys(a),s=r.getSetStateWrapper({invokerSetState:e}),c=r.getStateClone,l=r.getMetadataClone,f=u.reduce((function(t,e){return Object.assign(Object.assign({},t),(r={},u=function(){for(var t=a[e],r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];var u=t.apply(f,n);return"function"!=typeof u&&function(t){throw new Error("[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[".concat(t,"]: key is not a valid function, try something like this: \n{\n\n ").concat(t,": (param) => ({ setState, getState, setMetadata, getMetadata }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))}(e),u.call(f,{setState:s,getState:c,setMetadata:o,getMetadata:l})},(n=i(n=e))in r?Object.defineProperty(r,n,{value:u,enumerable:!0,configurable:!0,writable:!0}):r[n]=u,r));var r,n,u}),{});return f},this.config=Object.assign({metadata:null},null!=n?n:{}),this.onInitializeStore()}var e,r;return e=t,(r=[{key:"getStateOrchestrator",value:function(t){return this.setterConfig?this.getStoreActionsMap({invokerSetState:t}):this.getSetStateWrapper({invokerSetState:t})}}])&&a(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.GlobalStore=l},530:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},991:(t,e,r)=>{var n=Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]},o=function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(530),e),o(r(774),e)},789:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatToStore=e.formatFromStore=e.isPrimitive=e.isRegex=e.isDate=e.isString=e.isBoolean=e.isNumber=e.isNil=e.clone=void 0,e.clone=t=>{if((0,e.isPrimitive)(t)||(0,e.isDate)(t))return t;if(Array.isArray(t))return t.map((t=>(0,e.clone)(t)));if(t instanceof Map){const r=Array.from(t.entries());return new Map(r.map((t=>(0,e.clone)(t))))}if(t instanceof Set){const r=Array.from(t.values());return new Set(r.map((t=>(0,e.clone)(t))))}return t instanceof RegExp?new RegExp(t.toString()):t instanceof Error?new Error(t.message):Object.keys(t).reduce(((r,n)=>{const o=t[n];return Object.assign(Object.assign({},r),{[n]:(0,e.clone)(o)})}),{})},e.isNil=t=>null==t,e.isNumber=t=>"number"==typeof t,e.isBoolean=t=>"boolean"==typeof t,e.isString=t=>"string"==typeof t,e.isDate=t=>t instanceof Date,e.isRegex=t=>t instanceof RegExp,e.isPrimitive=t=>(0,e.isNil)(t)||(0,e.isNumber)(t)||(0,e.isBoolean)(t)||(0,e.isString)(t)||"symbol"==typeof t,e.formatFromStore=t=>(t=>{var r,n;if((0,e.isPrimitive)(t))return t;if("date"===(null==t?void 0:t.$t))return new Date(t.$v);if("map"===(null==t?void 0:t.$t)){const n=(null!==(r=t.$v)&&void 0!==r?r:[]).map((([t,r])=>[t,(0,e.formatFromStore)(r)]));return new Map(n)}if("set"===(null==t?void 0:t.$t)){const r=null!==(n=t.$v)&&void 0!==n?n:[].map((t=>(0,e.formatFromStore)(t)));return new Set(r)}return"regex"===(null==t?void 0:t.$t)?new RegExp(t.$v):"error"===(null==t?void 0:t.$t)?new Error(t.$v):Array.isArray(t)?t.map((t=>(0,e.formatFromStore)(t))):Object.keys(t).reduce(((r,n)=>{const o=t[n];return Object.assign(Object.assign({},r),{[n]:(0,e.formatFromStore)(o)})}),{})})((0,e.clone)(t)),e.formatToStore=(t,{stringify:r}={stringify:!1})=>{const n=(o=(0,e.clone)(t),(0,e.isPrimitive)(o)?o:Array.isArray(o)?o.map((t=>(0,e.formatToStore)(t))):o instanceof Map?{$t:"map",$v:Array.from(o.entries()).map((t=>(0,e.formatToStore)(t)))}:o instanceof Set?{$t:"set",$v:Array.from(o.values()).map((t=>(0,e.formatToStore)(t)))}:(0,e.isDate)(o)?{$t:"date",$v:o.toISOString()}:(0,e.isRegex)(o)?{$t:"regex",$v:o.toString()}:o instanceof Error?{$t:"error",$v:o.message}:Object.keys(o).reduce(((t,r)=>{const n=o[r];return Object.assign(Object.assign({},t),{[r]:(0,e.formatToStore)(n)})}),{}));var o;return r?JSON.stringify(n):n}},408:(t,e)=>{var r=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),s=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),f=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),y=Symbol.iterator,d={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S=Object.assign,v={};function m(t,e,r){this.props=t,this.context=e,this.refs=v,this.updater=r||d}function g(){}function b(t,e,r){this.props=t,this.context=e,this.refs=v,this.updater=r||d}m.prototype.isReactComponent={},m.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},m.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},g.prototype=m.prototype;var h=b.prototype=new g;h.constructor=b,S(h,m.prototype),h.isPureReactComponent=!0;var _=Array.isArray,C=Object.prototype.hasOwnProperty,O={current:null},j={key:!0,ref:!0,__self:!0,__source:!0};function k(t,e,n){var o,a={},i=null,u=null;if(null!=e)for(o in void 0!==e.ref&&(u=e.ref),void 0!==e.key&&(i=""+e.key),e)C.call(e,o)&&!j.hasOwnProperty(o)&&(a[o]=e[o]);var s=arguments.length-2;if(1===s)a.children=n;else if(1<s){for(var c=Array(s),l=0;l<s;l++)c[l]=arguments[l+2];a.children=c}if(t&&t.defaultProps)for(o in s=t.defaultProps)void 0===a[o]&&(a[o]=s[o]);return{$$typeof:r,type:t,key:i,ref:u,props:a,_owner:O.current}}function w(t){return"object"==typeof t&&null!==t&&t.$$typeof===r}var $=/\/+/g;function E(t,e){return"object"==typeof t&&null!==t&&null!=t.key?function(t){var e={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,(function(t){return e[t]}))}(""+t.key):e.toString(36)}function P(t,e,o,a,i){var u=typeof t;"undefined"!==u&&"boolean"!==u||(t=null);var s=!1;if(null===t)s=!0;else switch(u){case"string":case"number":s=!0;break;case"object":switch(t.$$typeof){case r:case n:s=!0}}if(s)return i=i(s=t),t=""===a?"."+E(s,0):a,_(i)?(o="",null!=t&&(o=t.replace($,"$&/")+"/"),P(i,e,o,"",(function(t){return t}))):null!=i&&(w(i)&&(i=function(t,e){return{$$typeof:r,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}(i,o+(!i.key||s&&s.key===i.key?"":(""+i.key).replace($,"$&/")+"/")+t)),e.push(i)),1;if(s=0,a=""===a?".":a+":",_(t))for(var c=0;c<t.length;c++){var l=a+E(u=t[c],c);s+=P(u,e,o,l,i)}else if(l=function(t){return null===t||"object"!=typeof t?null:"function"==typeof(t=y&&t[y]||t["@@iterator"])?t:null}(t),"function"==typeof l)for(t=l.call(t),c=0;!(u=t.next()).done;)s+=P(u=u.value,e,o,l=a+E(u,c++),i);else if("object"===u)throw e=String(t),Error("Objects are not valid as a React child (found: "+("[object Object]"===e?"object with keys {"+Object.keys(t).join(", ")+"}":e)+"). If you meant to render a collection of children, use an array instead.");return s}function M(t,e,r){if(null==t)return t;var n=[],o=0;return P(t,n,"","",(function(t){return e.call(r,t,o++)})),n}function R(t){if(-1===t._status){var e=t._result;(e=e()).then((function(e){0!==t._status&&-1!==t._status||(t._status=1,t._result=e)}),(function(e){0!==t._status&&-1!==t._status||(t._status=2,t._result=e)})),-1===t._status&&(t._status=0,t._result=e)}if(1===t._status)return t._result.default;throw t._result}var x={current:null},A={transition:null},I={ReactCurrentDispatcher:x,ReactCurrentBatchConfig:A,ReactCurrentOwner:O};e.Children={map:M,forEach:function(t,e,r){M(t,(function(){e.apply(this,arguments)}),r)},count:function(t){var e=0;return M(t,(function(){e++})),e},toArray:function(t){return M(t,(function(t){return t}))||[]},only:function(t){if(!w(t))throw Error("React.Children.only expected to receive a single React element child.");return t}},e.Component=m,e.Fragment=o,e.Profiler=i,e.PureComponent=b,e.StrictMode=a,e.Suspense=l,e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=I,e.cloneElement=function(t,e,n){if(null==t)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+t+".");var o=S({},t.props),a=t.key,i=t.ref,u=t._owner;if(null!=e){if(void 0!==e.ref&&(i=e.ref,u=O.current),void 0!==e.key&&(a=""+e.key),t.type&&t.type.defaultProps)var s=t.type.defaultProps;for(c in e)C.call(e,c)&&!j.hasOwnProperty(c)&&(o[c]=void 0===e[c]&&void 0!==s?s[c]:e[c])}var c=arguments.length-2;if(1===c)o.children=n;else if(1<c){s=Array(c);for(var l=0;l<c;l++)s[l]=arguments[l+2];o.children=s}return{$$typeof:r,type:t.type,key:a,ref:i,props:o,_owner:u}},e.createContext=function(t){return(t={$$typeof:s,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null}).Provider={$$typeof:u,_context:t},t.Consumer=t},e.createElement=k,e.createFactory=function(t){var e=k.bind(null,t);return e.type=t,e},e.createRef=function(){return{current:null}},e.forwardRef=function(t){return{$$typeof:c,render:t}},e.isValidElement=w,e.lazy=function(t){return{$$typeof:p,_payload:{_status:-1,_result:t},_init:R}},e.memo=function(t,e){return{$$typeof:f,type:t,compare:void 0===e?null:e}},e.startTransition=function(t){var e=A.transition;A.transition={};try{t()}finally{A.transition=e}},e.unstable_act=function(){throw Error("act(...) is not supported in production builds of React.")},e.useCallback=function(t,e){return x.current.useCallback(t,e)},e.useContext=function(t){return x.current.useContext(t)},e.useDebugValue=function(){},e.useDeferredValue=function(t){return x.current.useDeferredValue(t)},e.useEffect=function(t,e){return x.current.useEffect(t,e)},e.useId=function(){return x.current.useId()},e.useImperativeHandle=function(t,e,r){return x.current.useImperativeHandle(t,e,r)},e.useInsertionEffect=function(t,e){return x.current.useInsertionEffect(t,e)},e.useLayoutEffect=function(t,e){return x.current.useLayoutEffect(t,e)},e.useMemo=function(t,e){return x.current.useMemo(t,e)},e.useReducer=function(t,e,r){return x.current.useReducer(t,e,r)},e.useRef=function(t){return x.current.useRef(t)},e.useState=function(t){return x.current.useState(t)},e.useSyncExternalStore=function(t,e,r){return x.current.useSyncExternalStore(t,e,r)},e.useTransition=function(){return x.current.useTransition()},e.version="18.2.0"},294:(t,e,r)=>{t.exports=r(408)}},e={};return function r(n){var o=e[n];if(void 0!==o)return o.exports;var a=e[n]={exports:{}};return t[n](a,a.exports,r),a.exports}(991)})()));
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license React
3
+ * react.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
package/lib/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './GlobalStore.types';
2
2
  export * from './GlobalStore';
3
- //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-global-state-hooks",
3
- "version": "2.1.18",
3
+ "version": "2.1.20",
4
4
  "description": "This is a package to easily handling global-state across your react-native-components No-redux",
5
5
  "main": "lib/GlobalStore.js",
6
6
  "files": [
@@ -10,7 +10,7 @@
10
10
  "test:debug": "node --inspect-brk node_modules/.bin/jest --watch --runInBand",
11
11
  "test:quick": "jest --maxWorkers=4 -c --no-watchman -u",
12
12
  "test:coverage": "jest --maxWorkers=4 -c --colors --no-watchman --verbose --coverage",
13
- "build": "tsc",
13
+ "build": "webpack --config webpack.config.js",
14
14
  "prepare": "npm run build",
15
15
  "version": "npm run format && git add -A src",
16
16
  "postversion": "git push && git push --tags",
@@ -40,6 +40,10 @@
40
40
  },
41
41
  "homepage": "https://github.com/johnny-quesada-developer/react-native-global-state-hooks#readme",
42
42
  "devDependencies": {
43
+ "@babel/core": "^7.21.3",
44
+ "@babel/plugin-transform-modules-commonjs": "^7.21.2",
45
+ "@babel/preset-env": "^7.20.2",
46
+ "@babel/preset-typescript": "^7.21.0",
43
47
  "@types/jest": "^26.0.17",
44
48
  "@types/lodash": "^4.14.165",
45
49
  "@types/react": "^17.0.0",
@@ -47,6 +51,7 @@
47
51
  "@types/react-test-renderer": "^17.0.0",
48
52
  "@typescript-eslint/eslint-plugin": "^4.9.1",
49
53
  "@typescript-eslint/parser": "^4.9.1",
54
+ "babel-loader": "^9.1.2",
50
55
  "cancelable-promise-jq": "^1.0.4",
51
56
  "eslint": "^7.15.0",
52
57
  "eslint-config-airbnb": "^18.2.1",
@@ -59,8 +64,11 @@
59
64
  "react": ">=17.0.0",
60
65
  "react-test-renderer": "^17.0.1",
61
66
  "ts-jest": "^26.4.4",
67
+ "ts-loader": "^9.4.2",
62
68
  "tslib": "^2.5.0",
63
- "typescript": "^4.9.5"
69
+ "typescript": "^4.9.5",
70
+ "webpack": "^5.76.3",
71
+ "webpack-cli": "^5.0.1"
64
72
  },
65
73
  "peerDependencies": {
66
74
  "json-storage-formatter": ">=1.0.5",
@@ -1 +0,0 @@
1
- {"version":3,"file":"GlobalStore.d.ts","sourceRoot":"","sources":["../src/GlobalStore.ts"],"names":[],"mappings":"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"}
@@ -1,324 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GlobalStore = exports.formatToStore = exports.formatFromStore = void 0;
4
- var json_storage_formatter_1 = require("json-storage-formatter");
5
- Object.defineProperty(exports, "formatFromStore", { enumerable: true, get: function () { return json_storage_formatter_1.formatFromStore; } });
6
- Object.defineProperty(exports, "formatToStore", { enumerable: true, get: function () { return json_storage_formatter_1.formatToStore; } });
7
- const json_storage_formatter_2 = require("json-storage-formatter");
8
- const react_1 = require("react");
9
- const throwWrongKeyOnActionCollectionConfig = (action_key) => {
10
- throw new Error(`[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[${action_key}]: key is not a valid function, try something like this: \n{\n
11
- ${action_key}: (param) => ({ setState, getState, setMetadata, getMetadata }) => {\n
12
- setState((state) => ({ ...state, ...param }))\n
13
- }\n
14
- }\n`);
15
- };
16
- /**
17
- * The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
18
- * @template {TState} TState - The type of the state object
19
- * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
20
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
21
- * */
22
- class GlobalStore {
23
- /**
24
- * Create a new instance of the GlobalStore
25
- * @param {TState} state - The initial state
26
- * @param {GlobalStoreConfig<TState, TMetadata>} config - The configuration object (optional) (default: { metadata: null })
27
- * @param {GlobalStoreConfig<TState, TMetadata>} config.metadata - The metadata object (optional) (default: null) if not null the metadata object will be reactive
28
- * @param {GlobalStoreConfig<TState, TMetadata>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
29
- * @param {GlobalStoreConfig<TState, TMetadata>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
30
- * @param {GlobalStoreConfig<TState, TMetadata>} config.onSubscribed - The callback to execute when a new component gets subscribed to the store (optional) (default: null)
31
- * @param {GlobalStoreConfig<TState, TMetadata>} config.computePreventStateChange - The callback to execute everytime a state change is triggered and before the state is updated, it allows to prevent the state change by returning true (optional) (default: null) * @param {TStateSetter} setterConfig - The actions configuration object (optional) (default: null) if not null the store manipulation will be done through the actions
32
- * */
33
- constructor(state, config = {}, setterConfig = null) {
34
- this.state = state;
35
- this.setterConfig = setterConfig;
36
- /**
37
- * list of all the subscribers setState functions
38
- * @template {TState} TState - The type of the state object
39
- * */
40
- this.subscribers = new Set();
41
- /**
42
- * additional configuration for the store
43
- * @template {TState} TState - The type of the state object
44
- * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
45
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
46
- * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.metadata - The metadata to pass to the callbacks (optional) (default: null)
47
- * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
48
- * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
49
- * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onSubscribed - The callback to execute when a component is subscribed to the store (optional) (default: null)
50
- * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.computePreventStateChange - The callback to execute when the state is changed to compute if the state change should be prevented (optional) (default: null)
51
- */
52
- this.config = {
53
- metadata: null,
54
- };
55
- /**
56
- * execute once the store is created
57
- * @template {TState} TState - The type of the state object
58
- * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
59
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
60
- * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
61
- * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
62
- * @param {() => TState} parameters.getState - The getState function to get the state
63
- * @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
64
- * @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
65
- * */
66
- this.onInit = null;
67
- /**
68
- * execute every time the state is changed
69
- * @template {TState} TState - The type of the state object
70
- * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
71
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
72
- * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
73
- * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
74
- * @param {() => TState} parameters.getState - The getState function to get the state
75
- * @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
76
- * @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
77
- * */
78
- this.onStateChanged = null;
79
- /**
80
- * Execute each time a new component gets subscribed to the store
81
- * @template {TState} TState - The type of the state object
82
- * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
83
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
84
- * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
85
- * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
86
- * @param {() => TState} parameters.getState - The getState function to get the state
87
- * @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
88
- * @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
89
- * */
90
- this.onSubscribed = null;
91
- /**
92
- * Execute everytime a state change is triggered and before the state is updated, it allows to prevent the state change by returning true
93
- * @template {TState} TState - The type of the state object
94
- * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
95
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
96
- * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
97
- * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
98
- * @param {() => TState} parameters.getState - The getState function to get the state
99
- * @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
100
- * @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
101
- * @returns {boolean} - true to prevent the state change, false to allow the state change
102
- * */
103
- this.computePreventStateChange = null;
104
- this.onInitializeStore = () => {
105
- const { onInit } = this;
106
- const { onInit: onInitFromConfig } = this.config;
107
- if (!onInit && !onInitFromConfig)
108
- return;
109
- const parameters = this.getConfigCallbackParam({});
110
- onInit === null || onInit === void 0 ? void 0 : onInit(parameters);
111
- onInitFromConfig === null || onInitFromConfig === void 0 ? void 0 : onInitFromConfig(parameters);
112
- };
113
- /**
114
- * gets a clone of the state
115
- * @returns {TState} - The state clone
116
- * */
117
- this.getStateClone = () => (0, json_storage_formatter_2.clone)(this.state);
118
- /**
119
- * gets a clone of the metadata
120
- * @returns {TMetadata} - The metadata clone
121
- * */
122
- this.getMetadataClone = () => { var _a, _b; return (0, json_storage_formatter_2.clone)((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.metadata) !== null && _b !== void 0 ? _b : null); };
123
- /**
124
- * set the state and update all the subscribers
125
- * @param {StateSetter<TState>} setter - The setter function or the value to set
126
- * @param {React.Dispatch<React.SetStateAction<TState>>} invokerSetState - The setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
127
- * */
128
- this.setState = ({ invokerSetState, state, }) => {
129
- // update the state
130
- this.state = state;
131
- // execute first the callback of the component that invoked the state change
132
- invokerSetState === null || invokerSetState === void 0 ? void 0 : invokerSetState(state);
133
- // update all the subscribers
134
- this.subscribers.forEach((setState) => {
135
- if (setState === invokerSetState)
136
- return;
137
- setState(state);
138
- });
139
- };
140
- /**
141
- * Set the value of the metadata property, this is no reactive and will not trigger a re-render
142
- * @param {StateSetter<TMetadata>} setter - The setter function or the value to set
143
- * */
144
- this.setMetadata = (setter) => {
145
- var _a;
146
- const isSetterFunction = typeof setter === 'function';
147
- const metadata = isSetterFunction
148
- ? setter(this.getMetadataClone())
149
- : setter;
150
- this.config = Object.assign(Object.assign({}, ((_a = this.config) !== null && _a !== void 0 ? _a : {})), { metadata });
151
- };
152
- /**
153
- * get the parameters object to pass to the callback functions (onInit, onStateChanged, onSubscribed, computePreventStateChange)
154
- * this parameters object brings the following properties: setState, getState, setMetadata, getMetadata
155
- * this parameter object allows to update the state, get the state, update the metadata, get the metadata
156
- * @param {{ invokerSetState?: React.Dispatch<React.SetStateAction<TState>> }} parameters - The setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
157
- * @returns {StateConfigCallbackParam<TState, TMetadata>} - The parameters object
158
- * */
159
- this.getConfigCallbackParam = ({ invokerSetState, }) => {
160
- const { setMetadata, getMetadataClone: getMetadata, getStateClone: getState, } = this;
161
- const setState = this.getSetStateWrapper({ invokerSetState });
162
- const actions = this.getStoreActionsMap({});
163
- return {
164
- setMetadata,
165
- getMetadata,
166
- getState,
167
- setState,
168
- actions,
169
- };
170
- };
171
- /**
172
- * Returns a custom hook that allows to handle a global state
173
- * @returns {[TState, TStateSetter, TMetadata]} - The state, the state setter or the actions map, the metadata
174
- * */
175
- this.getHook = () => () => {
176
- const [value, invokerSetState] = (0, react_1.useState)(() => this.state);
177
- (0, react_1.useEffect)(() => {
178
- this.subscribers.add(invokerSetState);
179
- const { onSubscribed } = this;
180
- const { onSubscribed: onSubscribedFromConfig } = this.config;
181
- if (onSubscribed || onSubscribedFromConfig) {
182
- const parameters = this.getConfigCallbackParam({ invokerSetState });
183
- onSubscribed === null || onSubscribed === void 0 ? void 0 : onSubscribed(parameters);
184
- onSubscribedFromConfig === null || onSubscribedFromConfig === void 0 ? void 0 : onSubscribedFromConfig(parameters);
185
- }
186
- return () => {
187
- this.subscribers.delete(invokerSetState);
188
- };
189
- }, []);
190
- const stateOrchestrator = this.getStateOrchestrator(invokerSetState);
191
- return [value, stateOrchestrator, this.getMetadataClone()];
192
- };
193
- /**
194
- * Returns an array with the a function to get the state, the state setter or the actions map, and a function to get the metadata
195
- * @returns {[() => TState, TStateSetter, () => TMetadata]} - The state getter, the state setter or the actions map, the metadata getter
196
- * */
197
- this.getHookDecoupled = () => {
198
- const { getStateClone: getState, getMetadataClone: getMetadata } = this;
199
- const stateOrchestrator = this.getStateOrchestrator();
200
- return [getState, stateOrchestrator, getMetadata];
201
- };
202
- /**
203
- * returns a wrapper for the setState function that will update the state and all the subscribers
204
- * @param {{ invokerSetState?: React.Dispatch<React.SetStateAction<TState>> }} parameters - The setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
205
- * @returns {StateSetter<TState>} - The state setter
206
- * */
207
- this.getSetStateWrapper = ({ invokerSetState, } = {}) => {
208
- const setState = (setter) => {
209
- this.computeSetState({ invokerSetState, setter });
210
- };
211
- return setState;
212
- };
213
- /**
214
- * Calculate whenever or not we should compute the callback parameters on the state change
215
- * @returns {boolean} - True if we should compute the callback parameters on the state change
216
- * */
217
- this.hasStateCallbacks = () => {
218
- const { computePreventStateChange, onStateChanged } = this;
219
- const { computePreventStateChange: computePreventStateChangeFromConfig, onStateChanged: onStateChangedFromConfig, } = this.config;
220
- const preventStateChangesCalls = computePreventStateChange || computePreventStateChangeFromConfig;
221
- const stateChangeCalls = onStateChanged || onStateChangedFromConfig;
222
- const shouldComputeParameter = preventStateChangesCalls || stateChangeCalls;
223
- return !!shouldComputeParameter;
224
- };
225
- /**
226
- * This is responsible for defining whenever or not the state change should be allowed or prevented
227
- * the function also execute the functions:
228
- * - onStateChanged (if defined) - this function is executed after the state change
229
- * - computePreventStateChange (if defined) - this function is executed before the state change and it should return a boolean value that will be used to determine if the state change should be prevented or not
230
- * @param {{ setter: StateSetter<TState>; invokerSetState?: React.Dispatch<React.SetStateAction<TState>> }} parameters - The state setter and the setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
231
- */
232
- this.computeSetState = ({ setter, invokerSetState, }) => {
233
- const isSetterFunction = typeof setter === 'function';
234
- const previousState = this.getStateClone();
235
- const newState = isSetterFunction
236
- ? setter(previousState)
237
- : setter;
238
- const itHasStateCallbacks = this.hasStateCallbacks();
239
- const actions = itHasStateCallbacks && this.getStoreActionsMap({});
240
- const setState = itHasStateCallbacks && this.getSetStateWrapper({ invokerSetState });
241
- const { setMetadata, getMetadataClone: getMetadata, getStateClone: getState, } = this;
242
- const callbackParameter = {
243
- setMetadata,
244
- getMetadata,
245
- setState,
246
- getState,
247
- actions,
248
- previousState,
249
- state: newState,
250
- };
251
- const { computePreventStateChange } = this;
252
- const { computePreventStateChange: computePreventStateChangeFromConfig } = this.config;
253
- // check if the state change should be prevented
254
- if (computePreventStateChange || computePreventStateChangeFromConfig) {
255
- const preventStateChange = (computePreventStateChange === null || computePreventStateChange === void 0 ? void 0 : computePreventStateChange(callbackParameter)) ||
256
- (computePreventStateChangeFromConfig === null || computePreventStateChangeFromConfig === void 0 ? void 0 : computePreventStateChangeFromConfig(callbackParameter));
257
- if (preventStateChange)
258
- return;
259
- }
260
- this.setState({
261
- invokerSetState,
262
- state: newState,
263
- });
264
- const { onStateChanged } = this;
265
- const { onStateChanged: onStateChangedFromConfig } = this.config;
266
- if (!onStateChanged && !onStateChangedFromConfig)
267
- return;
268
- onStateChanged === null || onStateChanged === void 0 ? void 0 : onStateChanged(callbackParameter);
269
- onStateChangedFromConfig === null || onStateChangedFromConfig === void 0 ? void 0 : onStateChangedFromConfig(callbackParameter);
270
- };
271
- /**
272
- * This creates a map of actions that can be used to modify or interact with the state
273
- * @param {{ invokerSetState?: React.Dispatch<React.SetStateAction<TState>> }} parameters - The setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
274
- * @returns {ActionCollectionResult<TState, TMetadata, TStateSetter>} - The actions map result of the configuration object passed to the constructor
275
- * */
276
- this.getStoreActionsMap = ({ invokerSetState, }) => {
277
- if (!this.setterConfig)
278
- return null;
279
- const { setterConfig, setMetadata } = this;
280
- const actionsConfig = setterConfig;
281
- const actionsKeys = Object.keys(actionsConfig);
282
- const setState = this.getSetStateWrapper({
283
- invokerSetState,
284
- });
285
- // we expose a copy of the state and metadata to the actions to prevent them from modifying the state directly
286
- const { getStateClone: getState, getMetadataClone: getMetadata } = this;
287
- // we bind the functions to the actions object to allow reusing actions in the same api config by using the -this- keyword
288
- const actions = actionsKeys.reduce((accumulator, action_key) => (Object.assign(Object.assign({}, accumulator), { [action_key](...parameres) {
289
- const actionConfig = actionsConfig[action_key];
290
- const action = actionConfig.apply(actions, parameres);
291
- const actionIsNotAFunction = typeof action !== 'function';
292
- // we throw an error if the action is not a function, this is mandatory for the correct execution of the actions
293
- if (actionIsNotAFunction) {
294
- throwWrongKeyOnActionCollectionConfig(action_key);
295
- }
296
- // executes the actions bringing access to the state setter and a copy of the state
297
- const result = action.call(actions, {
298
- setState,
299
- getState,
300
- setMetadata,
301
- getMetadata,
302
- });
303
- // we return the result of the actions to the invoker
304
- return result;
305
- } })), {});
306
- return actions;
307
- };
308
- this.config = Object.assign({ metadata: null }, (config !== null && config !== void 0 ? config : {}));
309
- this.onInitializeStore();
310
- }
311
- /**
312
- * Returns the state setter or the actions map
313
- * @param {{ invokerSetState?: React.Dispatch<React.SetStateAction<TState>> }} parameters - The setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
314
- * @returns {TStateSetter} - The state setter or the actions map
315
- * */
316
- getStateOrchestrator(invokerSetState) {
317
- const stateHasCustomActions = this.setterConfig;
318
- if (stateHasCustomActions) {
319
- return this.getStoreActionsMap({ invokerSetState });
320
- }
321
- return this.getSetStateWrapper({ invokerSetState });
322
- }
323
- }
324
- exports.GlobalStore = GlobalStore;
@@ -1 +0,0 @@
1
- {"version":3,"file":"GlobalStore.types.d.ts","sourceRoot":"","sources":["../src/GlobalStore.types.ts"],"names":[],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
package/lib/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./GlobalStore.types"), exports);
5
- tslib_1.__exportStar(require("./GlobalStore"), exports);