little-state-machine
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -7,5 +7,5 @@ import { createContext, useState, useMemo, createElement, useContext, useCallback } from 'react'; | ||
var getBrowserStoreData = async (storageType, storeName) => { | ||
var getBrowserStoreData = (storageType, storeName) => { | ||
const sessionStorageData = storageType.getItem(storeName); | ||
try { | ||
const sessionStorageData = await storageType.getItem(storeName); | ||
return sessionStorageData ? JSON.parse(sessionStorageData) : undefined; | ||
@@ -18,5 +18,5 @@ } | ||
async function storeFactory(storageType, name) { | ||
function storeFactory(storageType, name) { | ||
const storeName = name || STORE_DEFAULT_NAME; | ||
let store = await getBrowserStoreData(storageType, storeName); | ||
let store = getBrowserStoreData(storageType, storeName); | ||
const getName = () => storeName; | ||
@@ -88,4 +88,4 @@ const set = (value) => { | ||
else { | ||
Object.entries(syncStoreOption).forEach(async ([key, values]) => { | ||
const browserStore = await getBrowserStoreData(storageType, key); | ||
Object.entries(syncStoreOption).forEach(([key, values]) => { | ||
const browserStore = getBrowserStoreData(storageType, key); | ||
values.forEach((value) => { | ||
@@ -137,14 +137,13 @@ store = Object.assign(Object.assign({}, store), { | ||
const storeName = options ? options.name : STORE_DEFAULT_NAME; | ||
storeFactory(storageType, storeName).then(methods => { | ||
if (isDevMode && isClient) { | ||
// @ts-ignore | ||
window['STATE_MACHINE_NAME'] = storeName; | ||
} | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
}); | ||
const methods = storeFactory(storageType, storeName); | ||
if (isDevMode && isClient) { | ||
// @ts-ignore | ||
window['STATE_MACHINE_NAME'] = storeName; | ||
} | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
} | ||
@@ -151,0 +150,0 @@ function StateMachineProvider(props) { |
@@ -17,8 +17,4 @@ 'use strict'; | ||
var _Symbol$iterator = require("@babel/runtime-corejs3/core-js-stable/symbol/iterator"); | ||
var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol"); | ||
var _Promise = require("@babel/runtime-corejs3/core-js-stable/promise"); | ||
var _Object$assign = require("@babel/runtime-corejs3/core-js-stable/object/assign"); | ||
@@ -63,139 +59,2 @@ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
return new (P || (P = _Promise))(function (resolve, reject) { | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function rejected(value) { | ||
try { | ||
step(generator["throw"](value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : new P(function (resolve) { | ||
resolve(result.value); | ||
}).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { | ||
label: 0, | ||
sent: function () { | ||
if (t[0] & 1) throw t[1]; | ||
return t[1]; | ||
}, | ||
trys: [], | ||
ops: [] | ||
}, | ||
f, | ||
y, | ||
t, | ||
g; | ||
return g = { | ||
next: verb(0), | ||
"throw": verb(1), | ||
"return": verb(2) | ||
}, typeof _Symbol === "function" && (g[_Symbol$iterator] = function () { | ||
return this; | ||
}), g; | ||
function verb(n) { | ||
return function (v) { | ||
return step([n, v]); | ||
}; | ||
} | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: | ||
case 1: | ||
t = op; | ||
break; | ||
case 4: | ||
_.label++; | ||
return { | ||
value: op[1], | ||
done: false | ||
}; | ||
case 5: | ||
_.label++; | ||
y = op[1]; | ||
op = [0]; | ||
continue; | ||
case 7: | ||
op = _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { | ||
_ = 0; | ||
continue; | ||
} | ||
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { | ||
_.label = op[1]; | ||
break; | ||
} | ||
if (op[0] === 6 && _.label < t[1]) { | ||
_.label = t[1]; | ||
t = op; | ||
break; | ||
} | ||
if (t && _.label < t[2]) { | ||
_.label = t[2]; | ||
_.ops.push(op); | ||
break; | ||
} | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { | ||
op = [6, e]; | ||
y = 0; | ||
} finally { | ||
f = t = 0; | ||
} | ||
if (op[0] & 5) throw op[1]; | ||
return { | ||
value: op[0] ? op[1] : void 0, | ||
done: true | ||
}; | ||
} | ||
} | ||
function __read(o, n) { | ||
@@ -232,71 +91,32 @@ var m = typeof _Symbol === "function" && _getIteratorMethod(o); | ||
var getBrowserStoreData = function (storageType, storeName) { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var sessionStorageData, _a; | ||
var sessionStorageData = storageType.getItem(storeName); | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 2,, 3]); | ||
return [4 | ||
/*yield*/ | ||
, storageType.getItem(storeName)]; | ||
case 1: | ||
sessionStorageData = _b.sent(); | ||
return [2 | ||
/*return*/ | ||
, sessionStorageData ? JSON.parse(sessionStorageData) : undefined]; | ||
case 2: | ||
_a = _b.sent(); | ||
return [2 | ||
/*return*/ | ||
, undefined]; | ||
case 3: | ||
return [2 | ||
/*return*/ | ||
]; | ||
} | ||
}); | ||
}); | ||
try { | ||
return sessionStorageData ? JSON.parse(sessionStorageData) : undefined; | ||
} catch (_a) { | ||
return undefined; | ||
} | ||
}; | ||
function storeFactory(storageType, name) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var storeName, store, getName, set, get; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
storeName = name || STORE_DEFAULT_NAME; | ||
return [4 | ||
/*yield*/ | ||
, getBrowserStoreData(storageType, storeName)]; | ||
var storeName = name || STORE_DEFAULT_NAME; | ||
var store = getBrowserStoreData(storageType, storeName); | ||
case 1: | ||
store = _a.sent(); | ||
var getName = function () { | ||
return storeName; | ||
}; | ||
getName = function () { | ||
return storeName; | ||
}; | ||
var set = function (value) { | ||
store = value; | ||
}; | ||
set = function (value) { | ||
store = value; | ||
}; | ||
var get = function () { | ||
return store; | ||
}; | ||
get = function () { | ||
return store; | ||
}; | ||
return [2 | ||
/*return*/ | ||
, { | ||
set: set, | ||
get: get, | ||
getName: getName | ||
}]; | ||
} | ||
}); | ||
}); | ||
return { | ||
set: set, | ||
get: get, | ||
getName: getName | ||
}; | ||
} | ||
@@ -357,4 +177,2 @@ | ||
function getSyncStoreData(defaultStoreData, options, storageType) { | ||
var _this = this; | ||
var store = defaultStoreData; | ||
@@ -389,25 +207,8 @@ var syncStoreOption = options.syncStores; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var browserStore; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
return [4 | ||
/*yield*/ | ||
, getBrowserStoreData(storageType, key)]; | ||
var browserStore = getBrowserStoreData(storageType, key); | ||
case 1: | ||
browserStore = _c.sent(); | ||
_forEachInstanceProperty(values).call(values, function (value) { | ||
var _a; | ||
_forEachInstanceProperty(values).call(values, function (value) { | ||
var _a; | ||
store = __assign(__assign({}, store), (_a = {}, _a[value] = __assign(__assign({}, store[value]), browserStore[value]), _a)); | ||
}); | ||
return [2 | ||
/*return*/ | ||
]; | ||
} | ||
}); | ||
store = __assign(__assign({}, store), (_a = {}, _a[value] = __assign(__assign({}, store[value]), browserStore[value]), _a)); | ||
}); | ||
@@ -471,15 +272,15 @@ }); | ||
var storeName = options ? options.name : STORE_DEFAULT_NAME; | ||
storeFactory(storageType, storeName).then(function (methods) { | ||
if (isDevMode && isClient) { | ||
// @ts-ignore | ||
window['STATE_MACHINE_NAME'] = storeName; | ||
} | ||
var methods = storeFactory(storageType, storeName); | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
}); | ||
if (isDevMode && isClient) { | ||
// @ts-ignore | ||
window['STATE_MACHINE_NAME'] = storeName; | ||
} | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
} | ||
@@ -486,0 +287,0 @@ |
@@ -11,5 +11,5 @@ 'use strict'; | ||
var getBrowserStoreData = async (storageType, storeName) => { | ||
var getBrowserStoreData = (storageType, storeName) => { | ||
const sessionStorageData = storageType.getItem(storeName); | ||
try { | ||
const sessionStorageData = await storageType.getItem(storeName); | ||
return sessionStorageData ? JSON.parse(sessionStorageData) : undefined; | ||
@@ -22,5 +22,5 @@ } | ||
async function storeFactory(storageType, name) { | ||
function storeFactory(storageType, name) { | ||
const storeName = name || STORE_DEFAULT_NAME; | ||
let store = await getBrowserStoreData(storageType, storeName); | ||
let store = getBrowserStoreData(storageType, storeName); | ||
const getName = () => storeName; | ||
@@ -92,4 +92,4 @@ const set = (value) => { | ||
else { | ||
Object.entries(syncStoreOption).forEach(async ([key, values]) => { | ||
const browserStore = await getBrowserStoreData(storageType, key); | ||
Object.entries(syncStoreOption).forEach(([key, values]) => { | ||
const browserStore = getBrowserStoreData(storageType, key); | ||
values.forEach((value) => { | ||
@@ -141,14 +141,13 @@ store = Object.assign(Object.assign({}, store), { | ||
const storeName = options ? options.name : STORE_DEFAULT_NAME; | ||
storeFactory(storageType, storeName).then(methods => { | ||
if (isDevMode && isClient) { | ||
// @ts-ignore | ||
window['STATE_MACHINE_NAME'] = storeName; | ||
} | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
}); | ||
const methods = storeFactory(storageType, storeName); | ||
if (isDevMode && isClient) { | ||
// @ts-ignore | ||
window['STATE_MACHINE_NAME'] = storeName; | ||
} | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
} | ||
@@ -155,0 +154,0 @@ function StateMachineProvider(props) { |
@@ -1,1 +0,1 @@ | ||
import{createContext as e,useState as t,useMemo as r,createElement as n,useContext as o,useCallback as a}from"react";var s=async(e,t)=>{try{const r=await e.getItem(t);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 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__";(async function(e,t){const r=t||"__STATE_MACHINE__";let n=await s(e,r);return{set:e=>{n=e},get:()=>n,getName:()=>r}})(l,r).then(n=>{S&&E&&(window.STATE_MACHINE_NAME=r),A=n.getName,d=n.get,m=n.set,T=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)||""))}(S,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(async([e,t])=>{const o=await 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(S&&((e="")=>{e&&E&&(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(T)&&T.length&&(e=T.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,u as setStorageType,w 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 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}; |
@@ -10,5 +10,5 @@ (function (global, factory) { | ||
var getBrowserStoreData = async (storageType, storeName) => { | ||
var getBrowserStoreData = (storageType, storeName) => { | ||
const sessionStorageData = storageType.getItem(storeName); | ||
try { | ||
const sessionStorageData = await storageType.getItem(storeName); | ||
return sessionStorageData ? JSON.parse(sessionStorageData) : undefined; | ||
@@ -21,5 +21,5 @@ } | ||
async function storeFactory(storageType, name) { | ||
function storeFactory(storageType, name) { | ||
const storeName = name || STORE_DEFAULT_NAME; | ||
let store = await getBrowserStoreData(storageType, storeName); | ||
let store = getBrowserStoreData(storageType, storeName); | ||
const getName = () => storeName; | ||
@@ -91,4 +91,4 @@ const set = (value) => { | ||
else { | ||
Object.entries(syncStoreOption).forEach(async ([key, values]) => { | ||
const browserStore = await getBrowserStoreData(storageType, key); | ||
Object.entries(syncStoreOption).forEach(([key, values]) => { | ||
const browserStore = getBrowserStoreData(storageType, key); | ||
values.forEach((value) => { | ||
@@ -133,10 +133,9 @@ store = Object.assign(Object.assign({}, store), { | ||
const storeName = options ? options.name : STORE_DEFAULT_NAME; | ||
storeFactory(storageType, storeName).then(methods => { | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
}); | ||
const methods = storeFactory(storageType, storeName); | ||
getName = methods.getName; | ||
getStore = methods.get; | ||
setStore = methods.set; | ||
middleWaresArray = options.middleWares; | ||
setUpDevTools(isDevMode, storageType, getName, getStore); | ||
setStore(getSyncStoreData(getStore() || defaultStoreData, options, storageType)); | ||
} | ||
@@ -143,0 +142,0 @@ function StateMachineProvider(props) { |
@@ -1,2 +0,2 @@ | ||
declare const _default: (storageType: Storage, storeName: string) => Promise<any>; | ||
declare const _default: (storageType: Storage, storeName: string) => any; | ||
export default _default; |
import { GetStoreName, GetStore, SetStore } from '../types'; | ||
export default function storeFactory<T>(storageType: Storage, name: string | undefined): Promise<{ | ||
export default function storeFactory<T>(storageType: Storage, name: string | undefined): { | ||
set: SetStore; | ||
get: GetStore; | ||
getName: GetStoreName; | ||
}>; | ||
}; |
@@ -7,3 +7,3 @@ import { TransformFunc } from '../types'; | ||
store: any; | ||
}) => Promise<any>; | ||
}) => any; | ||
export default _default; |
{ | ||
"name": "little-state-machine", | ||
"sideEffects": false, | ||
"version": "3.1.0", | ||
"version": "3.1.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
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
0
49316
23
1025