@codescouts/vue-store-beta
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -1,1 +0,1 @@ | ||
"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; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=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),m=(e,r,t)=>{const s=e.data;return(t?()=>t(s,Object.assign):()=>S(r,s))()},p=(e,r)=>{const t={withPersist:!1,entityType:void 0,factory:void 0},s=o=>typeof o=="string"?o:o.name,i=()=>{const{withPersist:o,entityType:n,factory:d}=t;if(o){const c=s(n),a=localStorage.getItem(c);if(a){let f;try{f=JSON.parse(a)}catch{f={}}r=m(f,n,d)}}return h.defineStore(e,{state:()=>({state:r}),actions:{save(c){if(this.$patch({state:c}),o){const a=s(n);localStorage.setItem(a,JSON.stringify({data:c}))}},get(){const{state:c}=this.$state;return c}}})};function u(o,n){return t.entityType=o,t.withPersist=!0,t.factory=n,{build:i}}return{build:i,withPersist:u}};exports.create=p; |
@@ -1,6 +0,6 @@ | ||
import { defineStore as m } from "pinia"; | ||
import { defineStore as d } from "pinia"; | ||
const h = (e, r) => (Object.entries(r).forEach((t) => { | ||
if (typeof t[1] == "object" && e[t[0]]) { | ||
const o = e[t[0]]; | ||
e[t[0]] = h(o, t[1]); | ||
const s = e[t[0]]; | ||
e[t[0]] = h(s, t[1]); | ||
} else | ||
@@ -11,5 +11,5 @@ e[t[0]] = t[1]; | ||
return h(t, r), t; | ||
}, 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))(); | ||
}, m = (e, r) => typeof e == "string" ? r : Array.isArray(r) ? r.map((t) => g(e, t)) : g(e, r), S = (e, r, t) => { | ||
const s = e.data; | ||
return (t ? () => t(s, Object.assign) : () => m(r, s))(); | ||
}, y = (e, r) => { | ||
@@ -20,36 +20,30 @@ const t = { | ||
factory: void 0 | ||
}, 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) { | ||
}, s = (o) => typeof o == "string" ? o : o.name, i = () => { | ||
const { withPersist: o, entityType: n, factory: l } = t; | ||
if (o) { | ||
const c = s(n), a = localStorage.getItem(c); | ||
if (a) { | ||
let f; | ||
try { | ||
f = JSON.parse(n); | ||
f = JSON.parse(a); | ||
} catch { | ||
f = {}; | ||
} | ||
r = p(f, a, l); | ||
r = S(f, n, l); | ||
} | ||
} | ||
return m(e, { | ||
return d(e, { | ||
state: () => ({ | ||
state: { | ||
state: r | ||
} | ||
state: r | ||
}), | ||
actions: { | ||
save(c) { | ||
if (this.$patch({ | ||
state: { | ||
state: c | ||
} | ||
}), s) { | ||
const n = o(a); | ||
localStorage.setItem(n, JSON.stringify(c)); | ||
if (this.$patch({ state: c }), o) { | ||
const a = s(n); | ||
localStorage.setItem(a, JSON.stringify({ data: c })); | ||
} | ||
}, | ||
get() { | ||
var c; | ||
return (c = this.$state.state) == null ? void 0 : c.state; | ||
const { state: c } = this.$state; | ||
return c; | ||
} | ||
@@ -59,4 +53,4 @@ } | ||
}; | ||
function u(s, a) { | ||
return t.entityType = s, t.withPersist = !0, t.factory = a, { build: i }; | ||
function u(o, n) { | ||
return t.entityType = o, t.withPersist = !0, t.factory = n, { build: i }; | ||
} | ||
@@ -63,0 +57,0 @@ return { build: i, withPersist: u }; |
{ | ||
"name": "@codescouts/vue-store-beta", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"type": "module", | ||
@@ -29,2 +29,3 @@ "main": "./dist/index.cjs.js", | ||
"devDependencies": { | ||
"@codescouts/vue-store-beta": "^1.0.10", | ||
"@types/node": "^20.1.1", | ||
@@ -31,0 +32,0 @@ "@typescript-eslint/eslint-plugin": "^5.57.1", |
@@ -20,3 +20,3 @@ import { create } from "./auto-create"; | ||
) => { | ||
const persistedEntity = persistedState.state; | ||
const persistedEntity = persistedState.data; | ||
@@ -23,0 +23,0 @@ const factoryImpl = !!factory |
@@ -36,21 +36,18 @@ import { defineStore } from "pinia"; | ||
state: () => ({ | ||
state: { | ||
state: initialState, | ||
}, | ||
state: initialState, | ||
}), | ||
actions: { | ||
save(state: T) { | ||
this.$patch({ | ||
state: { | ||
state, | ||
}, | ||
}); | ||
this.$patch({ state }); | ||
if (withPersist) { | ||
const storageKey = getStoreKey(entityType); | ||
localStorage.setItem(storageKey, JSON.stringify(state)); | ||
localStorage.setItem(storageKey, JSON.stringify({ data: state })); | ||
} | ||
}, | ||
get(): T | T[] { | ||
return this.$state.state?.state as T | T[]; | ||
const { state } = this.$state; | ||
return state as T | T[]; | ||
}, | ||
@@ -57,0 +54,0 @@ }, |
8790
10
214