@codescouts/vue-store-beta
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("pinia"),S=(e,r)=>(Object.entries(r).forEach(t=>{if(typeof t[1]=="object"&&e[t[0]]){const s=e[t[0]];e[t[0]]=S(s,t[1])}else e[t[0]]=t[1]}),e),g=(e,r)=>{const t=new e;return S(t,r),t},y=(e,r)=>typeof e=="string"?r:Array.isArray(r)?r.map(t=>g(e,t)):g(e,r),m=(e,r,t)=>{const s=Object.keys(e)[0],c=e[s];return(t?()=>t(c,Object.assign):()=>y(r,c))()},p=(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;let l=r();if(o){const i=s(n),a=localStorage.getItem(i);if(a){let f;try{f=JSON.parse(a)}catch{f={}}l=m(f,n,h)}}return d.defineStore(e,{state:()=>({state:l}),actions:{save(i){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=p; | ||
"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; |
import { defineStore as m } from "pinia"; | ||
const S = (e, r) => (Object.entries(r).forEach((t) => { | ||
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]] = S(s, t[1]); | ||
e[t[0]] = h(s, t[1]); | ||
} else | ||
e[t[0]] = t[1]; | ||
}), e), l = (e, r) => { | ||
}), e), u = (e, r) => { | ||
const t = new e(); | ||
return S(t, r), t; | ||
}, d = (e, r) => typeof e == "string" ? r : Array.isArray(r) ? r.map((t) => l(e, t)) : l(e, r), y = (e, r, t) => { | ||
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) : () => d(r, c))(); | ||
}, P = (e, r) => { | ||
return (t ? () => t(c, Object.assign) : () => y(r, c))(); | ||
}, w = (e, r) => { | ||
const t = { | ||
@@ -20,4 +20,3 @@ withPersist: !1, | ||
}, s = (o) => typeof o == "string" ? o : o.name, c = () => { | ||
const { withPersist: o, entityType: n, factory: h } = t; | ||
let g = r(); | ||
const { withPersist: o, entityType: n, factory: l } = t; | ||
if (o) { | ||
@@ -32,3 +31,3 @@ const a = s(n), i = localStorage.getItem(a); | ||
} | ||
g = y(f, n, h); | ||
r = S(f, n, l); | ||
} | ||
@@ -38,6 +37,7 @@ } | ||
state: () => ({ | ||
state: g | ||
state: r | ||
}), | ||
actions: { | ||
save(a) { | ||
debugger; | ||
if (this.$patch({ state: a }), o) { | ||
@@ -54,9 +54,9 @@ const i = s(n); | ||
}; | ||
function u(o, n) { | ||
function g(o, n) { | ||
return t.entityType = o, t.withPersist = !0, t.factory = n, { build: c }; | ||
} | ||
return { build: c, withPersist: u }; | ||
return { build: c, withPersist: g }; | ||
}; | ||
export { | ||
P as create | ||
w as create | ||
}; |
import { Factory, Newly, Return, Store } from "./store.types"; | ||
export declare const create: <T, S>(id: string, stateCreator: () => Partial<T>) => { | ||
export declare const create: <T, S>(id: string, initialState: T) => { | ||
build: () => Store<T, S>; | ||
@@ -4,0 +4,0 @@ withPersist: { |
@@ -1,2 +0,2 @@ | ||
export type StateCreator<T> = () => Partial<T>; | ||
export type StateCreator<T> = (set: (value: Partial<T>) => void) => any; | ||
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.7", | ||
"version": "1.0.8", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js", |
@@ -27,5 +27,5 @@ import { create } from "./auto-create"; | ||
const restoredState = factoryImpl(); | ||
const restoredState = factoryImpl() as E; | ||
return restoredState as E; | ||
return restoredState; | ||
}; |
@@ -5,3 +5,3 @@ import { defineStore } from "pinia"; | ||
export const create = <T, S>(id: string, stateCreator: () => Partial<T>) => { | ||
export const create = <T, S>(id: string, initialState: T) => { | ||
const configuration = { | ||
@@ -19,4 +19,2 @@ withPersist: false, | ||
let initialState: Partial<T> = stateCreator(); | ||
if (withPersist) { | ||
@@ -34,5 +32,3 @@ const storageKey = getStoreKey(entityType); | ||
const restoredState = merge(persistedState, entityType, factory); | ||
initialState = restoredState as T; | ||
initialState = merge(persistedState, entityType, factory); | ||
} | ||
@@ -47,2 +43,3 @@ } | ||
save(state: T) { | ||
debugger; | ||
this.$patch({ state }); | ||
@@ -49,0 +46,0 @@ |
@@ -1,2 +0,2 @@ | ||
export type StateCreator<T> = () => Partial<T>; | ||
export type StateCreator<T> = (set: (value: Partial<T>) => void) => any; | ||
export type Factory = ( | ||
@@ -3,0 +3,0 @@ persistedEntity: any, |
8793
215