little-state-machine
Advanced tools
Comparing version 3.1.3 to 3.1.4-beta.1
@@ -104,6 +104,6 @@ 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 | ||
: { | ||
getItem: payload => payload, | ||
getItem: (payload) => payload, | ||
setItem: (payload) => payload, | ||
@@ -179,3 +179,3 @@ clear: () => { }, | ||
if (updateStoreFunction && Object.keys(updateStoreFunction).length) { | ||
return { | ||
return useMemo(() => ({ | ||
actions: Object.entries(updateStoreFunction).reduce((previous, [key, callback]) => (Object.assign(Object.assign({}, previous), { [key]: useCallback(actionTemplate({ | ||
@@ -186,5 +186,5 @@ options, | ||
}), []) })), {}), | ||
action: p => p, | ||
action: (p) => p, | ||
state: globalState, | ||
}; | ||
}), [updateStoreFunction, globalState]); | ||
} | ||
@@ -191,0 +191,0 @@ return { |
@@ -338,23 +338,25 @@ 'use strict'; | ||
if (updateStoreFunction && _Object$keys(updateStoreFunction).length) { | ||
var _context2; | ||
return React.useMemo(function () { | ||
var _context2; | ||
return { | ||
actions: _reduceInstanceProperty(_context2 = _Object$entries(updateStoreFunction)).call(_context2, function (previous, _a) { | ||
var _b; | ||
return { | ||
actions: _reduceInstanceProperty(_context2 = _Object$entries(updateStoreFunction)).call(_context2, function (previous, _a) { | ||
var _b; | ||
var _c = __read(_a, 2), | ||
key = _c[0], | ||
callback = _c[1]; | ||
var _c = __read(_a, 2), | ||
key = _c[0], | ||
callback = _c[1]; | ||
return __assign(__assign({}, previous), (_b = {}, _b[key] = React.useCallback(actionTemplate({ | ||
options: options, | ||
callback: callback, | ||
updateStore: updateStore | ||
}), []), _b)); | ||
}, {}), | ||
action: function (p) { | ||
return p; | ||
}, | ||
state: globalState | ||
}; | ||
return __assign(__assign({}, previous), (_b = {}, _b[key] = React.useCallback(actionTemplate({ | ||
options: options, | ||
callback: callback, | ||
updateStore: updateStore | ||
}), []), _b)); | ||
}, {}), | ||
action: function (p) { | ||
return p; | ||
}, | ||
state: globalState | ||
}; | ||
}, [updateStoreFunction, globalState]); | ||
} | ||
@@ -361,0 +363,0 @@ |
@@ -108,6 +108,6 @@ 'use strict'; | ||
const isDevMode = process.env.NODE_ENV !== 'production'; | ||
let storageType = isClient && typeof (sessionStorage) !== 'undefined' | ||
let storageType = isClient && typeof sessionStorage !== 'undefined' | ||
? window.sessionStorage | ||
: { | ||
getItem: payload => payload, | ||
getItem: (payload) => payload, | ||
setItem: (payload) => payload, | ||
@@ -183,3 +183,3 @@ clear: () => { }, | ||
if (updateStoreFunction && Object.keys(updateStoreFunction).length) { | ||
return { | ||
return React.useMemo(() => ({ | ||
actions: Object.entries(updateStoreFunction).reduce((previous, [key, callback]) => (Object.assign(Object.assign({}, previous), { [key]: React.useCallback(actionTemplate({ | ||
@@ -190,5 +190,5 @@ options, | ||
}), []) })), {}), | ||
action: p => p, | ||
action: (p) => p, | ||
state: globalState, | ||
}; | ||
}), [updateStoreFunction, globalState]); | ||
} | ||
@@ -195,0 +195,0 @@ return { |
@@ -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:o,updateStore:s}=n(c);return e&&Object.keys(e).length?r(()=>({actions:Object.entries(e).reduce((e,[r,o])=>Object.assign(Object.assign({},e),{[r]:a(g({options:t,callback:o,updateStore:s}),[])}),{}),action:e=>e,state:o}),[e,o]):{actions:{},action:a(e?g({options:t,callback:e,updateStore:s}):()=>{},[]),state:o}}export{c as StateMachineContext,N as StateMachineProvider,T as createStore,u as setStorageType,p as useStateMachine}; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(global = global || self, factory(global.ReactHookForm = {}, global.React)); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactHookForm = {}, global.React)); | ||
}(this, (function (exports, React) { 'use strict'; | ||
@@ -107,6 +107,6 @@ | ||
const isDevMode = "production" !== 'production'; | ||
let storageType = isClient && typeof (sessionStorage) !== 'undefined' | ||
let storageType = isClient && typeof sessionStorage !== 'undefined' | ||
? window.sessionStorage | ||
: { | ||
getItem: payload => payload, | ||
getItem: (payload) => payload, | ||
setItem: (payload) => payload, | ||
@@ -168,3 +168,3 @@ clear: () => { }, | ||
if (updateStoreFunction && Object.keys(updateStoreFunction).length) { | ||
return { | ||
return React.useMemo(() => ({ | ||
actions: Object.entries(updateStoreFunction).reduce((previous, [key, callback]) => (Object.assign(Object.assign({}, previous), { [key]: React.useCallback(actionTemplate({ | ||
@@ -175,5 +175,5 @@ options, | ||
}), []) })), {}), | ||
action: p => p, | ||
action: (p) => p, | ||
state: globalState, | ||
}; | ||
}), [updateStoreFunction, globalState]); | ||
} | ||
@@ -180,0 +180,0 @@ return { |
import * as React from 'react'; | ||
import { UpdateStoreFunction } from './types'; | ||
import { Store, UpdateStoreFunction } from './types'; | ||
declare const _default: React.Context<{ | ||
store: Record<string, any>; | ||
store: Store; | ||
updateStore: UpdateStoreFunction; | ||
}>; | ||
export default _default; |
{ | ||
"name": "little-state-machine", | ||
"sideEffects": false, | ||
"version": "3.1.3", | ||
"version": "3.1.4-beta.1", | ||
"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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
53813
1027
2