little-state-machine
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -34,2 +34,11 @@ import { createContext, useState, useMemo, createElement, useContext, useCallback } from 'react'; | ||
var isSessionStorageAllowed = () => { | ||
try { | ||
return !!window.sessionStorage; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
}; | ||
function setUpDevTools(isDevMode, storageType, getName, getStore) { | ||
@@ -105,3 +114,3 @@ if (typeof window === 'undefined' || !isDevMode) | ||
const isDevMode = process.env.NODE_ENV !== 'production'; | ||
let storageType = isClient | ||
let storageType = isClient && isSessionStorageAllowed() | ||
? window.sessionStorage | ||
@@ -108,0 +117,0 @@ : { |
@@ -125,2 +125,10 @@ 'use strict'; | ||
var isSessionStorageAllowed = function () { | ||
try { | ||
return !!window.sessionStorage; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
function setUpDevTools(isDevMode, storageType, getName, getStore) { | ||
@@ -222,3 +230,3 @@ if (typeof window === 'undefined' || !isDevMode) return; // @ts-ignore | ||
var isDevMode = process.env.NODE_ENV !== 'production'; | ||
var storageType = isClient ? window.sessionStorage : { | ||
var storageType = isClient && isSessionStorageAllowed() ? window.sessionStorage : { | ||
getItem: function (payload) { | ||
@@ -225,0 +233,0 @@ return payload; |
@@ -38,2 +38,11 @@ 'use strict'; | ||
var isSessionStorageAllowed = () => { | ||
try { | ||
return !!window.sessionStorage; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
}; | ||
function setUpDevTools(isDevMode, storageType, getName, getStore) { | ||
@@ -109,3 +118,3 @@ if (typeof window === 'undefined' || !isDevMode) | ||
const isDevMode = process.env.NODE_ENV !== 'production'; | ||
let storageType = isClient | ||
let storageType = isClient && isSessionStorageAllowed() | ||
? window.sessionStorage | ||
@@ -112,0 +121,0 @@ : { |
@@ -1,1 +0,1 @@ | ||
import{createContext as e,useState as t,useMemo as r,createElement as o,useContext as n,useCallback as a}from"react";var s=(e,t)=>{const r=e.getItem(t);try{return r?JSON.parse(r):void 0}catch(e){return}};var i=e=>void 0===e;var c=e({store:{},updateStore:e=>e}),_=({transform:e,externalStoreName:t,storageType:r,store:o})=>e({externalStoreData:s(r,t),currentStoreData:o});const E="undefined"!=typeof window,S="production"!==process.env.NODE_ENV;let d,m,A,l=E?window.sessionStorage:{getItem:e=>e,setItem:e=>e,clear:()=>{},length:0,key:e=>e.toString(),removeItem:()=>{}},T=[];function u(e){l=e}function f(e,t={name:"__STATE_MACHINE__",middleWares:[],syncStores:void 0}){const r=t?t.name:"__STATE_MACHINE__",o=function(e,t){const r=t||"__STATE_MACHINE__";let o=s(e,r);return{set:e=>{o=e},get:()=>o,getName:()=>r}}(l,r);S&&E&&(window.STATE_MACHINE_NAME=r),A=o.getName,d=o.get,m=o.set,T=t.middleWares,function(e,t,r,o){"undefined"!=typeof window&&e&&(window.STATE_MACHINE_DEBUG=e=>t.setItem("___STATE_MACHINE_DEBUG__",e),window.STATE_MACHINE_RESET=()=>t.clear(),window.STATE_MACHINE_GET_STORE=()=>t.getItem(r()),window.STATE_MACHINE_SAVE_TO=e=>window.localStorage.setItem(e,JSON.stringify(o())),window.STATE_MACHINE_LOAD=({storeName:e,data:o})=>t.setItem(r()||"___STATE_MACHINE_DEBUG__",o||window.localStorage.getItem(e)||""))}(S,l,A,d),m(function(e,t,r){let o=e;const n=t.syncStores;if(!n)return o;try{if(Array.isArray(n))n.forEach(e=>{o=_({transform:e.transform,externalStoreName:e.externalStoreName,storageType:r,store:o})});else{if(n.externalStoreName&&"function"==typeof n.transform&&"string"==typeof n.externalStoreName)return _({transform:n.transform,externalStoreName:n.externalStoreName,storageType:r,store:o});Object.entries(n).forEach(([e,t])=>{const n=s(r,e);t.forEach(e=>{o=Object.assign(Object.assign({},o),{[e]:Object.assign(Object.assign({},o[e]),n[e])})})})}}catch(e){return o}return o}(d()||e,t,l))}function N(e){const[n,a]=t(d()),s=r(()=>({store:n,updateStore:a}),[n]);return o(c.Provider,Object.assign({value:s},e))}const g=({options:e,callback:t,updateStore:r})=>o=>{let n;const a=t?t.name:"";if(S&&((e="")=>{e&&E&&(window.__STATE_MACHINE_ACTION_NAME__=e)})(a),t&&(n=t(d(),o)),m(i(n)?d():n),l.setItem(A(),JSON.stringify(d())),i(e)||e&&!1!==e.shouldReRenderApp){let e=d();Array.isArray(T)&&T.length&&(e=T.reduce((e,t)=>t(e)||e,e)),r(e)}};function w(e,t){const{store:r,updateStore:o}=n(c);return e&&Object.keys(e).length?{actions:Object.entries(e).reduce((e,[r,n])=>Object.assign(Object.assign({},e),{[r]:a(g({options:t,callback:n,updateStore:o}),[])}),{}),action:e=>e,state:r}:{actions:{},action:a(e?g({options:t,callback:e,updateStore:o}):()=>{},[]),state:r}}export{c as StateMachineContext,N as StateMachineProvider,f as createStore,u as setStorageType,w as useStateMachine}; | ||
import{createContext as e,useState as t,useMemo as r,createElement as n,useContext as o,useCallback as a}from"react";var s=(e,t)=>{const r=e.getItem(t);try{return r?JSON.parse(r):void 0}catch(e){return}};var i=e=>void 0===e;var c=e({store:{},updateStore:e=>e}),_=({transform:e,externalStoreName:t,storageType:r,store:n})=>e({externalStoreData:s(r,t),currentStoreData:n});const S="undefined"!=typeof window,E="production"!==process.env.NODE_ENV;let d,m,A,l=S&&(()=>{try{return!!window.sessionStorage}catch(e){return!1}})()?window.sessionStorage:{getItem:e=>e,setItem:e=>e,clear:()=>{},length:0,key:e=>e.toString(),removeItem:()=>{}},u=[];function T(e){l=e}function f(e,t={name:"__STATE_MACHINE__",middleWares:[],syncStores:void 0}){const r=t?t.name:"__STATE_MACHINE__",n=function(e,t){const r=t||"__STATE_MACHINE__";let n=s(e,r);return{set:e=>{n=e},get:()=>n,getName:()=>r}}(l,r);E&&S&&(window.STATE_MACHINE_NAME=r),A=n.getName,d=n.get,m=n.set,u=t.middleWares,function(e,t,r,n){"undefined"!=typeof window&&e&&(window.STATE_MACHINE_DEBUG=e=>t.setItem("___STATE_MACHINE_DEBUG__",e),window.STATE_MACHINE_RESET=()=>t.clear(),window.STATE_MACHINE_GET_STORE=()=>t.getItem(r()),window.STATE_MACHINE_SAVE_TO=e=>window.localStorage.setItem(e,JSON.stringify(n())),window.STATE_MACHINE_LOAD=({storeName:e,data:n})=>t.setItem(r()||"___STATE_MACHINE_DEBUG__",n||window.localStorage.getItem(e)||""))}(E,l,A,d),m(function(e,t,r){let n=e;const o=t.syncStores;if(!o)return n;try{if(Array.isArray(o))o.forEach(e=>{n=_({transform:e.transform,externalStoreName:e.externalStoreName,storageType:r,store:n})});else{if(o.externalStoreName&&"function"==typeof o.transform&&"string"==typeof o.externalStoreName)return _({transform:o.transform,externalStoreName:o.externalStoreName,storageType:r,store:n});Object.entries(o).forEach(([e,t])=>{const o=s(r,e);t.forEach(e=>{n=Object.assign(Object.assign({},n),{[e]:Object.assign(Object.assign({},n[e]),o[e])})})})}}catch(e){return n}return n}(d()||e,t,l))}function N(e){const[o,a]=t(d()),s=r(()=>({store:o,updateStore:a}),[o]);return n(c.Provider,Object.assign({value:s},e))}const g=({options:e,callback:t,updateStore:r})=>n=>{let o;const a=t?t.name:"";if(E&&((e="")=>{e&&S&&(window.__STATE_MACHINE_ACTION_NAME__=e)})(a),t&&(o=t(d(),n)),m(i(o)?d():o),l.setItem(A(),JSON.stringify(d())),i(e)||e&&!1!==e.shouldReRenderApp){let e=d();Array.isArray(u)&&u.length&&(e=u.reduce((e,t)=>t(e)||e,e)),r(e)}};function w(e,t){const{store:r,updateStore:n}=o(c);return e&&Object.keys(e).length?{actions:Object.entries(e).reduce((e,[r,o])=>Object.assign(Object.assign({},e),{[r]:a(g({options:t,callback:o,updateStore:n}),[])}),{}),action:e=>e,state:r}:{actions:{},action:a(e?g({options:t,callback:e,updateStore:n}):()=>{},[]),state:r}}export{c as StateMachineContext,N as StateMachineProvider,f as createStore,T as setStorageType,w as useStateMachine}; |
@@ -37,2 +37,11 @@ (function (global, factory) { | ||
var isSessionStorageAllowed = () => { | ||
try { | ||
return !!window.sessionStorage; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
}; | ||
function setUpDevTools(isDevMode, storageType, getName, getStore) { | ||
@@ -108,3 +117,3 @@ if (typeof window === 'undefined' || !isDevMode) | ||
const isDevMode = "production" !== 'production'; | ||
let storageType = isClient | ||
let storageType = isClient && isSessionStorageAllowed() | ||
? window.sessionStorage | ||
@@ -111,0 +120,0 @@ : { |
{ | ||
"name": "little-state-machine", | ||
"sideEffects": false, | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"main": "dist/little-state-machine.js", | ||
@@ -6,0 +6,0 @@ "module": "dist/little-state-machine.es.js", |
139
README.md
@@ -116,6 +116,2 @@ <div align="center"><a href="https://lrz5wloklm.csb.app/"><img src="https://github.com/bluebill1049/little-state-machine/blob/master/docs/logo.png?raw=true" alt="Little State Machine - React Hooks for state management" width="140px" /></a> | ||
// The following code is for React Native usage | ||
// import { AsyncStorage } from "react-native"; | ||
// setStorageType(AsyncStorage); | ||
// create your store | ||
@@ -225,1 +221,136 @@ createStore({ | ||
Or you can add [core-js](https://github.com/zloirock/core-js) polyfill into your project and add `core-js/es/object/entries` in your `polyfills.[js|ts]` file. | ||
## Sponsors | ||
Thank you very much for those kind people with their sponsorship to this project. | ||
<p> | ||
<a href="https://github.com/sayav" | ||
><img | ||
src="https://avatars1.githubusercontent.com/u/42376060?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@sayav" | ||
/></a> | ||
<a href="https://github.com/lemcii" | ||
><img | ||
src="https://avatars1.githubusercontent.com/u/35668113?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@lemcii" | ||
/></a> | ||
<a href="https://github.com/washingtonsoares" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/5726150?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@washingtonsoares" | ||
/></a> | ||
<a href="https://github.com/lixunn" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/5017964?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@lixunn" | ||
/></a> | ||
<a href="https://github.com/SamSamskies" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/3655410?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@SamSamskies" | ||
/></a> | ||
<a href="https://github.com/peaonunes" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/3356720?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@peaonunes" | ||
/></a> | ||
<a href="https://github.com/wilhelmeek" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/609452?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@wilhelmeek" | ||
/></a> | ||
<a href="https://github.com/iwarner" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/279251?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@iwarner" | ||
/></a> | ||
<a href="https://github.com/joejknowles" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/10728145?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@joejknowles" | ||
/></a> | ||
<a href="https://github.com/chris-gunawardena" | ||
><img | ||
src="https://avatars0.githubusercontent.com/u/5763108?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@chris-gunawardena" | ||
/></a> | ||
<a href="https://github.com/Tymek" | ||
><img | ||
src="https://avatars1.githubusercontent.com/u/2625371?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@Tymek" | ||
/></a> | ||
<a href="https://github.com/Luchanso" | ||
><img | ||
src="https://avatars0.githubusercontent.com/u/2098777?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@Luchanso" | ||
/></a> | ||
<a href="https://github.com/vcarel" | ||
><img | ||
src="https://avatars1.githubusercontent.com/u/1541093?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@vcarel" | ||
/></a> | ||
<a href="https://github.com/gragland" | ||
><img | ||
src="https://avatars0.githubusercontent.com/u/1481077?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@gragland" | ||
/></a> | ||
<a href="https://github.com/tjshipe" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/1254942?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@tjshipe" | ||
/></a> | ||
<a href="https://github.com/krnlde" | ||
><img | ||
src="https://avatars1.githubusercontent.com/u/1087002?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@krnlde" | ||
/></a> | ||
<a href="https://github.com/msutkowski" | ||
><img | ||
src="https://avatars2.githubusercontent.com/u/784953?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@msutkowski" | ||
/></a> | ||
<a href="https://github.com/mlukaszczyk" | ||
><img | ||
src="https://avatars3.githubusercontent.com/u/599247?s=60&v=4" | ||
width="50" | ||
height="50" | ||
alt="@mlukaszczyk" | ||
/></a> | ||
</p> | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54086
24
1058
355
284177