pinia-plugin-data
Advanced tools
+1
-9
@@ -7,11 +7,3 @@ import { PiniaPluginContext, StateTree } from 'pinia'; | ||
| serializer?: Serializer; | ||
| /** | ||
| * Hook called before state is hydrated from storage. | ||
| * @default undefined | ||
| */ | ||
| beforeRestore?: (context: PiniaPluginContext) => void; | ||
| /** | ||
| * Hook called after state is hydrated from storage. | ||
| * @default undefined | ||
| */ | ||
| afterRestore?: (context: PiniaPluginContext) => void; | ||
@@ -26,3 +18,3 @@ onExpire?(store: StateTree): boolean; | ||
| * @param store Store data has resumed durable | ||
| * @return true | undefaine The default is to reject, you to return a clear state. false Represents data retention | ||
| * @return true | undefined The default is to reject, you to return a clear state. false Represents data retention | ||
| */ | ||
@@ -29,0 +21,0 @@ onExpire(store: StateTree): boolean; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| import"pinia";import{shallowRef as e}from"vue";class t{key;storage;serializer;constructor(e,t,s){this.key=e,this.storage=t,this.serializer=s}beforeRestore(){}afterRestore(){}onExpire(e){return!1}}const s=e(window.localStorage);class r{getItem(e){return s.value.getItem(e)}setItem(e,t){s.value.setItem(e,t)}removeItem(e){s.value.removeItem(e)}}class i{deserialize(e){return JSON.parse(e)}serialize(e){return JSON.stringify(e)}}class o{state;slave;values=[];constructor(e){this.slave=e,this.state="onWaiting"}dispatch(e){e.dispatch().then((()=>Promise.resolve(e.onExpire()))).then(a({reset:e.reset}))}trigger(e){if(e.center)e.dispatch().then((()=>Promise.resolve(e.onExpire()))).then((t=>{t||void 0===t?(this.state="onReject",e.reset(),this.values.forEach((({reset:e})=>{e()}))):(this.state="onResolve",this.values.forEach(this.dispatch)),this.values.length=0}));else if("onResolve"===this.state)this.dispatch(e);else if("onWaiting"===this.state)this.values.push({dispatch:e.dispatch,reset:e.reset,onExpire:e.onExpire});else{if("onReject"!==this.state)throw new Error(`未知的${this.state}状态`);e.reset()}}}const n=new Map;function a(e){return t=>{(t||void 0===t)&&e.reset()}}const c=()=>{};function l(e,t){try{const s=e.serializer,r=e.key,i=e.storage,c=s.serialize(r),l=i.getItem(c);if(null===l)return;const h=s.deserialize(l),p=async()=>(await Promise.resolve(e.beforeRestore(t)),await Promise.resolve(t.store.$patch(h)),await Promise.resolve(e.afterRestore(t))),u=()=>{const e=t.options.state?.();e&&t.store.$patch(e),i.removeItem(c)};"slave"in e?function(e){const t=n.get(e);if(t)return t;{const t=new o(e);return n.set(e,t),t}}(e.slave).trigger({dispatch:p,center:e.center,reset:u,onExpire:()=>e.onExpire(t.store)}):p().then((()=>{Promise.resolve(e.onExpire(t.store)).then(a({reset:u}))}))}catch(e){throw e}}function h(e,s){const o=function(e,s){if("boolean"==typeof s)return new t(e.store.$id,new r,new i);{const t=s;return{key:t.key??e.store.$id,afterRestore:t.afterRestore??c,beforeRestore:t.beforeRestore??c,serializer:t.serializer??new i,storage:t.storage??new r,slave:t.slave??void 0,center:t.center??!1,onExpire:t.onExpire??(()=>!1)}}}(e,s);l(o,e),e.store.$subscribe(((e,t)=>{const s=o.serializer,r=o.key;o.storage.setItem(s.serialize(r),s.serialize(t))}),{deep:!0,detached:!0})}function p(e){e.options.persistence&&h(e,e.options.persistence)}export{p as default}; | ||
| import"pinia";import{shallowRef as e}from"vue";class t{key;storage;serializer;constructor(e,t,s){this.key=e,this.storage=t,this.serializer=s}beforeRestore(){}afterRestore(){}onExpire(e){return!1}}const s=e(window.localStorage);class r{getItem(e){return s.value.getItem(e)}setItem(e,t){s.value.setItem(e,t)}removeItem(e){s.value.removeItem(e)}}class i{deserialize(e){return JSON.parse(e)}serialize(e){return JSON.stringify(e)}}class o{state;slave;values=[];constructor(e){this.slave=e,this.state="onWaiting"}dispatch(e){e.dispatch().then((()=>e.onExpire())).then(a({reset:e.reset}))}trigger(e){if(e.center)e.dispatch().then((()=>e.onExpire())).then((t=>{t||void 0===t?(this.state="onReject",e.reset(),this.values.forEach((({reset:e})=>{e()}))):(this.state="onResolve",this.values.forEach(this.dispatch)),this.values.length=0}));else if("onResolve"===this.state)this.dispatch(e);else if("onWaiting"===this.state)this.values.push({dispatch:e.dispatch,reset:e.reset,onExpire:e.onExpire});else{if("onReject"!==this.state)throw new Error(`未知的${this.state}状态`);e.reset()}}}const n=new Map;function a(e){return t=>{(t||void 0===t)&&e.reset}}const c=()=>{};function l(e,t){try{const s=e.serializer,r=e.key,i=e.storage,c=s.serialize(r),l=i.getItem(c);if(null===l)return;const h=s.deserialize(l),p=async()=>{await e.beforeRestore(t),await t.store.$patch(h),await e.afterRestore(t)},u=()=>{const e=t.options.state?.();e&&t.store.$patch(e),i.removeItem(c)};"slave"in e?function(e){const t=n.get(e);if(t)return t;{const t=new o(e);return n.set(e,t),t}}(e.slave).trigger({dispatch:p,center:e.center,reset:u,onExpire:()=>e.onExpire(t.store)}):p().then((()=>{Promise.resolve(e.onExpire(t.store)).then(a({reset:u}))}))}catch(e){throw e}}function h(e,s){const o=function(e,s){if("boolean"==typeof s)return new t(e.store.$id,new r,new i);{const t=s;return{key:t.key??e.store.$id,afterRestore:t.afterRestore??c,beforeRestore:t.beforeRestore??c,serializer:t.serializer??new i,storage:t.storage??new r,slave:t.slave??void 0,center:t.center??!1,onExpire:t.onExpire??(()=>!1)}}}(e,s);l(o,e),e.store.$subscribe(((e,t)=>{!function(e,t,s,r){t.setItem(s.serialize(r),s.serialize(e))}(t,o.storage,o.serializer,o.key)}),{deep:!0,detached:!0})}function p(e){e.options.persistence&&h(e,e.options.persistence)}export{p as default}; |
@@ -7,11 +7,3 @@ import { Serializer, StorageLike } from "./index"; | ||
| serializer?: Serializer; | ||
| /** | ||
| * Hook called before state is hydrated from storage. | ||
| * @default undefined | ||
| */ | ||
| beforeRestore?: (context: PiniaPluginContext) => void; | ||
| /** | ||
| * Hook called after state is hydrated from storage. | ||
| * @default undefined | ||
| */ | ||
| afterRestore?: (context: PiniaPluginContext) => void; | ||
@@ -26,3 +18,3 @@ onExpire?(store: StateTree): boolean; | ||
| * @param store Store data has resumed durable | ||
| * @return true | undefaine The default is to reject, you to return a clear state. false Represents data retention | ||
| * @return true | undefined The default is to reject, you to return a clear state. false Represents data retention | ||
| */ | ||
@@ -29,0 +21,0 @@ onExpire(store: StateTree): boolean; |
+10
-8
| { | ||
| "name": "pinia-plugin-data", | ||
| "version": "0.0.9", | ||
| "version": "0.0.10", | ||
| "main": "./lib/index.min.js", | ||
@@ -12,16 +12,18 @@ "types": "./lib/index.d.ts", | ||
| "peerDependencies": { | ||
| "pinia": "^2.0.17", | ||
| "vue": "^3.2.37" | ||
| "pinia": "^2.0.17" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "pinia": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "devDependencies": { | ||
| "@rollup/plugin-node-resolve": "^13.3.0", | ||
| "vue": "^3.2.37", | ||
| "@rollup/plugin-typescript": "^8.3.3", | ||
| "@vue/tsconfig": "^0.1.3", | ||
| "rollup": "^2.77.0", | ||
| "rollup-plugin-dts": "^4.2.2", | ||
| "rollup-plugin-filesize": "^9.1.2", | ||
| "rollup-plugin-terser": "^7.0.2", | ||
| "tslib": "^2.4.0", | ||
| "typescript": "~4.7.4", | ||
| "vite": "^3.0.2", | ||
| "rollup-plugin-filesize": "^9.1.2" | ||
| "typescript": "~4.7.4" | ||
| }, | ||
@@ -28,0 +30,0 @@ "author": "mauguin <2508192786@qq.com>", |
+4
-1
@@ -38,5 +38,8 @@ # pinia 数据持久化 | ||
| beforeRestore?: (context: PiniaPluginContext) => void; | ||
| afterRestore?: (context: PiniaPluginContext) => void | boolean; | ||
| afterRestore?: (context: PiniaPluginContext) => void ; | ||
| // 将当前的store恢复托管 到 center的store上 | ||
| slave?: string; | ||
| center?: boolean; | ||
| //在任何地方恢复数据后执行查询是否过期 过期会删除缓存支持异步返回 | ||
| onExpire:(store:StateTree):boolean; | ||
| } | ||
@@ -43,0 +46,0 @@ |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Unpopular package
QualityThis package is not very popular.
1
-50%8
-20%0
-100%0
-100%50
6.38%9158
-3.35%123
-11.51%1
Infinity%