little-state-machine
Advanced tools
Comparing version 3.1.3-beta.2 to 3.1.3-beta.3
@@ -104,3 +104,3 @@ import { createContext, useState, useMemo, createElement, useContext, useCallback } from 'react'; | ||
const isDevMode = process.env.NODE_ENV !== 'production'; | ||
let storageType = isClient && typeof (sessionStorage) == 'undefined' | ||
let storageType = isClient && typeof (sessionStorage) !== 'undefined' | ||
? window.sessionStorage | ||
@@ -107,0 +107,0 @@ : { |
@@ -221,3 +221,3 @@ 'use strict'; | ||
var isDevMode = process.env.NODE_ENV !== 'production'; | ||
var storageType = isClient && typeof sessionStorage == 'undefined' ? window.sessionStorage : { | ||
var storageType = isClient && typeof sessionStorage !== 'undefined' ? window.sessionStorage : { | ||
getItem: function (payload) { | ||
@@ -224,0 +224,0 @@ return payload; |
@@ -108,3 +108,3 @@ 'use strict'; | ||
const isDevMode = process.env.NODE_ENV !== 'production'; | ||
let storageType = isClient && typeof (sessionStorage) == 'undefined' | ||
let storageType = isClient && typeof (sessionStorage) !== 'undefined' | ||
? window.sessionStorage | ||
@@ -111,0 +111,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 S="undefined"!=typeof window,E="production"!==process.env.NODE_ENV;let d,m,A,l=S&&"undefined"==typeof sessionStorage?window.sessionStorage:{getItem:e=>e,setItem:e=>e,clear:()=>{},length:0,key:e=>e.toString(),removeItem:()=>{}},f=[];function u(e){l=e}function T(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);E&&S&&(window.STATE_MACHINE_NAME=r),A=o.getName,d=o.get,m=o.set,f=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)||""))}(E,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(E&&((e="")=>{e&&S&&(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(f)&&f.length&&(e=f.reduce((e,t)=>t(e)||e,e)),r(e)}};function p(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,T as createStore,u as setStorageType,p as useStateMachine}; | ||
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 S="undefined"!=typeof window,E="production"!==process.env.NODE_ENV;let d,m,A,l=S&&"undefined"!=typeof sessionStorage?window.sessionStorage:{getItem:e=>e,setItem:e=>e,clear:()=>{},length:0,key:e=>e.toString(),removeItem:()=>{}},f=[];function u(e){l=e}function T(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);E&&S&&(window.STATE_MACHINE_NAME=r),A=o.getName,d=o.get,m=o.set,f=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)||""))}(E,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(E&&((e="")=>{e&&S&&(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(f)&&f.length&&(e=f.reduce((e,t)=>t(e)||e,e)),r(e)}};function p(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,T as createStore,u as setStorageType,p as useStateMachine}; |
@@ -107,3 +107,3 @@ (function (global, factory) { | ||
const isDevMode = "production" !== 'production'; | ||
let storageType = isClient && typeof (sessionStorage) == 'undefined' | ||
let storageType = isClient && typeof (sessionStorage) !== 'undefined' | ||
? window.sessionStorage | ||
@@ -110,0 +110,0 @@ : { |
{ | ||
"name": "little-state-machine", | ||
"sideEffects": false, | ||
"version": "3.1.3-beta.2", | ||
"version": "3.1.3-beta.3", | ||
"main": "dist/little-state-machine.js", | ||
@@ -6,0 +6,0 @@ "module": "dist/little-state-machine.es.js", |
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
53460