@kaokei/use-vue-service 4.0.2 → 4.0.4
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 +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -31
- package/package.json +4 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@kaokei/di"),o=require("vue"),y=new c.Token("FIND_CHILD_SERVICE"),P=new c.Token("FIND_CHILDREN_SERVICES"),C=Symbol("SCOPE_KEY"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@kaokei/di"),o=require("vue"),y=new c.Token("FIND_CHILD_SERVICE"),P=new c.Token("FIND_CHILDREN_SERVICES"),C=Symbol("SCOPE_KEY"),N="__raw__",u=Symbol("CONTAINER_TOKEN");function k(n){const e=n,t=o.effectScope(!0);return e[C]=t,t}function b(n){return n[C]}function V(n){const e=n;if(e){const t=b(e);t&&(t.stop(),delete e[C])}}function D(n){const e=b(n);return e||k(n)}function S(n,e,t,r){if(n){for(const i of n)if(i.isCurrentBound(e)&&(t.push(i.get(e)),r)||S(i.getChildren(),e,t,r))return!0}return!1}function F(n,e){const t=[];return S(e.getChildren(),n,t,!0),t[0]}function H(n,e){const t=[];return S(e.getChildren(),n,t,!1),t}function L(n,e,t){return c.isObject(e)?c.getOwnMetadata(N,t)?o.markRaw(e):o.reactive(e):e}function K(n){return V(n)}function W({container:n}){return e=>F(e,n)}function Y({container:n}){return e=>H(e,n)}function h(n){let e;return n?e=n.createChild():e=new c.Container,e.bind(y).toDynamicValue(W),e.bind(P).toDynamicValue(Y),e.onActivation(L),e.onDeactivation(K),e}const l=h();function s(n,e){if(typeof e=="function")e(n);else for(let t=0;t<e.length;t++)n.bind(e[t]).toSelf()}function A(){const n=o.getCurrentInstance();if(n){const e=u,t=n.provides,r=n.parent&&n.parent.provides;if(t&&t!==r&&c.hasOwn(t,e))return t[e]}}function j(n){if(!o.hasInjectionContext())throw new Error(`${n} must inside setup.`)}function g(){return o.inject(u,l)}function q(n){return j("useService"),(A()||g()).get(n)}function M(n){j("declareProviders");const e=A();if(e)s(e,n);else{const t=g(),r=h(t);s(r,n),o.provide(u,r),o.onUnmounted(()=>{r.destroy()})}}function U(n){return l.get(n)}function z(n){s(l,n)}function B(n,e){return e.runWithContext(()=>g().get(n))}function T(n,e){e.runWithContext(()=>{const t=o.inject(u,null);if(t)s(t,n);else{const r=h(l);s(r,n),e.provide(u,r),e.onUnmount(()=>{r.destroy()})}})}function G(n){return e=>T(n,e)}function _(n,e){const t=e.name;return function(){const r=this,i=o.toRaw(this),E=D(i),R=n;let p,f=Object.getPrototypeOf(i);for(;f;){const a=Object.getOwnPropertyDescriptor(f,t);if(a&&a.set){p=a.set;break}f=Object.getPrototypeOf(f)}const I=p?E.run(()=>o.computed({get:()=>R.call(r),set:a=>p.call(r,a)})):E.run(()=>o.computed(()=>R.call(r)));return Object.defineProperty(i,t,{value:I,writable:!0,configurable:!0,enumerable:!0}),I}}function $(n,e){return typeof n=="function"&&(e==null?void 0:e.kind)==="getter"?_(n,e):_}function d(n){return c.isObject(n)?o.markRaw(n):n}function O(n,e){const t=e.name;return e.addInitializer(function(){let r=this[t];Object.defineProperty(this,t,{configurable:!0,enumerable:!0,get(){return r},set(i){r=d(i)}})}),d}function m(n,e){return{get(){return n.get.call(o.toRaw(this))},set(t){n.set.call(o.toRaw(this),d(t))},init:d}}function v(n,e){e.metadata&&(e.metadata[N]=!0)}function J(n,e){return(e==null?void 0:e.kind)==="field"?O(n,e):(e==null?void 0:e.kind)==="accessor"?m(n):(e==null?void 0:e.kind)==="class"?v(n,e):(t,r)=>(r==null?void 0:r.kind)==="field"?O(t,r):(r==null?void 0:r.kind)==="accessor"?m(t):v(t,r)}function w(n,e){return function(...t){const i=D(this).run(()=>o.effectScope());return i.run(()=>n.call(this,...t)),i}}function Q(n,e){return typeof n=="function"&&(e==null?void 0:e.kind)==="method"?w(n):w}exports.CONTAINER_TOKEN=u;exports.Computed=$;exports.FIND_CHILDREN_SERVICES=P;exports.FIND_CHILD_SERVICE=y;exports.Raw=J;exports.RunInScope=Q;exports.declareAppProviders=T;exports.declareAppProvidersPlugin=G;exports.declareProviders=M;exports.declareRootProviders=z;exports.useAppService=B;exports.useRootService=U;exports.useService=q;Object.keys(c).forEach(n=>{n!=="default"&&!Object.prototype.hasOwnProperty.call(exports,n)&&Object.defineProperty(exports,n,{enumerable:!0,get:()=>c[n]})});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@kaokei/di';
|
|
2
2
|
export { useService, declareProviders, useRootService, declareRootProviders, useAppService, declareAppProviders, declareAppProvidersPlugin, } from './core.ts';
|
|
3
|
-
export { FIND_CHILD_SERVICE, FIND_CHILDREN_SERVICES } from './constants.ts';
|
|
3
|
+
export { FIND_CHILD_SERVICE, FIND_CHILDREN_SERVICES, CONTAINER_TOKEN } from './constants.ts';
|
|
4
4
|
export type { FindChildService, FindChildrenServices } from './interface.ts';
|
|
5
5
|
export { Computed } from './computed.ts';
|
|
6
6
|
export { Raw } from './raw.ts';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@kaokei/di';
|
|
2
2
|
export { useService, declareProviders, useRootService, declareRootProviders, useAppService, declareAppProviders, declareAppProvidersPlugin, } from './core.ts';
|
|
3
|
-
export { FIND_CHILD_SERVICE, FIND_CHILDREN_SERVICES } from './constants.ts';
|
|
3
|
+
export { FIND_CHILD_SERVICE, FIND_CHILDREN_SERVICES, CONTAINER_TOKEN } from './constants.ts';
|
|
4
4
|
export type { FindChildService, FindChildrenServices } from './interface.ts';
|
|
5
5
|
export { Computed } from './computed.ts';
|
|
6
6
|
export { Raw } from './raw.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Token as D, Container as H, isObject as v, getOwnMetadata as j, hasOwn as K } from "@kaokei/di";
|
|
2
2
|
export * from "@kaokei/di";
|
|
3
|
-
import { effectScope as N, markRaw as P, reactive as L, inject as b, provide as W, onUnmounted as Y, hasInjectionContext as U, getCurrentInstance as z, toRaw as
|
|
3
|
+
import { effectScope as N, markRaw as P, reactive as L, inject as b, provide as W, onUnmounted as Y, hasInjectionContext as U, getCurrentInstance as z, toRaw as l, computed as E } from "vue";
|
|
4
4
|
const B = new D(
|
|
5
5
|
"FIND_CHILD_SERVICE"
|
|
6
6
|
), G = new D(
|
|
@@ -26,8 +26,8 @@ function T(n) {
|
|
|
26
26
|
}
|
|
27
27
|
function C(n, e, t, r) {
|
|
28
28
|
if (n) {
|
|
29
|
-
for (const
|
|
30
|
-
if (
|
|
29
|
+
for (const i of n)
|
|
30
|
+
if (i.isCurrentBound(e) && (t.push(i.get(e)), r) || C(i.getChildren(), e, t, r))
|
|
31
31
|
return !0;
|
|
32
32
|
}
|
|
33
33
|
return !1;
|
|
@@ -58,7 +58,7 @@ function S(n) {
|
|
|
58
58
|
let e;
|
|
59
59
|
return n ? e = n.createChild() : e = new H(), e.bind(B).toDynamicValue(Z), e.bind(G).toDynamicValue(x), e.onActivation(Q), e.onDeactivation(X), e;
|
|
60
60
|
}
|
|
61
|
-
const
|
|
61
|
+
const f = S();
|
|
62
62
|
function c(n, e) {
|
|
63
63
|
if (typeof e == "function")
|
|
64
64
|
e(n);
|
|
@@ -79,12 +79,12 @@ function F(n) {
|
|
|
79
79
|
throw new Error(`${n} must inside setup.`);
|
|
80
80
|
}
|
|
81
81
|
function h() {
|
|
82
|
-
return b(u,
|
|
82
|
+
return b(u, f);
|
|
83
83
|
}
|
|
84
84
|
function re(n) {
|
|
85
85
|
return F("useService"), (V() || h()).get(n);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function ie(n) {
|
|
88
88
|
F("declareProviders");
|
|
89
89
|
const e = V();
|
|
90
90
|
if (e)
|
|
@@ -96,11 +96,11 @@ function oe(n) {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
return
|
|
99
|
+
function oe(n) {
|
|
100
|
+
return f.get(n);
|
|
101
101
|
}
|
|
102
102
|
function ue(n) {
|
|
103
|
-
c(
|
|
103
|
+
c(f, n);
|
|
104
104
|
}
|
|
105
105
|
function ce(n, e) {
|
|
106
106
|
return e.runWithContext(() => h().get(n));
|
|
@@ -111,7 +111,7 @@ function ee(n, e) {
|
|
|
111
111
|
if (t)
|
|
112
112
|
c(t, n);
|
|
113
113
|
else {
|
|
114
|
-
const r = S(
|
|
114
|
+
const r = S(f);
|
|
115
115
|
c(r, n), e.provide(u, r), e.onUnmount(() => {
|
|
116
116
|
r.destroy();
|
|
117
117
|
});
|
|
@@ -124,23 +124,23 @@ function se(n) {
|
|
|
124
124
|
function I(n, e) {
|
|
125
125
|
const t = e.name;
|
|
126
126
|
return function() {
|
|
127
|
-
const r = this,
|
|
128
|
-
let
|
|
127
|
+
const r = this, i = l(this), g = T(i), m = n;
|
|
128
|
+
let d, s = Object.getPrototypeOf(i);
|
|
129
129
|
for (; s; ) {
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
130
|
+
const o = Object.getOwnPropertyDescriptor(s, t);
|
|
131
|
+
if (o && o.set) {
|
|
132
|
+
d = o.set;
|
|
133
133
|
break;
|
|
134
134
|
}
|
|
135
135
|
s = Object.getPrototypeOf(s);
|
|
136
136
|
}
|
|
137
|
-
const _ =
|
|
137
|
+
const _ = d ? g.run(
|
|
138
138
|
() => E({
|
|
139
139
|
get: () => m.call(r),
|
|
140
|
-
set: (
|
|
140
|
+
set: (o) => d.call(r, o)
|
|
141
141
|
})
|
|
142
142
|
) : g.run(() => E(() => m.call(r)));
|
|
143
|
-
return Object.defineProperty(
|
|
143
|
+
return Object.defineProperty(i, t, {
|
|
144
144
|
value: _,
|
|
145
145
|
writable: !0,
|
|
146
146
|
configurable: !0,
|
|
@@ -151,34 +151,34 @@ function I(n, e) {
|
|
|
151
151
|
function ae(n, e) {
|
|
152
152
|
return typeof n == "function" && (e == null ? void 0 : e.kind) === "getter" ? I(n, e) : I;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function a(n) {
|
|
155
155
|
return v(n) ? P(n) : n;
|
|
156
156
|
}
|
|
157
157
|
function w(n, e) {
|
|
158
158
|
const t = e.name;
|
|
159
|
-
e.addInitializer(function() {
|
|
160
|
-
let r;
|
|
159
|
+
return e.addInitializer(function() {
|
|
160
|
+
let r = this[t];
|
|
161
161
|
Object.defineProperty(this, t, {
|
|
162
162
|
configurable: !0,
|
|
163
163
|
enumerable: !0,
|
|
164
164
|
get() {
|
|
165
165
|
return r;
|
|
166
166
|
},
|
|
167
|
-
set(
|
|
168
|
-
r =
|
|
167
|
+
set(i) {
|
|
168
|
+
r = a(i);
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
|
-
});
|
|
171
|
+
}), a;
|
|
172
172
|
}
|
|
173
173
|
function O(n, e) {
|
|
174
174
|
return {
|
|
175
175
|
get() {
|
|
176
|
-
return n.get.call(
|
|
176
|
+
return n.get.call(l(this));
|
|
177
177
|
},
|
|
178
178
|
set(t) {
|
|
179
|
-
n.set.call(
|
|
179
|
+
n.set.call(l(this), a(t));
|
|
180
180
|
},
|
|
181
|
-
init:
|
|
181
|
+
init: a
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
184
|
function R(n, e) {
|
|
@@ -189,14 +189,15 @@ function fe(n, e) {
|
|
|
189
189
|
}
|
|
190
190
|
function y(n, e) {
|
|
191
191
|
return function(...t) {
|
|
192
|
-
const
|
|
193
|
-
return
|
|
192
|
+
const i = T(this).run(() => N());
|
|
193
|
+
return i.run(() => n.call(this, ...t)), i;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
function de(n, e) {
|
|
197
197
|
return typeof n == "function" && (e == null ? void 0 : e.kind) === "method" ? y(n) : y;
|
|
198
198
|
}
|
|
199
199
|
export {
|
|
200
|
+
u as CONTAINER_TOKEN,
|
|
200
201
|
ae as Computed,
|
|
201
202
|
G as FIND_CHILDREN_SERVICES,
|
|
202
203
|
B as FIND_CHILD_SERVICE,
|
|
@@ -204,9 +205,9 @@ export {
|
|
|
204
205
|
de as RunInScope,
|
|
205
206
|
ee as declareAppProviders,
|
|
206
207
|
se as declareAppProvidersPlugin,
|
|
207
|
-
|
|
208
|
+
ie as declareProviders,
|
|
208
209
|
ue as declareRootProviders,
|
|
209
210
|
ce as useAppService,
|
|
210
|
-
|
|
211
|
+
oe as useRootService,
|
|
211
212
|
re as useService
|
|
212
213
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaokei/use-vue-service",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight Vue 3 state management with dependency injection, inspired by Angular services.",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"coverage": "vitest run --coverage",
|
|
44
44
|
"build": "vue-tsc -b tsconfig.app.json && vite build",
|
|
45
45
|
"clean": "rm -rf dist/*",
|
|
46
|
-
"public": "npm publish --access public",
|
|
47
46
|
"postpublish": "git push origin --follow-tags",
|
|
48
47
|
"prepublishOnly": "npm run clean && npm run build",
|
|
49
48
|
"release": "standard-version -r",
|
|
@@ -79,5 +78,8 @@
|
|
|
79
78
|
"reflect-metadata": "^0.2.2",
|
|
80
79
|
"unplugin-swc": "^1.5.9"
|
|
81
80
|
},
|
|
81
|
+
"publishConfig": {
|
|
82
|
+
"access": "public"
|
|
83
|
+
},
|
|
82
84
|
"packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
|
|
83
85
|
}
|