little-state-machine
Advanced tools
Comparing version 4.7.0-next.1 to 4.7.0
export declare const STORE_DEFAULT_NAME = "__LSM__"; | ||
export declare const STORE_ACTION_NAME = "__LSM_NAME__"; | ||
export declare const PERSIST_BEFORE_UNLOAD = "beforeUnload"; | ||
export declare const PERSIST_OPTION: { | ||
readonly NONE: "none"; | ||
readonly ACTION: "action"; | ||
readonly UNLOAD: "beforeUnload"; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import*as e from"react";var t=function(){var e={name:"__LSM__",middleWares:[],storageType:{},persist:""},t={};try{e.storageType="undefined"!=typeof sessionStorage?window.sessionStorage:{}}catch(e){}return{updateStore:function(n){try{t=JSON.parse(e.storageType.getItem(e.name)||"")||n}catch(e){t=n}},saveStore:function(){e.storageType.setItem(e.name,JSON.stringify(t))},get state(){return t},set state(e){t=e},get options(){return e},set options(t){e=t}}}(),n=e.createContext(void 0),o=function(o){var r=o.children,s=e.useState(t.state),a=s[0],i=s[1];return e.useEffect(function(){"beforeUnload"===t.options.persist&&(window.onbeforeunload=function(){return t.saveStore()},t.options.storageType.removeItem(t.options.name))},[]),e.createElement(n.Provider,{value:{state:a,setState:i}},r)};function r(){return r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},r.apply(this,arguments)}function s(e,n){n&&(t.options=r({},t.options,n)),"production"!==process.env.NODE_ENV&&"undefined"!=typeof window&&(window.__LSM_NAME__=t.options.name,window.__LSM_RESET__=function(){return t.options.storageType.removeItem(t.options.name)}),t.updateStore(e)}function a(o){var r=e.useContext(n),s=r.state,a=r.setState,i=e.useRef(Object.entries(o||{}).reduce(function(e,n){var o;return Object.assign({},e,((o={})[n[0]]=function(e,n){return function(o,r){"production"!==process.env.NODE_ENV&&(window.__LSM_NAME__=n.name),t.state=n(t.state,o),t.options.middleWares&&(t.state=t.options.middleWares.reduce(function(e,t){return t(e,n.name,o)||e},t.state)),(!r||!r.skipRender)&&e(t.state),"beforeUnload"!==t.options.persist&&t.saveStore()}}(a,n[1]),o))},{}));return{actions:i.current,state:s,getState:e.useCallback(function(){return t.state},[])}}export{o as StateMachineProvider,s as createStore,a as useStateMachine}; | ||
import*as e from"react";var t=function(){var e={name:"__LSM__",middleWares:[],persist:"action"},t={};try{e.storageType="undefined"!=typeof sessionStorage?window.sessionStorage:void 0}catch(e){}return{updateStore:function(n){try{t=e.storageType&&JSON.parse(e.storageType.getItem(e.name)||"")||n}catch(e){t=n}},saveStore:function(){e.storageType&&e.storageType.setItem(e.name,JSON.stringify(t))},get state(){return t},set state(e){t=e},get options(){return e},set options(t){e=t}}}(),n=e.createContext(void 0),o=function(o){var r=o.children,s=e.useState(t.state),a=s[0],i=s[1];return e.useEffect(function(){"beforeUnload"===t.options.persist&&(window.onbeforeunload=function(){return t.saveStore()},t.options.storageType&&t.options.storageType.removeItem(t.options.name))},[]),e.createElement(n.Provider,{value:{state:a,setState:i}},r)};function r(){return r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},r.apply(this,arguments)}function s(e,n){n&&(t.options=r({},t.options,n)),"production"!==process.env.NODE_ENV&&"undefined"!=typeof window&&(window.__LSM_NAME__=t.options.name,window.__LSM_RESET__=function(){return t.options.storageType&&t.options.storageType.removeItem(t.options.name)}),t.updateStore(e)}function a(o){var r=e.useContext(n),s=r.state,a=r.setState,i=e.useRef(Object.entries(o||{}).reduce(function(e,n){var o;return Object.assign({},e,((o={})[n[0]]=function(e,n){return function(o,r){"production"!==process.env.NODE_ENV&&(window.__LSM_NAME__=n.name),t.state=n(t.state,o),t.options.middleWares&&(t.state=t.options.middleWares.reduce(function(e,t){return t(e,n.name,o)||e},t.state)),(!r||!r.skipRender)&&e(t.state),"action"===t.options.persist&&t.saveStore()}}(a,n[1]),o))},{}));return{actions:i.current,state:s}}export{o as StateMachineProvider,s as createStore,a as useStateMachine}; | ||
//# sourceMappingURL=little-state-machine.es.js.map |
@@ -1,2 +0,2 @@ | ||
function e(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var t=/*#__PURE__*/e(require("react")),r=function(){var e={name:"__LSM__",middleWares:[],storageType:{},persist:""},t={};try{e.storageType="undefined"!=typeof sessionStorage?window.sessionStorage:{}}catch(e){}return{updateStore:function(r){try{t=JSON.parse(e.storageType.getItem(e.name)||"")||r}catch(e){t=r}},saveStore:function(){e.storageType.setItem(e.name,JSON.stringify(t))},get state(){return t},set state(e){t=e},get options(){return e},set options(t){e=t}}}(),n=t.createContext(void 0);function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}exports.StateMachineProvider=function(e){var o=e.children,a=t.useState(r.state),s=a[0],i=a[1];return t.useEffect(function(){"beforeUnload"===r.options.persist&&(window.onbeforeunload=function(){return r.saveStore()},r.options.storageType.removeItem(r.options.name))},[]),t.createElement(n.Provider,{value:{state:s,setState:i}},o)},exports.createStore=function(e,t){t&&(r.options=o({},r.options,t)),r.updateStore(e)},exports.useStateMachine=function(e){var o=t.useContext(n),a=o.state,s=o.setState,i=t.useRef(Object.entries(e||{}).reduce(function(e,t){var n;return Object.assign({},e,((n={})[t[0]]=function(e,t){return function(n,o){r.state=t(r.state,n),r.options.middleWares&&(r.state=r.options.middleWares.reduce(function(e,r){return r(e,t.name,n)||e},r.state)),(!o||!o.skipRender)&&e(r.state),"beforeUnload"!==r.options.persist&&r.saveStore()}}(s,t[1]),n))},{}));return{actions:i.current,state:a,getState:t.useCallback(function(){return r.state},[])}}; | ||
function e(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var t=/*#__PURE__*/e(require("react")),r=function(){var e={name:"__LSM__",middleWares:[],persist:"action"},t={};try{e.storageType="undefined"!=typeof sessionStorage?window.sessionStorage:void 0}catch(e){}return{updateStore:function(r){try{t=e.storageType&&JSON.parse(e.storageType.getItem(e.name)||"")||r}catch(e){t=r}},saveStore:function(){e.storageType&&e.storageType.setItem(e.name,JSON.stringify(t))},get state(){return t},set state(e){t=e},get options(){return e},set options(t){e=t}}}(),n=t.createContext(void 0);function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}exports.StateMachineProvider=function(e){var o=e.children,s=t.useState(r.state),a=s[0],i=s[1];return t.useEffect(function(){"beforeUnload"===r.options.persist&&(window.onbeforeunload=function(){return r.saveStore()},r.options.storageType&&r.options.storageType.removeItem(r.options.name))},[]),t.createElement(n.Provider,{value:{state:a,setState:i}},o)},exports.createStore=function(e,t){t&&(r.options=o({},r.options,t)),r.updateStore(e)},exports.useStateMachine=function(e){var o=t.useContext(n),s=o.state,a=o.setState,i=t.useRef(Object.entries(e||{}).reduce(function(e,t){var n;return Object.assign({},e,((n={})[t[0]]=function(e,t){return function(n,o){r.state=t(r.state,n),r.options.middleWares&&(r.state=r.options.middleWares.reduce(function(e,r){return r(e,t.name,n)||e},r.state)),(!o||!o.skipRender)&&e(r.state),"action"===r.options.persist&&r.saveStore()}}(a,t[1]),n))},{}));return{actions:i.current,state:s}}; | ||
//# sourceMappingURL=little-state-machine.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e||self).littleStateMachine={},e.react)}(this,function(e,t){function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var r=/*#__PURE__*/n(t),o="beforeUnload",a=function(){var e={name:"__LSM__",middleWares:[],storageType:{},persist:""},t={};try{e.storageType="undefined"!=typeof sessionStorage?window.sessionStorage:{}}catch(e){}return{updateStore:function(n){try{t=JSON.parse(e.storageType.getItem(e.name)||"")||n}catch(e){t=n}},saveStore:function(){e.storageType.setItem(e.name,JSON.stringify(t))},get state(){return t},set state(e){t=e},get options(){return e},set options(t){e=t}}}(),s=r.createContext(void 0);function i(){return i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i.apply(this,arguments)}e.StateMachineProvider=function(e){var t=e.children,n=r.useState(a.state),i=n[0],u=n[1];return r.useEffect(function(){a.options.persist===o&&(window.onbeforeunload=function(){return a.saveStore()},a.options.storageType.removeItem(a.options.name))},[]),r.createElement(s.Provider,{value:{state:i,setState:u}},t)},e.createStore=function(e,t){t&&(a.options=i({},a.options,t)),a.updateStore(e)},e.useStateMachine=function(e){var t=r.useContext(s),n=t.state,i=t.setState,u=r.useRef(Object.entries(e||{}).reduce(function(e,t){var n;return Object.assign({},e,((n={})[t[0]]=function(e,t){return function(n,r){a.state=t(a.state,n),a.options.middleWares&&(a.state=a.options.middleWares.reduce(function(e,r){return r(e,t.name,n)||e},a.state)),(!r||!r.skipRender)&&e(a.state),a.options.persist!==o&&a.saveStore()}}(i,t[1]),n))},{}));return{actions:u.current,state:n,getState:r.useCallback(function(){return a.state},[])}}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e||self).littleStateMachine={},e.react)}(this,function(e,t){function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var r=/*#__PURE__*/n(t),o="action",a=function(){var e={name:"__LSM__",middleWares:[],persist:o},t={};try{e.storageType="undefined"!=typeof sessionStorage?window.sessionStorage:void 0}catch(e){}return{updateStore:function(n){try{t=e.storageType&&JSON.parse(e.storageType.getItem(e.name)||"")||n}catch(e){t=n}},saveStore:function(){e.storageType&&e.storageType.setItem(e.name,JSON.stringify(t))},get state(){return t},set state(e){t=e},get options(){return e},set options(t){e=t}}}(),s=r.createContext(void 0);function i(){return i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i.apply(this,arguments)}e.StateMachineProvider=function(e){var t=e.children,n=r.useState(a.state),o=n[0],i=n[1];return r.useEffect(function(){"beforeUnload"===a.options.persist&&(window.onbeforeunload=function(){return a.saveStore()},a.options.storageType&&a.options.storageType.removeItem(a.options.name))},[]),r.createElement(s.Provider,{value:{state:o,setState:i}},t)},e.createStore=function(e,t){t&&(a.options=i({},a.options,t)),a.updateStore(e)},e.useStateMachine=function(e){var t=r.useContext(s),n=t.state,i=t.setState,u=r.useRef(Object.entries(e||{}).reduce(function(e,t){var n;return Object.assign({},e,((n={})[t[0]]=function(e,t){return function(n,r){a.state=t(a.state,n),a.options.middleWares&&(a.state=a.options.middleWares.reduce(function(e,r){return r(e,t.name,n)||e},a.state)),(!r||!r.skipRender)&&e(a.state),a.options.persist===o&&a.saveStore()}}(i,t[1]),n))},{}));return{actions:u.current,state:n}}}); | ||
//# sourceMappingURL=little-state-machine.umd.js.map |
@@ -1,2 +0,2 @@ | ||
import { MiddleWare, GlobalState } from '../types'; | ||
import { GlobalState } from '../types'; | ||
declare const _default: { | ||
@@ -6,9 +6,9 @@ updateStore(defaultValues: GlobalState): void; | ||
state: GlobalState; | ||
options: { | ||
options: Partial<{ | ||
name: string; | ||
middleWares: MiddleWare[]; | ||
middleWares: import("../types").MiddleWare[]; | ||
storageType: Storage; | ||
persist: string; | ||
}; | ||
persist: "none" | "action" | "beforeUnload"; | ||
}>; | ||
}; | ||
export default _default; |
@@ -6,3 +6,2 @@ import { StateMachineOptions, GlobalState, AnyCallback, AnyActions, ActionsOutput } from './types'; | ||
state: GlobalState; | ||
getState: () => GlobalState; | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { PERSIST_OPTION } from './constants'; | ||
import * as React from 'react'; | ||
@@ -16,3 +17,2 @@ export interface GlobalState { | ||
export declare type MiddleWare = (state: GlobalState, payload: any, callbackName: string) => GlobalState; | ||
export declare type PersistOptions = 'onAction' | 'none' | 'beforeUnload'; | ||
export declare type StateMachineOptions = Partial<{ | ||
@@ -22,3 +22,3 @@ name: string; | ||
storageType: Storage; | ||
persist: PersistOptions; | ||
persist: typeof PERSIST_OPTION[keyof typeof PERSIST_OPTION]; | ||
}>; | ||
@@ -25,0 +25,0 @@ declare global { |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "4.7.0-next.1", | ||
"version": "4.7.0", | ||
"main": "dist/little-state-machine.js", | ||
@@ -34,3 +34,3 @@ "module": "dist/little-state-machine.es.js", | ||
"jest": "27.5.0", | ||
"microbundle": "^0.14.2", | ||
"microbundle": "^0.15.1", | ||
"npm-run-all": "^4.1.5", | ||
@@ -37,0 +37,0 @@ "prettier": "^2.5.1", |
@@ -55,2 +55,9 @@ <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> | ||
storageType?: Storage; // session/local storage (default to session) | ||
// one of 'none' | 'action' | 'beforeUnload' | ||
// when 'none' is used then state is not persisted | ||
// when 'action' is used then state is saved to the storage after store action is completed | ||
// when 'beforeUnload' is used then state is saved to storage before page unload and is restored | ||
// after next page load and then storage is cleared | ||
persist?: 'onAction' // onAction is default if not provided | ||
}, | ||
@@ -57,0 +64,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
37180
100
3
196