@coaction/pinia 0.1.0 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @coaction/pinia
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
[](https://www.npmjs.com/package/@coaction/pinia)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A Coaction integration tool for Pinia
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
You can install it via npm, yarn or pnpm.
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install coaction @coaction/pinia
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { create } from 'coaction';
|
|
21
|
+
import { bindPinia } from '@coaction/pinia';
|
|
22
|
+
import { defineStore } from 'pinia';
|
|
23
|
+
|
|
24
|
+
const useStore = create(() =>
|
|
25
|
+
defineStore(
|
|
26
|
+
'test',
|
|
27
|
+
bindPinia({
|
|
28
|
+
state: () => ({ count: 0 }),
|
|
29
|
+
getters: {
|
|
30
|
+
double: (state) => state.count * 2
|
|
31
|
+
},
|
|
32
|
+
actions: {
|
|
33
|
+
increment(state) {
|
|
34
|
+
state.count += 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
You can find the documentation [here](https://github.com/unadlib/coaction).
|
|
@@ -7,9 +7,9 @@ var coaction = require('coaction');
|
|
|
7
7
|
var pinia = require('pinia');
|
|
8
8
|
|
|
9
9
|
const instancesMap = new WeakMap();
|
|
10
|
-
const handleStore = (store, state) => {
|
|
11
|
-
if (!
|
|
12
|
-
|
|
10
|
+
const handleStore = (store, state, _, internal) => {
|
|
11
|
+
if (!internal.toMutableRaw) {
|
|
12
|
+
internal.toMutableRaw = key => instancesMap.get(key);
|
|
13
13
|
Object.assign(store, {
|
|
14
14
|
subscribe: callback => {
|
|
15
15
|
store._subscriptions.add(callback);
|
|
@@ -47,7 +47,7 @@ const handleStore = (store, state) => {
|
|
|
47
47
|
mutability.apply(state, patches);
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
const stopWatch =
|
|
50
|
+
const stopWatch = internal.toMutableRaw(state).$subscribe((...args) => {
|
|
51
51
|
store._subscriptions.forEach(callback => callback(...args));
|
|
52
52
|
});
|
|
53
53
|
const destroy = () => {
|
|
@@ -4,9 +4,9 @@ import { createPinia, setActivePinia } from 'pinia';
|
|
|
4
4
|
export * from 'pinia';
|
|
5
5
|
|
|
6
6
|
const instancesMap = new WeakMap();
|
|
7
|
-
const handleStore = (store, state) => {
|
|
8
|
-
if (!
|
|
9
|
-
|
|
7
|
+
const handleStore = (store, state, _, internal) => {
|
|
8
|
+
if (!internal.toMutableRaw) {
|
|
9
|
+
internal.toMutableRaw = key => instancesMap.get(key);
|
|
10
10
|
Object.assign(store, {
|
|
11
11
|
subscribe: callback => {
|
|
12
12
|
store._subscriptions.add(callback);
|
|
@@ -44,7 +44,7 @@ const handleStore = (store, state) => {
|
|
|
44
44
|
apply(state, patches);
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
const stopWatch =
|
|
47
|
+
const stopWatch = internal.toMutableRaw(state).$subscribe((...args) => {
|
|
48
48
|
store._subscriptions.forEach(callback => callback(...args));
|
|
49
49
|
});
|
|
50
50
|
const destroy = () => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mutative"),require("coaction"),require("pinia")):"function"==typeof define&&define.amd?define(["exports","mutative","coaction","pinia"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoactionPinia={},e.Mutative,e.Coaction,e.Pinia)}(this,(function(e,t,r,n){"use strict";const o="replace";function
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mutative"),require("coaction"),require("pinia")):"function"==typeof define&&define.amd?define(["exports","mutative","coaction","pinia"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoactionPinia={},e.Mutative,e.Coaction,e.Pinia)}(this,(function(e,t,r,n){"use strict";const o="replace";function a(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function s(e,t){return 2===a(e)?e.get(t):e[t]}function i(e){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(i);if(e instanceof Map)return new Map(Array.from(e.entries()).map((([e,t])=>[e,i(t)])));if(e instanceof Set)return new Set(Array.from(e).map(i));const t=Object.create(Object.getPrototypeOf(e));for(const r in e)t[r]=i(e[r]);return t}const c=new WeakMap,u=r.createBinder({handleStore:(e,t,r,n)=>{if(!n.toMutableRaw){n.toMutableRaw=e=>c.get(e),Object.assign(e,{subscribe:t=>(e._subscriptions.add(t),()=>e._subscriptions.delete(t))}),e._subscriptions=new Set,e._destroyers=new Set;const t=e.destroy;e.destroy=()=>{t(),e._subscriptions.clear(),e._subscriptions=void 0,e._destroyers.forEach((e=>e())),e._destroyers=void 0},e.apply=(t=e.getState(),r)=>{if(r)!function(e,t){let r;for(r=t.length-1;r>=0;r-=1){const{value:n,op:a,path:s}=t[r];if(!s.length&&a===o||""===s&&"add"===a){e=n;break}}r>-1&&(t=t.slice(r+1)),t.forEach((t=>{const{path:r,op:n}=t,c=function(e){return Array.isArray(e)?e:e.split("/").map((e=>e.replace(/~1/g,"/").replace(/~0/g,"~"))).slice(1)}(r);let u=e;for(let e=0;e<c.length-1;e+=1){const t=a(u);let r=c[e];if("string"!=typeof r&&"number"!=typeof r&&(r=String(r)),(0===t||1===t)&&("__proto__"===r||"constructor"===r)||"function"==typeof u&&"prototype"===r)throw new Error("Patching reserved attributes like __proto__ and constructor is not allowed.");if(u=s(3===a(u)?Array.from(u):u,r),"object"!=typeof u)throw new Error(`Cannot apply patch at '${c.join("/")}'.`)}const f=a(u),p=i(t.value),l=c[c.length-1];switch(n){case o:switch(f){case 2:return u.set(l,p);case 3:throw new Error("Cannot apply replace patch to set.");default:return u[l]=p}case"add":switch(f){case 1:return"-"===l?u.push(p):u.splice(l,0,p);case 2:return u.set(l,p);case 3:return u.add(p);default:return u[l]=p}case"remove":switch(f){case 1:return u.splice(l,1);case 2:return u.delete(l);case 3:return u.delete(t.value);default:return delete u[l]}default:throw new Error(`Unsupported patch operation: ${n}.`)}}))}(t,r);else{if(t===e.getState())return;if(e.isSliceStore){if("object"==typeof t&&null!==t)for(const r in t){const n=r,o=t[n];"object"==typeof o&&null!==o&&Object.assign(e.getState()[n],o)}}else Object.assign(e.getState(),t)}}}const u=n.toMutableRaw(t).$subscribe(((...t)=>{e._subscriptions.forEach((e=>e(...t)))}));e._destroyers.add((()=>{c.delete(t),u()}))},handleState:e=>{const t={};e.getters=e.getters??{};for(const r in e.getters)t[r]={get(){return e.getters[r].call(this,this)}};const r=Object.defineProperties({...e.state?.(),...e.actions},t),o=n.createPinia();return n.setActivePinia(o),{copyState:e,key:"actions",bind:e=>(r.name=e.$id,c.set(r,e),r)}}});e.adapt=e=>e,e.bindPinia=u,Object.keys(n).forEach((function(t){"default"===t||e.hasOwnProperty(t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=coaction-pinia.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coaction-pinia.umd.min.js","sources":["../../../node_modules/mutability/dist/index.esm.js","../src/index.ts"],"sourcesContent":["import{create as e}from\"mutative\";const t=\"remove\",r=\"replace\",n=\"add\";function o(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function a(e,t){return 2===o(e)?e.get(t):e[t]}function c(e){if(\"object\"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(c);if(e instanceof Map)return new Map(Array.from(e.entries()).map((([e,t])=>[e,c(t)])));if(e instanceof Set)return new Set(Array.from(e).map(c));const t=Object.create(Object.getPrototypeOf(e));for(const r in e)t[r]=c(e[r]);return t}function s(e,s){let i;for(i=s.length-1;i>=0;i-=1){const{value:t,op:o,path:a}=s[i];if(!a.length&&o===r||\"\"===a&&o===n){e=t;break}}i>-1&&(s=s.slice(i+1)),s.forEach((s=>{const{path:i,op:p}=s,u=function(e){return Array.isArray(e)?e:e.split(\"/\").map((e=>e.replace(/~1/g,\"/\").replace(/~0/g,\"~\"))).slice(1)}(i);let f=e;for(let e=0;e<u.length-1;e+=1){const t=o(f);let r=u[e];if(\"string\"!=typeof r&&\"number\"!=typeof r&&(r=String(r)),(0===t||1===t)&&(\"__proto__\"===r||\"constructor\"===r)||\"function\"==typeof f&&\"prototype\"===r)throw new Error(\"Patching reserved attributes like __proto__ and constructor is not allowed.\");if(f=a(3===o(f)?Array.from(f):f,r),\"object\"!=typeof f)throw new Error(`Cannot apply patch at '${u.join(\"/\")}'.`)}const l=o(f),h=c(s.value),y=u[u.length-1];switch(p){case r:switch(l){case 2:return f.set(y,h);case 3:throw new Error(\"Cannot apply replace patch to set.\");default:return f[y]=h}case n:switch(l){case 1:return\"-\"===y?f.push(h):f.splice(y,0,h);case 2:return f.set(y,h);case 3:return f.add(h);default:return f[y]=h}case t:switch(l){case 1:return f.splice(y,1);case 2:return f.delete(y);case 3:return f.delete(s.value);default:return delete f[y]}default:throw new Error(`Unsupported patch operation: ${p}.`)}}))}const i=(t,r)=>{const[,n,o]=e(t,r,{enablePatches:!0});return s(t,n),{inversePatches:o,patches:n}};export{s as apply,i as mutate};\n//# sourceMappingURL=index.esm.js.map\n","import { apply } from 'mutability';\nimport { createBinder, type Store } from 'coaction';\nimport { createPinia, setActivePinia } from 'pinia';\nimport type {\n _GettersTree,\n DefineStoreOptions,\n StateTree,\n StoreDefinition\n} from 'pinia';\n\nexport * from 'pinia';\n\nconst instancesMap = new WeakMap<object, unknown>();\n\ntype StoreWithSubscriptions = Store<object> & {\n // TODO: fix type\n _subscriptions?: Set<(...args: any) => void>;\n _destroyers?: Set<() => void>;\n};\n\ntype FunctionKeys<T> = {\n [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n}[keyof T];\n\ntype Equal<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2\n ? true\n : false;\n\ntype ReadonlyKeys<T> = {\n [K in keyof T]: Equal<\n { [P in K]: T[P] },\n Readonly<{ [P in K]: T[P] }>\n > extends true\n ? K\n : never;\n}[keyof T];\n\nexport type IStore<T extends object> = [\n string,\n Pick<T, Exclude<keyof T, ReadonlyKeys<T> | FunctionKeys<T>>>,\n {\n [K in ReadonlyKeys<T>]: (\n state: Pick<T, Exclude<keyof T, ReadonlyKeys<T> | FunctionKeys<T>>>\n ) => T[K];\n },\n Pick<T, FunctionKeys<T>>\n];\n\nconst handleStore = (store: StoreWithSubscriptions, state: object) => {\n if (!store.toRaw) {\n store.toRaw = (key: any) => instancesMap.get(key);\n Object.assign(store, {\n subscribe: (callback: any) => {\n store._subscriptions!.add(callback);\n return () => store._subscriptions!.delete(callback);\n }\n });\n store._subscriptions = new Set<() => void>();\n store._destroyers = new Set<() => void>();\n const baseDestroy = store.destroy;\n store.destroy = () => {\n baseDestroy();\n store._subscriptions!.clear();\n store._subscriptions = undefined;\n store._destroyers!.forEach((destroy) => destroy());\n store._destroyers = undefined;\n };\n store.apply = (state = store.getState(), patches) => {\n if (!patches) {\n if (state === store.getState()) return;\n if (store.isSliceStore) {\n if (typeof state === 'object' && state !== null) {\n for (const key in state) {\n const _key = key as keyof typeof state;\n const _state = state[_key];\n if (typeof _state === 'object' && _state !== null) {\n Object.assign(store.getState()[_key], _state);\n }\n }\n }\n } else {\n Object.assign(store.getState(), state);\n }\n return;\n }\n apply(state, patches);\n };\n }\n const stopWatch = store.toRaw(state).$subscribe((...args: unknown[]) => {\n store._subscriptions!.forEach((callback) => callback(...args));\n });\n const destroy = () => {\n instancesMap.delete(state);\n stopWatch();\n };\n store._destroyers!.add(destroy);\n};\n\n/**\n * Bind a store to Pinia\n */\nexport const bindPinia = createBinder({\n handleStore,\n handleState: ((options: DefineStoreOptions<any, any, any, any>) => {\n const descriptors: Record<string, PropertyDescriptor> = {};\n options.getters = options.getters ?? {};\n for (const key in options.getters) {\n descriptors[key] = {\n get() {\n return options.getters[key].call(this, this);\n }\n };\n }\n const rawState = Object.defineProperties(\n {\n ...options.state?.(),\n ...options.actions\n },\n descriptors\n );\n const pinia = createPinia();\n setActivePinia(pinia);\n return {\n copyState: options as any,\n key: 'actions',\n bind: (state: any) => {\n rawState.name = state.$id;\n instancesMap.set(rawState, state);\n return rawState;\n }\n };\n }) as any\n}) as <\n Id extends string,\n S extends StateTree = {},\n G extends _GettersTree<S> = {},\n A = {}\n>(\n options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>\n) => Omit<DefineStoreOptions<Id, S, G, A>, 'id'>;\n\n/**\n * Adapt a store type to Pinia\n */\nexport const adapt = <T extends object>(\n store: StoreDefinition<IStore<T>[0], IStore<T>[1], IStore<T>[2], IStore<T>[3]>\n) => store as any as T;\n\nexport type PiniaStore<T extends object> = StoreDefinition<\n IStore<T>[0],\n IStore<T>[1],\n IStore<T>[2],\n IStore<T>[3]\n>;\n"],"names":["r","o","e","Array","isArray","Map","Set","a","t","get","c","map","from","entries","Object","create","getPrototypeOf","instancesMap","WeakMap","bindPinia","createBinder","handleStore","store","state","toRaw","key","assign","subscribe","callback","_subscriptions","add","delete","_destroyers","baseDestroy","destroy","clear","undefined","forEach","apply","getState","patches","s","i","length","value","op","path","slice","p","u","split","replace","f","String","Error","join","l","h","y","set","push","splice","isSliceStore","_key","_state","stopWatch","$subscribe","args","handleState","options","descriptors","getters","call","this","rawState","defineProperties","actions","pinia","createPinia","setActivePinia","copyState","bind","name","$id"],"mappings":"gXAAkC,MAAiBA,EAAE,UAAkB,SAASC,EAAEC,GAAG,OAAOC,MAAMC,QAA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,KACzC,GAGJ,MAAMC,EAAW5D,OAAO6D,iBACtB,IACKN,EAAQ9C,aACR8C,EAAQO,SAEbN,GAEIO,EAAQC,EAAAA,cAEd,OADAC,EAAcA,eAACF,GACR,CACLG,UAAWX,EACX5C,IAAK,UACLwD,KAAO1D,IACLmD,EAASQ,KAAO3D,EAAM4D,IACtBlE,EAAa0C,IAAIe,EAAUnD,GACpBmD,GAEV,YAeHpD,GACGA"}
|
|
1
|
+
{"version":3,"file":"coaction-pinia.umd.min.js","sources":["../../../node_modules/mutability/dist/index.esm.js","../src/index.ts"],"sourcesContent":["import{create as e}from\"mutative\";const t=\"remove\",r=\"replace\",n=\"add\";function o(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function a(e,t){return 2===o(e)?e.get(t):e[t]}function c(e){if(\"object\"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(c);if(e instanceof Map)return new Map(Array.from(e.entries()).map((([e,t])=>[e,c(t)])));if(e instanceof Set)return new Set(Array.from(e).map(c));const t=Object.create(Object.getPrototypeOf(e));for(const r in e)t[r]=c(e[r]);return t}function s(e,s){let i;for(i=s.length-1;i>=0;i-=1){const{value:t,op:o,path:a}=s[i];if(!a.length&&o===r||\"\"===a&&o===n){e=t;break}}i>-1&&(s=s.slice(i+1)),s.forEach((s=>{const{path:i,op:p}=s,u=function(e){return Array.isArray(e)?e:e.split(\"/\").map((e=>e.replace(/~1/g,\"/\").replace(/~0/g,\"~\"))).slice(1)}(i);let f=e;for(let e=0;e<u.length-1;e+=1){const t=o(f);let r=u[e];if(\"string\"!=typeof r&&\"number\"!=typeof r&&(r=String(r)),(0===t||1===t)&&(\"__proto__\"===r||\"constructor\"===r)||\"function\"==typeof f&&\"prototype\"===r)throw new Error(\"Patching reserved attributes like __proto__ and constructor is not allowed.\");if(f=a(3===o(f)?Array.from(f):f,r),\"object\"!=typeof f)throw new Error(`Cannot apply patch at '${u.join(\"/\")}'.`)}const l=o(f),h=c(s.value),y=u[u.length-1];switch(p){case r:switch(l){case 2:return f.set(y,h);case 3:throw new Error(\"Cannot apply replace patch to set.\");default:return f[y]=h}case n:switch(l){case 1:return\"-\"===y?f.push(h):f.splice(y,0,h);case 2:return f.set(y,h);case 3:return f.add(h);default:return f[y]=h}case t:switch(l){case 1:return f.splice(y,1);case 2:return f.delete(y);case 3:return f.delete(s.value);default:return delete f[y]}default:throw new Error(`Unsupported patch operation: ${p}.`)}}))}const i=(t,r)=>{const[,n,o]=e(t,r,{enablePatches:!0});return s(t,n),{inversePatches:o,patches:n}};export{s as apply,i as mutate};\n//# sourceMappingURL=index.esm.js.map\n","import { apply } from 'mutability';\nimport { createBinder, type Store } from 'coaction';\nimport { createPinia, setActivePinia } from 'pinia';\nimport type {\n _GettersTree,\n DefineStoreOptions,\n StateTree,\n StoreDefinition\n} from 'pinia';\n\nexport * from 'pinia';\n\nconst instancesMap = new WeakMap<object, unknown>();\n\ntype StoreWithSubscriptions = Store<object> & {\n // TODO: fix type\n _subscriptions?: Set<(...args: any) => void>;\n _destroyers?: Set<() => void>;\n};\n\ntype FunctionKeys<T> = {\n [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n}[keyof T];\n\ntype Equal<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2\n ? true\n : false;\n\ntype ReadonlyKeys<T> = {\n [K in keyof T]: Equal<\n { [P in K]: T[P] },\n Readonly<{ [P in K]: T[P] }>\n > extends true\n ? K\n : never;\n}[keyof T];\n\nexport type IStore<T extends object> = [\n string,\n Pick<T, Exclude<keyof T, ReadonlyKeys<T> | FunctionKeys<T>>>,\n {\n [K in ReadonlyKeys<T>]: (\n state: Pick<T, Exclude<keyof T, ReadonlyKeys<T> | FunctionKeys<T>>>\n ) => T[K];\n },\n Pick<T, FunctionKeys<T>>\n];\n\nconst handleStore = (\n store: StoreWithSubscriptions,\n state: object,\n _: object,\n internal: any\n) => {\n if (!internal.toMutableRaw) {\n internal.toMutableRaw = (key: any) => instancesMap.get(key);\n Object.assign(store, {\n subscribe: (callback: any) => {\n store._subscriptions!.add(callback);\n return () => store._subscriptions!.delete(callback);\n }\n });\n store._subscriptions = new Set<() => void>();\n store._destroyers = new Set<() => void>();\n const baseDestroy = store.destroy;\n store.destroy = () => {\n baseDestroy();\n store._subscriptions!.clear();\n store._subscriptions = undefined;\n store._destroyers!.forEach((destroy) => destroy());\n store._destroyers = undefined;\n };\n store.apply = (state = store.getState(), patches) => {\n if (!patches) {\n if (state === store.getState()) return;\n if (store.isSliceStore) {\n if (typeof state === 'object' && state !== null) {\n for (const key in state) {\n const _key = key as keyof typeof state;\n const _state = state[_key];\n if (typeof _state === 'object' && _state !== null) {\n Object.assign(store.getState()[_key], _state);\n }\n }\n }\n } else {\n Object.assign(store.getState(), state);\n }\n return;\n }\n apply(state, patches);\n };\n }\n const stopWatch = internal\n .toMutableRaw(state)\n .$subscribe((...args: unknown[]) => {\n store._subscriptions!.forEach((callback) => callback(...args));\n });\n const destroy = () => {\n instancesMap.delete(state);\n stopWatch();\n };\n store._destroyers!.add(destroy);\n};\n\n/**\n * Bind a store to Pinia\n */\nexport const bindPinia = createBinder({\n handleStore,\n handleState: ((options: DefineStoreOptions<any, any, any, any>) => {\n const descriptors: Record<string, PropertyDescriptor> = {};\n options.getters = options.getters ?? {};\n for (const key in options.getters) {\n descriptors[key] = {\n get() {\n return options.getters[key].call(this, this);\n }\n };\n }\n const rawState = Object.defineProperties(\n {\n ...options.state?.(),\n ...options.actions\n },\n descriptors\n );\n const pinia = createPinia();\n setActivePinia(pinia);\n return {\n copyState: options as any,\n key: 'actions',\n bind: (state: any) => {\n rawState.name = state.$id;\n instancesMap.set(rawState, state);\n return rawState;\n }\n };\n }) as any\n}) as <\n Id extends string,\n S extends StateTree = {},\n G extends _GettersTree<S> = {},\n A = {}\n>(\n options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>\n) => Omit<DefineStoreOptions<Id, S, G, A>, 'id'>;\n\n/**\n * Adapt a store type to Pinia\n */\nexport const adapt = <T extends object>(\n store: StoreDefinition<IStore<T>[0], IStore<T>[1], IStore<T>[2], IStore<T>[3]>\n) => store as any as T;\n\nexport type PiniaStore<T extends object> = StoreDefinition<\n IStore<T>[0],\n IStore<T>[1],\n IStore<T>[2],\n IStore<T>[3]\n>;\n"],"names":["r","o","e","Array","isArray","Map","Set","a","t","get","c","map","from","entries","Object","create","getPrototypeOf","instancesMap","WeakMap","bindPinia","createBinder","handleStore","store","state","_","internal","toMutableRaw","key","assign","subscribe","callback","_subscriptions","add","delete","_destroyers","baseDestroy","destroy","clear","undefined","forEach","apply","getState","patches","s","i","length","value","op","path","slice","p","u","split","replace","f","String","Error","join","l","h","y","set","push","splice","isSliceStore","_key","_state","stopWatch","$subscribe","args","handleState","options","descriptors","getters","call","this","rawState","defineProperties","actions","pinia","createPinia","setActivePinia","copyState","bind","name","$id"],"mappings":"gXAAkC,MAAiBA,EAAE,UAAkB,SAASC,EAAEC,GAAG,OAAOC,MAAMC,QAAQF,GAAG,EAAEA,aAAaG,IAAI,EAAEH,aAAaI,IAAI,EAAE,CAAC,CAAC,SAASC,EAAEL,EAAEM,GAAG,OAAO,IAAIP,EAAEC,GAAGA,EAAEO,IAAID,GAAGN,EAAEM,EAAE,CAAC,SAASE,EAAER,GAAG,GAAG,iBAAiBA,GAAG,OAAOA,EAAE,OAAOA,EAAE,GAAGC,MAAMC,QAAQF,GAAG,OAAOA,EAAES,IAAID,GAAG,GAAGR,aAAaG,IAAI,OAAO,IAAIA,IAAIF,MAAMS,KAAKV,EAAEW,WAAWF,OAAOT,EAAEM,KAAK,CAACN,EAAEQ,EAAEF,OAAO,GAAGN,aAAaI,IAAI,OAAO,IAAIA,IAAIH,MAAMS,KAAKV,GAAGS,IAAID,IAAI,MAAMF,EAAEM,OAAOC,OAAOD,OAAOE,eAAed,IAAI,IAAI,MAAMF,KAAKE,EAAEM,EAAER,GAAGU,EAAER,EAAEF,IAAI,OAAOQ,CAAC,CCYpgB,MAAMS,EA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AAgC,OAAVA,EAC/B,IAAK,MAAMI,KAAOJ,EAAO,CACvB,MAAM0C,EAAOtC,EACPuC,EAAS3C,EAAM0C,GACC,iBAAXC,GAAkC,OAAXA,GAChCpD,OAAOc,OAAON,EAAMmB,WAAWwB,GAAOC,EAE1C,OAGFpD,OAAOc,OAAON,EAAMmB,WAAYlB,EAGpC,CACqB,CAEzB,CACA,MAAM4C,EAAY1C,EACfC,aAAaH,GACb6C,YAAW,IAAIC,KACd/C,EAAMS,eAAgBQ,SAAST,GAAaA,KAAYuC,IAAM,IAMlE/C,EAAMY,YAAaF,KAJHI,KACdnB,EAAagB,OAAOV,GACpB4C,GAAW,GAEkB,EAQ/BG,YAAeC,IACb,MAAMC,EAAkD,CAAA,EACxDD,EAAQE,QAAUF,EAAQE,SAAW,CAAA,EACrC,IAAK,MAAM9C,KAAO4C,EAAQE,QACxBD,EAAY7C,GAAO,CACjBlB,GAAAA,GACE,OAAO8D,EAAQE,QAAQ9C,GAAK+C,KAAKC,KAAMA,KACzC,GAGJ,MAAMC,EAAW9D,OAAO+D,iBACtB,IACKN,EAAQhD,aACRgD,EAAQO,SAEbN,GAEIO,EAAQC,EAAAA,cAEd,OADAC,EAAcA,eAACF,GACR,CACLG,UAAWX,EACX5C,IAAK,UACLwD,KAAO5D,IACLqD,EAASQ,KAAO7D,EAAM8D,IACtBpE,EAAa4C,IAAIe,EAAUrD,GACpBqD,GAEV,YAeHtD,GACGA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coaction/pinia",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Coaction
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "A Coaction integration tool for Pinia",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
7
7
|
"coaction",
|
|
@@ -47,17 +47,23 @@
|
|
|
47
47
|
]
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"coaction": "^0.1.
|
|
50
|
+
"coaction": "^0.1.5",
|
|
51
51
|
"mutative": "^1.1.0",
|
|
52
52
|
"pinia": "^2.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"coaction": {
|
|
56
56
|
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"mutative": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"pinia": {
|
|
62
|
+
"optional": true
|
|
57
63
|
}
|
|
58
64
|
},
|
|
59
65
|
"devDependencies": {
|
|
60
|
-
"coaction": "
|
|
66
|
+
"coaction": "^0.1.5",
|
|
61
67
|
"mutative": "^1.1.0",
|
|
62
68
|
"pinia": "^2.2.4"
|
|
63
69
|
},
|