@storix-js/vuex 0.2.1 → 0.3.0
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 +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +131 -144
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -44,3 +44,5 @@ const bridge = createVuexBridge({
|
|
|
44
44
|
This keeps simple integrations patch-based while allowing special keys to flow through Vuex business logic.
|
|
45
45
|
|
|
46
46
|
Use `applyVuexPatchMutation()` inside your Vuex mutation to apply the incoming patch payload.
|
|
47
|
+
|
|
48
|
+
For Vue 2 rendering, combine this bridge with `@storix-js/vue2`; the rendering adapter and Vuex bridge have separate lifecycles and should each be disposed at their ownership boundary.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@storix-js/core");var t=e=>typeof e==`object`&&!!e;function n(e){if(!t(e))return e;let n=new WeakSet,r=e=>{if(!t(e))return;let i=e;if(n.has(i))return;n.add(i);let a=Reflect.ownKeys(i);for(let e of a){let t=Reflect.get(i,e);r(t)}Object.freeze(i)};return r(e),e}function r(e,t){for(let[n,r]of Object.entries(t))e[n]=r}var i=e=>Object.keys(e).length>0,a=e=>e?Array.isArray(e)?e:[e]:[],o=e=>{let t=[e];if(e.includes(`.`)){let n=e.split(`.`,1)[0];n&&n!==e&&t.push(n)}return t},s=(e,n)=>{if(!n||!t(e))return e;try{Object.defineProperty(e,n,{value:!0,enumerable:!1,configurable:!0})}catch{return e}return e};function c(r){let c=r.mutationType??`storix/APPLY_PATCH`,l=r.immutable??!0,u=r.clone??e.isolateSnapshot,d=r.equals??e.deepEqual,f=r.projectVuexToStorix??(e=>e),p=r.projectStorixToVuex??(e=>e),m=r.suppressBridgeEcho??!1,h=r.bridgeOriginKey??`__storixBridge`,g=r.outboundDefault??{mode:`patch`,type:c},_=e=>{let t=u(e);return l?n(t):t},v=!1,y=!1,b=!1,x=new Map,S=e=>{if(m)for(let t of e){let e=x.get(t)??0;x.set(t,e+1)}},C=e=>{if(!m||!t(e))return!1;let n=Reflect.get(e,`payload`);if(h&&t(n)&&Reflect.get(n,h))return!0;let r=Reflect.get(e,`type`);if(typeof r!=`string`)return!1;let i=x.get(r)??0;return i<=0?!1:(i===1?x.delete(r):x.set(r,i-1),!0)},w=()=>{if(v||b)return;let t=_(f(r.vuex.state)),n=r.store.$snapshot(),a=(0,e.createPatchFromSnapshot)(n,t,d,_);if(i(a)){y=!0;try{r.store.$patch(a,r.externalMutationOrigin??`local`)}finally{y=!1}}},T=e=>{let t=o(e.storixMutation.key).flatMap(e=>a(r.outboundRoutes?.[e]));return t.push(...a(g)),t.find(t=>!t.when||t.when(e))},E=(e,t)=>{if(e.mode===`custom`){e.handler?.(t),S(e.suppressMutationTypes??[]);return}let n=t.projectedPatch,i=s(_(e.mapPayload?e.mapPayload(t):n),h);if(e.mode===`dispatch`){if(typeof r.vuex.dispatch!=`function`)throw Error(`Vuex bridge route mode "dispatch" requires vuex.dispatch to be available.`);if(!e.type)throw Error(`Vuex bridge dispatch route requires a "type".`);r.vuex.dispatch(e.type,i),S(e.suppressMutationTypes??[]);return}let a=e.type??c;r.vuex.commit(a,i),S(e.suppressMutationTypes??[a])},D=t=>{if(v||y)return;let n=r.store.$snapshot(),a=_(p(n)),o=_(f(r.vuex.state)),s=(0,e.createPatchFromSnapshot)(o,a,d,_);if(!i(s))return;let c={storixMutation:t??{namespace:r.store.$namespace,scopeId:r.store.$scopeId,storeId:r.store.$id,key:Object.keys(s)[0]??`*`,oldValue:void 0,newValue:void 0,origin:`local`},storixSnapshot:n,vuexState:r.vuex.state,projectedPatch:s,projectedVuexState:a,origin:`storix`},l=T(c);if(l){b=!0;try{E(l,c)}finally{b=!1}}},O=r.vuex.subscribe(e=>{C(e)||w()}),k=r.store.$subscribe(e=>{D(e)});return w(),{dispose(){v||(v=!0,O(),k())},syncFromExternal:w,syncFromStore(){D()}}}exports.applyVuexPatchMutation=r,exports.createVuexBridge=c,exports.deepFreeze=n;
|
package/dist/index.js
CHANGED
|
@@ -1,148 +1,135 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { createPatchFromSnapshot as e, deepEqual as t, isolateSnapshot as n } from "@storix-js/core";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
var r = (e) => typeof e == "object" && !!e;
|
|
4
|
+
function i(e) {
|
|
5
|
+
if (!r(e)) return e;
|
|
6
|
+
let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
|
|
7
|
+
if (!r(e)) return;
|
|
8
|
+
let i = e;
|
|
9
|
+
if (t.has(i)) return;
|
|
10
|
+
t.add(i);
|
|
11
|
+
let a = Reflect.ownKeys(i);
|
|
12
|
+
for (let e of a) {
|
|
13
|
+
let t = Reflect.get(i, e);
|
|
14
|
+
n(t);
|
|
15
|
+
}
|
|
16
|
+
Object.freeze(i);
|
|
17
|
+
};
|
|
18
|
+
return n(e), e;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
e[o] = i;
|
|
20
|
+
function a(e, t) {
|
|
21
|
+
for (let [n, r] of Object.entries(t)) e[n] = r;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
var o = (e) => Object.keys(e).length > 0, s = (e) => e ? Array.isArray(e) ? e : [e] : [], c = (e) => {
|
|
24
|
+
let t = [e];
|
|
25
|
+
if (e.includes(".")) {
|
|
26
|
+
let n = e.split(".", 1)[0];
|
|
27
|
+
n && n !== e && t.push(n);
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
}, l = (e, t) => {
|
|
31
|
+
if (!t || !r(e)) return e;
|
|
32
|
+
try {
|
|
33
|
+
Object.defineProperty(e, t, {
|
|
34
|
+
value: !0,
|
|
35
|
+
enumerable: !1,
|
|
36
|
+
configurable: !0
|
|
37
|
+
});
|
|
38
|
+
} catch {
|
|
39
|
+
return e;
|
|
40
|
+
}
|
|
41
|
+
return e;
|
|
42
42
|
};
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
return v(), {
|
|
135
|
-
dispose() {
|
|
136
|
-
x || (x = !0, $(), B());
|
|
137
|
-
},
|
|
138
|
-
syncFromExternal: v,
|
|
139
|
-
syncFromStore() {
|
|
140
|
-
M();
|
|
141
|
-
}
|
|
142
|
-
};
|
|
43
|
+
function u(a) {
|
|
44
|
+
let u = a.mutationType ?? "storix/APPLY_PATCH", d = a.immutable ?? !0, f = a.clone ?? n, p = a.equals ?? t, m = a.projectVuexToStorix ?? ((e) => e), h = a.projectStorixToVuex ?? ((e) => e), g = a.suppressBridgeEcho ?? !1, _ = a.bridgeOriginKey ?? "__storixBridge", v = a.outboundDefault ?? {
|
|
45
|
+
mode: "patch",
|
|
46
|
+
type: u
|
|
47
|
+
}, y = (e) => {
|
|
48
|
+
let t = f(e);
|
|
49
|
+
return d ? i(t) : t;
|
|
50
|
+
}, b = !1, x = !1, S = !1, C = /* @__PURE__ */ new Map(), w = (e) => {
|
|
51
|
+
if (g) for (let t of e) {
|
|
52
|
+
let e = C.get(t) ?? 0;
|
|
53
|
+
C.set(t, e + 1);
|
|
54
|
+
}
|
|
55
|
+
}, T = (e) => {
|
|
56
|
+
if (!g || !r(e)) return !1;
|
|
57
|
+
let t = Reflect.get(e, "payload");
|
|
58
|
+
if (_ && r(t) && Reflect.get(t, _)) return !0;
|
|
59
|
+
let n = Reflect.get(e, "type");
|
|
60
|
+
if (typeof n != "string") return !1;
|
|
61
|
+
let i = C.get(n) ?? 0;
|
|
62
|
+
return i <= 0 ? !1 : (i === 1 ? C.delete(n) : C.set(n, i - 1), !0);
|
|
63
|
+
}, E = () => {
|
|
64
|
+
if (b || S) return;
|
|
65
|
+
let t = y(m(a.vuex.state)), n = a.store.$snapshot(), r = e(n, t, p, y);
|
|
66
|
+
if (o(r)) {
|
|
67
|
+
x = !0;
|
|
68
|
+
try {
|
|
69
|
+
a.store.$patch(r, a.externalMutationOrigin ?? "local");
|
|
70
|
+
} finally {
|
|
71
|
+
x = !1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, D = (e) => {
|
|
75
|
+
let t = c(e.storixMutation.key).flatMap((e) => s(a.outboundRoutes?.[e]));
|
|
76
|
+
return t.push(...s(v)), t.find((t) => !t.when || t.when(e));
|
|
77
|
+
}, O = (e, t) => {
|
|
78
|
+
if (e.mode === "custom") {
|
|
79
|
+
e.handler?.(t), w(e.suppressMutationTypes ?? []);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let n = t.projectedPatch, r = l(y(e.mapPayload ? e.mapPayload(t) : n), _);
|
|
83
|
+
if (e.mode === "dispatch") {
|
|
84
|
+
if (typeof a.vuex.dispatch != "function") throw Error("Vuex bridge route mode \"dispatch\" requires vuex.dispatch to be available.");
|
|
85
|
+
if (!e.type) throw Error("Vuex bridge dispatch route requires a \"type\".");
|
|
86
|
+
a.vuex.dispatch(e.type, r), w(e.suppressMutationTypes ?? []);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let i = e.type ?? u;
|
|
90
|
+
a.vuex.commit(i, r), w(e.suppressMutationTypes ?? [i]);
|
|
91
|
+
}, k = (t) => {
|
|
92
|
+
if (b || x) return;
|
|
93
|
+
let n = a.store.$snapshot(), r = y(h(n)), i = y(m(a.vuex.state)), s = e(i, r, p, y);
|
|
94
|
+
if (!o(s)) return;
|
|
95
|
+
let c = {
|
|
96
|
+
storixMutation: t ?? {
|
|
97
|
+
namespace: a.store.$namespace,
|
|
98
|
+
scopeId: a.store.$scopeId,
|
|
99
|
+
storeId: a.store.$id,
|
|
100
|
+
key: Object.keys(s)[0] ?? "*",
|
|
101
|
+
oldValue: void 0,
|
|
102
|
+
newValue: void 0,
|
|
103
|
+
origin: "local"
|
|
104
|
+
},
|
|
105
|
+
storixSnapshot: n,
|
|
106
|
+
vuexState: a.vuex.state,
|
|
107
|
+
projectedPatch: s,
|
|
108
|
+
projectedVuexState: r,
|
|
109
|
+
origin: "storix"
|
|
110
|
+
}, l = D(c);
|
|
111
|
+
if (l) {
|
|
112
|
+
S = !0;
|
|
113
|
+
try {
|
|
114
|
+
O(l, c);
|
|
115
|
+
} finally {
|
|
116
|
+
S = !1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}, A = a.vuex.subscribe((e) => {
|
|
120
|
+
T(e) || E();
|
|
121
|
+
}), j = a.store.$subscribe((e) => {
|
|
122
|
+
k(e);
|
|
123
|
+
});
|
|
124
|
+
return E(), {
|
|
125
|
+
dispose() {
|
|
126
|
+
b || (b = !0, A(), j());
|
|
127
|
+
},
|
|
128
|
+
syncFromExternal: E,
|
|
129
|
+
syncFromStore() {
|
|
130
|
+
k();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
143
133
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
K as createVuexBridge,
|
|
147
|
-
z as deepFreeze
|
|
148
|
-
};
|
|
134
|
+
//#endregion
|
|
135
|
+
export { a as applyVuexPatchMutation, u as createVuexBridge, i as deepFreeze };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storix-js/vuex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"require": "./dist/index.cjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@storix-js/core": "0.3.0"
|
|
24
|
+
},
|
|
22
25
|
"scripts": {
|
|
23
26
|
"build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
24
27
|
"dev": "vite build --watch",
|
|
25
28
|
"test": "vitest run --passWithNoTests",
|
|
26
29
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
27
|
-
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@storix-js/core": "workspace:*"
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|