text: import r,{createContext as t,useState as e,useReducer as n,useEffect as o}from"react";function a(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(r)))return;var e=[],n=!0,o=!1,a=void 0;try{for(var u,i=r[Symbol.iterator]();!(n=(u=i.next()).done)&&(e.push(u.value),!t||e.length!==t);n=!0);}catch(r){o=!0,a=r}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return e}(r,t)||function(r,t){if(!r)return;if("string"==typeof r)return u(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);"Object"===e&&r.constructor&&(e=r.constructor.name);if("Map"===e||"Set"===e)return Array.from(e);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return u(r,t)}(r,t)||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.")}()}function u(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}var i={},c=function(r){var e,n,o,a=t({storage:{},dispatch:function(r){console.log("Action dispatched: ",r),console.warn("You're using Storage.Consumer outside of Storage.Provider")}}),u=(o=a,(n=r)in(e={})?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o,e);return function(r){Object.assign(i,r)}(u),u[r]},l=function(r){return i[r]?i[r]:null},s=function(r,t){var e,n="React-Context-Storage-"+r;try{return(e=t?sessionStorage.getItem(n):localStorage.getItem(n))?JSON.parse(e):null}catch(r){throw new Error("Error getting ".concat(t?"session":"local"," storage for ").concat(n))}},f=function(r,t,e){var n="React-Context-Storage-"+r;try{var o=JSON.stringify(t);e?sessionStorage.setItem(n,o):localStorage.setItem(n,o)}catch(r){throw new Error("Error setting ".concat(e?"session":"local"," storage for ").concat(n))}},g=function(t){var u=t.storageName,i=t.defaultValues,g=t.reducer,m=t.useSession,v=t.useLocal;return function(t){return function(d){var y=a(e(null),2),S=y[0],b=y[1],h=function(){if(null===S){var r=m?s(u,!0)||i:v&&s(u,!1)||i;return b(r),r}return S},p=a(n(g,S,(function(){return h()})),2),w=p[0],E=p[1];o((function(){m?f(u,w,!0):v&&f(u,w,!1)}),[u,w,m,v]);var O=l(u)||c(u);return r.createElement(O.Provider,{value:{storage:w,dispatch:E}},r.createElement(t,Object.assign({},d)))}}},m=function(t){return function(e){return function(n){var o=l(t);if(!o)throw new Error("Invalid Storage name. Storage must be created using withStorageProvider()");return r.createElement(o.Consumer,null,(function(t){return r.createElement(e,Object.assign({},n,{context:t}))}))}}};export{m as withStorage,g as withStorageProvider};
  //# sourceMappingURL=build.js.map
  