@codescouts/vue-store-beta
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("pinia"),l=(t,r)=>(Object.entries(r).forEach(e=>{if(typeof e[1]=="object"&&t[e[0]]){const c=t[e[0]];t[e[0]]=l(c,e[1])}else t[e[0]]=e[1]}),t),u=(t,r)=>{const e=new t;return l(e,r),e},g=(t,r)=>typeof t=="string"?r:Array.isArray(r)?r.map(e=>u(t,e)):u(t,r),m=(t,r,e)=>{const c=Object.keys(t)[0],a=t[c];return(e?()=>e(a,Object.assign):()=>g(r,a))()},w=(t,r)=>{const e={withPersist:!1,factory:void 0},c=s=>typeof s=="string"?s:s.name,a=()=>{const{withPersist:s,factory:h}=e;let n;r(o=>{n=o});const f=c(t);if(s){const o=localStorage.getItem(f);if(o){let i;try{i=JSON.parse(o)}catch{i={}}n=m(i,t,h)}}return d.defineStore(t.name,{state:()=>({state:n}),actions:{save(o){this.$patch({state:o}),s&&localStorage.setItem(f,JSON.stringify(o))},get(){const o=this.$state.state;return g(t,o)}}})};return{build:a,withPersist:s=>(e.withPersist=!0,e.factory=s,{build:a})}};exports.create=w; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("pinia"),l=(t,r)=>(Object.entries(r).forEach(e=>{if(typeof e[1]=="object"&&t[e[0]]){const c=t[e[0]];t[e[0]]=l(c,e[1])}else t[e[0]]=e[1]}),t),u=(t,r)=>{const e=new t;return l(e,r),e},g=(t,r)=>typeof t=="string"?r:Array.isArray(r)?r.map(e=>u(t,e)):u(t,r),m=(t,r,e)=>{const c=Object.keys(t)[0],a=t[c];return(e?()=>e(a,Object.assign):()=>g(r,a))()},w=(t,r)=>{const e={withPersist:!1,factory:void 0},c=s=>typeof s=="string"?s:s.name,a=()=>{const{withPersist:s,factory:h}=e;let i=r();const f=c(t);if(s){const o=localStorage.getItem(f);if(o){let n;try{n=JSON.parse(o)}catch{n={}}i=m(n,t,h)}}return d.defineStore(t.name,{state:()=>({state:i}),actions:{save(o){this.$patch({state:o}),s&&localStorage.setItem(f,JSON.stringify(o))},get(){const o=this.$state.state;return g(t,o)}}})};return{build:a,withPersist:s=>(e.withPersist=!0,e.factory=s,{build:a})}};exports.create=w; |
@@ -20,6 +20,3 @@ import { defineStore as m } from "pinia"; | ||
const { withPersist: s, factory: S } = e; | ||
let n; | ||
r((o) => { | ||
n = o; | ||
}); | ||
let i = r(); | ||
const f = c(t); | ||
@@ -29,9 +26,9 @@ if (s) { | ||
if (o) { | ||
let i; | ||
let n; | ||
try { | ||
i = JSON.parse(o); | ||
n = JSON.parse(o); | ||
} catch { | ||
i = {}; | ||
n = {}; | ||
} | ||
n = w(i, t, S); | ||
i = w(n, t, S); | ||
} | ||
@@ -41,3 +38,3 @@ } | ||
state: () => ({ | ||
state: n | ||
state: i | ||
}), | ||
@@ -44,0 +41,0 @@ actions: { |
@@ -1,2 +0,2 @@ | ||
export type StateCreator<T> = (set: (value: Partial<T>) => void) => any; | ||
export type StateCreator<T> = () => Partial<T>; | ||
export type Factory = (persistedEntity: any, assign: <T extends {}, U>(target: T, source: U) => T & U) => unknown; | ||
@@ -3,0 +3,0 @@ export type Newly<T> = { |
{ | ||
"name": "@codescouts/vue-store-beta", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js", |
@@ -20,8 +20,4 @@ import { defineStore } from "pinia"; | ||
let initialState: Partial<T>; | ||
let initialState: Partial<T> = stateCreator(); | ||
stateCreator((value) => { | ||
initialState = value; | ||
}); | ||
const storageKey = getStoreKey(rootType); | ||
@@ -28,0 +24,0 @@ if (withPersist) { |
@@ -1,2 +0,2 @@ | ||
export type StateCreator<T> = (set: (value: Partial<T>) => void) => any; | ||
export type StateCreator<T> = () => Partial<T>; | ||
export type Factory = ( | ||
@@ -3,0 +3,0 @@ persistedEntity: any, |
8375
201