@codescouts/vue-store-beta
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("pinia"),l=(e,r)=>(Object.entries(r).forEach(t=>{if(typeof t[1]=="object"&&e[t[0]]){const s=e[t[0]];e[t[0]]=l(s,t[1])}else e[t[0]]=t[1]}),e),g=(e,r)=>{const t=new e;return l(t,r),t},S=(e,r)=>typeof e=="string"?r:Array.isArray(r)?r.map(t=>g(e,t)):g(e,r),d=(e,r,t)=>{const s=Object.keys(e)[0],c=e[s];return(t?()=>t(c,Object.assign):()=>S(r,c))()},m=(e,r)=>{const t={withPersist:!1,entityType:void 0,factory:void 0},s=o=>typeof o=="string"?o:o.name,c=()=>{const{withPersist:o,entityType:n,factory:h}=t;if(o){const i=s(n),a=localStorage.getItem(i);if(a){let f;try{f=JSON.parse(a)}catch{f={}}r=d(f,n,h)}}return y.defineStore(e,{state:()=>({state:r}),actions:{save(i){debugger;if(this.$patch({state:i}),o){const a=s(n);localStorage.setItem(a,JSON.stringify(i))}},get(){return this.$state.state}}})};function u(o,n){return t.entityType=o,t.withPersist=!0,t.factory=n,{build:c}}return{build:c,withPersist:u}};exports.create=m; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("pinia"),l=(e,r)=>(Object.entries(r).forEach(t=>{if(typeof t[1]=="object"&&e[t[0]]){const o=e[t[0]];e[t[0]]=l(o,t[1])}else e[t[0]]=t[1]}),e),g=(e,r)=>{const t=new e;return l(t,r),t},d=(e,r)=>typeof e=="string"?r:Array.isArray(r)?r.map(t=>g(e,t)):g(e,r),m=(e,r,t)=>{const o=e.state;return(t?()=>t(o,Object.assign):()=>d(r,o))()},p=(e,r)=>{const t={withPersist:!1,entityType:void 0,factory:void 0},o=s=>typeof s=="string"?s:s.name,i=()=>{const{withPersist:s,entityType:a,factory:h}=t;if(s){const c=o(a),n=localStorage.getItem(c);if(n){let f;try{f=JSON.parse(n)}catch{f={}}r=m(f,a,h)}}return S.defineStore(e,{state:()=>({state:{state:r}}),actions:{save(c){if(this.$patch({state:{state:c}}),s){const n=o(a);localStorage.setItem(n,JSON.stringify(c))}},get(){var c;return(c=this.$state.state)==null?void 0:c.state}}})};function u(s,a){return t.entityType=s,t.withPersist=!0,t.factory=a,{build:i}}return{build:i,withPersist:u}};exports.create=p; |
import { defineStore as m } from "pinia"; | ||
const h = (e, r) => (Object.entries(r).forEach((t) => { | ||
if (typeof t[1] == "object" && e[t[0]]) { | ||
const s = e[t[0]]; | ||
e[t[0]] = h(s, t[1]); | ||
const o = e[t[0]]; | ||
e[t[0]] = h(o, t[1]); | ||
} else | ||
e[t[0]] = t[1]; | ||
}), e), u = (e, r) => { | ||
}), e), g = (e, r) => { | ||
const t = new e(); | ||
return h(t, r), t; | ||
}, y = (e, r) => typeof e == "string" ? r : Array.isArray(r) ? r.map((t) => u(e, t)) : u(e, r), S = (e, r, t) => { | ||
const s = Object.keys(e)[0], c = e[s]; | ||
return (t ? () => t(c, Object.assign) : () => y(r, c))(); | ||
}, w = (e, r) => { | ||
}, S = (e, r) => typeof e == "string" ? r : Array.isArray(r) ? r.map((t) => g(e, t)) : g(e, r), p = (e, r, t) => { | ||
const o = e.state; | ||
return (t ? () => t(o, Object.assign) : () => S(r, o))(); | ||
}, y = (e, r) => { | ||
const t = { | ||
@@ -19,14 +19,14 @@ withPersist: !1, | ||
factory: void 0 | ||
}, s = (o) => typeof o == "string" ? o : o.name, c = () => { | ||
const { withPersist: o, entityType: n, factory: l } = t; | ||
if (o) { | ||
const a = s(n), i = localStorage.getItem(a); | ||
if (i) { | ||
}, o = (s) => typeof s == "string" ? s : s.name, i = () => { | ||
const { withPersist: s, entityType: a, factory: l } = t; | ||
if (s) { | ||
const c = o(a), n = localStorage.getItem(c); | ||
if (n) { | ||
let f; | ||
try { | ||
f = JSON.parse(i); | ||
f = JSON.parse(n); | ||
} catch { | ||
f = {}; | ||
} | ||
r = S(f, n, l); | ||
r = p(f, a, l); | ||
} | ||
@@ -36,14 +36,20 @@ } | ||
state: () => ({ | ||
state: r | ||
state: { | ||
state: r | ||
} | ||
}), | ||
actions: { | ||
save(a) { | ||
debugger; | ||
if (this.$patch({ state: a }), o) { | ||
const i = s(n); | ||
localStorage.setItem(i, JSON.stringify(a)); | ||
save(c) { | ||
if (this.$patch({ | ||
state: { | ||
state: c | ||
} | ||
}), s) { | ||
const n = o(a); | ||
localStorage.setItem(n, JSON.stringify(c)); | ||
} | ||
}, | ||
get() { | ||
return this.$state.state; | ||
var c; | ||
return (c = this.$state.state) == null ? void 0 : c.state; | ||
} | ||
@@ -53,9 +59,9 @@ } | ||
}; | ||
function g(o, n) { | ||
return t.entityType = o, t.withPersist = !0, t.factory = n, { build: c }; | ||
function u(s, a) { | ||
return t.entityType = s, t.withPersist = !0, t.factory = a, { build: i }; | ||
} | ||
return { build: c, withPersist: g }; | ||
return { build: i, withPersist: u }; | ||
}; | ||
export { | ||
w as create | ||
y as create | ||
}; |
{ | ||
"name": "@codescouts/vue-store-beta", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js", |
@@ -20,4 +20,3 @@ import { create } from "./auto-create"; | ||
) => { | ||
const entityKey = Object.keys(persistedState)[0]; | ||
const persistedEntity = persistedState[entityKey]; | ||
const persistedEntity = persistedState.state; | ||
@@ -24,0 +23,0 @@ const factoryImpl = !!factory |
@@ -36,8 +36,13 @@ import { defineStore } from "pinia"; | ||
state: () => ({ | ||
state: initialState, | ||
state: { | ||
state: initialState, | ||
}, | ||
}), | ||
actions: { | ||
save(state: T) { | ||
debugger; | ||
this.$patch({ state }); | ||
this.$patch({ | ||
state: { | ||
state, | ||
}, | ||
}); | ||
@@ -50,3 +55,3 @@ if (withPersist) { | ||
get(): T | T[] { | ||
return this.$state.state as T | T[]; | ||
return this.$state.state?.state as T | T[]; | ||
}, | ||
@@ -53,0 +58,0 @@ }, |
8932
225