@kaokei/use-vue-service 3.0.1 → 3.0.2
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 +1 -1
- package/dist/constants.d.cts +0 -2
- package/dist/constants.d.ts +0 -2
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +100 -103
- package/dist/scope.d.cts +1 -1
- package/dist/scope.d.ts +1 -1
- package/dist/utils.d.cts +1 -2
- package/dist/utils.d.ts +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/constants.d.cts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Token } from '@kaokei/di';
|
|
2
|
-
import { ComponentInternalInstance } from 'vue';
|
|
3
2
|
import { FindChildService, FindChildrenServices } from './interface.ts';
|
|
4
|
-
export declare const CURRENT_COMPONENT: Token<ComponentInternalInstance>;
|
|
5
3
|
export declare const FIND_CHILD_SERVICE: Token<FindChildService>;
|
|
6
4
|
export declare const FIND_CHILDREN_SERVICES: Token<FindChildrenServices>;
|
|
7
5
|
export declare const SCOPE_KEY: unique symbol;
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Token } from '@kaokei/di';
|
|
2
|
-
import { ComponentInternalInstance } from 'vue';
|
|
3
2
|
import { FindChildService, FindChildrenServices } from './interface.ts';
|
|
4
|
-
export declare const CURRENT_COMPONENT: Token<ComponentInternalInstance>;
|
|
5
3
|
export declare const FIND_CHILD_SERVICE: Token<FindChildService>;
|
|
6
4
|
export declare const FIND_CHILDREN_SERVICES: Token<FindChildrenServices>;
|
|
7
5
|
export declare const SCOPE_KEY: unique symbol;
|
package/dist/core.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { App } from 'vue';
|
|
|
2
2
|
import { CommonToken } from '@kaokei/di';
|
|
3
3
|
import { NewableProvider, FunctionProvider, Provider } from './interface.ts';
|
|
4
4
|
export declare function useService<T>(token: CommonToken<T>): T;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function getRootService<T>(token: CommonToken<T>): T;
|
|
6
6
|
export declare function useAppService<T>(token: CommonToken<T>, app: App): T;
|
|
7
7
|
export declare function declareProviders(providers: FunctionProvider): void;
|
|
8
8
|
export declare function declareProviders(providers: NewableProvider): void;
|
package/dist/core.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { App } from 'vue';
|
|
|
2
2
|
import { CommonToken } from '@kaokei/di';
|
|
3
3
|
import { NewableProvider, FunctionProvider, Provider } from './interface.ts';
|
|
4
4
|
export declare function useService<T>(token: CommonToken<T>): T;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function getRootService<T>(token: CommonToken<T>): T;
|
|
6
6
|
export declare function useAppService<T>(token: CommonToken<T>, app: App): T;
|
|
7
7
|
export declare function declareProviders(providers: FunctionProvider): void;
|
|
8
8
|
export declare function declareProviders(providers: NewableProvider): void;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@kaokei/di"),o=require("vue");function b(e){const t=e,n=o.effectScope(!0);return t[S]=n,n}function _(e){return e[S]}function N(e){const t=e;if(t){const n=_(t);n&&(n.stop(),delete t[S])}}function h(e){const t=_(e);return t||b(e)}function C(e,t,n){return e&&e.forEach(r=>{r&&r.isCurrentBound(t)&&n.push(r.get(t)),r.children&&C(r.children,t,n)}),n}function D(e,t){const n=[];return C(t.children,e,n),n[0]}function O(e,t){const n=[];return C(t.children,e,n),n}function A(e){return e!==null&&typeof e=="object"}function V(e,t){return A(t)?o.reactive(t):t}function T(e){return N(e)}function j({container:e}){return t=>D(t,e)}function w({container:e}){return t=>O(t,e)}function E(e){let t;return e?t=e.createChild():t=new u.Container,t.bind(I).toDynamicValue(j),t.bind(g).toDynamicValue(w),t.onActivation(V),t.onDeactivation(T),t}const I=new u.Token("USE_REACT_SERVICE_FIND_CHILD_SERVICE"),g=new u.Token("USE_REACT_SERVICE_FIND_CHILDREN_SERVICES"),S=Symbol(),s="USE_VUE_SERVICE_CONTAINER_TOKEN",f=E();function a(e,t){if(typeof t=="function")t(e);else for(let n=0;n<t.length;n++)e.bind(t[n]).toSelf()}function R(){const e=o.getCurrentInstance();if(e){const t=s,n=e.provides,r=e.parent&&e.parent.provides;if(n&&n!==r&&Object.prototype.hasOwnProperty.call(n,t))return n[t]}}function v(){if(o.hasInjectionContext())return o.inject(s,f);throw new Error("getProvideContainer 只能在 setup 中使用")}function F(e){return(R()||v()).get(e)}function H(e){return f.get(e)}function L(e,t){return t.runWithContext(()=>v().get(e))}function U(e){const t=R();if(t)a(t,e);else{const n=v();let r=E(n);a(r,e),o.provide(s,r),o.onUnmounted(()=>{r.destroy(),r=null})}}function x(e){a(f,e)}function m(e,t){t.runWithContext(()=>{const n=o.inject(s,null);if(n)a(n,e);else{let r=E(f);a(r,e),t.provide(s,r),t.onUnmount(()=>{r.destroy(),r=null})}})}function K(e){return t=>m(e,t)}function q(e,t,n){const r=n.get,d=n.set;return{configurable:!0,enumerable:!0,get(){const c=o.reactive(this),l=Symbol.for(t);let i=c[l];if(!i){const y=h(c).run(()=>d?o.computed({get:()=>r.call(c),set:P=>d.call(c,P)}):o.computed(()=>r.call(c)));i=o.markRaw({value:y}),c[l]=i}return i.value.value},set(c){const l=o.reactive(this),i=Symbol.for(t),p=l[i];p&&d&&(p.value.value=c)}}}exports.Computed=q;exports.FIND_CHILDREN_SERVICES=g;exports.FIND_CHILD_SERVICE=I;exports.declareAppProviders=m;exports.declareAppProvidersPlugin=K;exports.declareProviders=U;exports.declareRootProviders=x;exports.getEffectScope=h;exports.getRootService=H;exports.useAppService=L;exports.useService=F;Object.keys(u).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>u[e]})});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '@kaokei/di';
|
|
2
|
-
export {
|
|
3
|
-
export { useService, declareProviders,
|
|
2
|
+
export { FIND_CHILD_SERVICE, FIND_CHILDREN_SERVICES } from './constants.ts';
|
|
3
|
+
export { useService, declareProviders, getRootService, declareRootProviders, useAppService, declareAppProviders, declareAppProvidersPlugin, } from './core.ts';
|
|
4
4
|
export { Computed } from './computed.ts';
|
|
5
5
|
export { getEffectScope } from './scope.ts';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '@kaokei/di';
|
|
2
|
-
export {
|
|
3
|
-
export { useService, declareProviders,
|
|
2
|
+
export { FIND_CHILD_SERVICE, FIND_CHILDREN_SERVICES } from './constants.ts';
|
|
3
|
+
export { useService, declareProviders, getRootService, declareRootProviders, useAppService, declareAppProviders, declareAppProvidersPlugin, } from './core.ts';
|
|
4
4
|
export { Computed } from './computed.ts';
|
|
5
5
|
export { getEffectScope } from './scope.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,167 +1,164 @@
|
|
|
1
|
-
import { Container as y, Token as
|
|
1
|
+
import { Container as y, Token as h } from "@kaokei/di";
|
|
2
2
|
export * from "@kaokei/di";
|
|
3
|
-
import { effectScope as
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}), n;
|
|
3
|
+
import { effectScope as N, reactive as d, provide as D, onUnmounted as b, inject as _, getCurrentInstance as O, hasInjectionContext as P, computed as v, markRaw as A } from "vue";
|
|
4
|
+
function V(e) {
|
|
5
|
+
const t = e, n = N(!0);
|
|
6
|
+
return t[E] = n, n;
|
|
8
7
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
return E(e.children, t, n), n[0];
|
|
8
|
+
function m(e) {
|
|
9
|
+
return e[E];
|
|
12
10
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
|
|
11
|
+
function T(e) {
|
|
12
|
+
const t = e;
|
|
13
|
+
if (t) {
|
|
14
|
+
const n = m(t);
|
|
15
|
+
n && (n.stop(), delete t[E]);
|
|
16
|
+
}
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
const
|
|
19
|
-
return
|
|
18
|
+
function w(e) {
|
|
19
|
+
const t = m(e);
|
|
20
|
+
return t || V(e);
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
22
|
+
function C(e, t, n) {
|
|
23
|
+
return e && e.forEach((o) => {
|
|
24
|
+
o && o.isCurrentBound(t) && n.push(o.get(t)), o.children && C(o.children, t, n);
|
|
25
|
+
}), n;
|
|
23
26
|
}
|
|
24
|
-
function
|
|
25
|
-
const
|
|
26
|
-
return e
|
|
27
|
+
function F(e, t) {
|
|
28
|
+
const n = [];
|
|
29
|
+
return C(t.children, e, n), n[0];
|
|
27
30
|
}
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const n = I(e);
|
|
32
|
-
n && (n.stop(), delete e[S]);
|
|
33
|
-
}
|
|
31
|
+
function U(e, t) {
|
|
32
|
+
const n = [];
|
|
33
|
+
return C(t.children, e, n), n;
|
|
34
34
|
}
|
|
35
|
-
function H(
|
|
36
|
-
return
|
|
35
|
+
function H(e) {
|
|
36
|
+
return e !== null && typeof e == "object";
|
|
37
37
|
}
|
|
38
|
-
function x(
|
|
39
|
-
return H(
|
|
38
|
+
function x(e, t) {
|
|
39
|
+
return H(t) ? d(t) : t;
|
|
40
40
|
}
|
|
41
|
-
function L(
|
|
42
|
-
return
|
|
41
|
+
function L(e) {
|
|
42
|
+
return T(e);
|
|
43
43
|
}
|
|
44
|
-
function j({ container:
|
|
45
|
-
return (
|
|
44
|
+
function j({ container: e }) {
|
|
45
|
+
return (t) => F(t, e);
|
|
46
46
|
}
|
|
47
47
|
function K({
|
|
48
|
-
container:
|
|
48
|
+
container: e
|
|
49
49
|
}) {
|
|
50
|
-
return (
|
|
50
|
+
return (t) => U(t, e);
|
|
51
51
|
}
|
|
52
|
-
function p(
|
|
53
|
-
let
|
|
54
|
-
return
|
|
52
|
+
function p(e) {
|
|
53
|
+
let t;
|
|
54
|
+
return e ? t = e.createChild() : t = new y(), t.bind(W).toDynamicValue(j), t.bind(k).toDynamicValue(K), t.onActivation(x), t.onDeactivation(L), t;
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
"USE_VUE_SERVICE_CURRENT_COMPONENT"
|
|
58
|
-
), W = new d(
|
|
56
|
+
const W = new h(
|
|
59
57
|
"USE_REACT_SERVICE_FIND_CHILD_SERVICE"
|
|
60
|
-
), k = new
|
|
58
|
+
), k = new h(
|
|
61
59
|
"USE_REACT_SERVICE_FIND_CHILDREN_SERVICES"
|
|
62
|
-
),
|
|
63
|
-
function
|
|
64
|
-
if (typeof
|
|
65
|
-
e
|
|
60
|
+
), E = Symbol(), i = "USE_VUE_SERVICE_CONTAINER_TOKEN", f = p();
|
|
61
|
+
function u(e, t) {
|
|
62
|
+
if (typeof t == "function")
|
|
63
|
+
t(e);
|
|
66
64
|
else
|
|
67
|
-
for (let n = 0; n <
|
|
68
|
-
|
|
65
|
+
for (let n = 0; n < t.length; n++)
|
|
66
|
+
e.bind(t[n]).toSelf();
|
|
69
67
|
}
|
|
70
|
-
function
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
68
|
+
function I() {
|
|
69
|
+
const e = O();
|
|
70
|
+
if (e) {
|
|
71
|
+
const t = i, n = e.provides, o = e.parent && e.parent.provides;
|
|
74
72
|
if (
|
|
75
73
|
// 当前实例的provides存在
|
|
76
74
|
n && // 当前实例的provides已经和parentProvides不是一个对象,说明已经Object.create(parentProvides)
|
|
77
75
|
n !== o && // provides自身已经具有CONTAINER_TOKEN属性
|
|
78
|
-
Object.prototype.hasOwnProperty.call(n,
|
|
76
|
+
Object.prototype.hasOwnProperty.call(n, t)
|
|
79
77
|
)
|
|
80
|
-
return n[
|
|
78
|
+
return n[t];
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
|
-
function
|
|
84
|
-
if (
|
|
85
|
-
return
|
|
81
|
+
function S() {
|
|
82
|
+
if (P())
|
|
83
|
+
return _(i, f);
|
|
86
84
|
throw new Error("getProvideContainer 只能在 setup 中使用");
|
|
87
85
|
}
|
|
88
|
-
function q(
|
|
89
|
-
return (
|
|
86
|
+
function q(e) {
|
|
87
|
+
return (I() || S()).get(e);
|
|
90
88
|
}
|
|
91
|
-
function z(
|
|
92
|
-
return
|
|
89
|
+
function z(e) {
|
|
90
|
+
return f.get(e);
|
|
93
91
|
}
|
|
94
|
-
function J(
|
|
95
|
-
return
|
|
92
|
+
function J(e, t) {
|
|
93
|
+
return t.runWithContext(() => S().get(e));
|
|
96
94
|
}
|
|
97
|
-
function
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
|
|
95
|
+
function M(e) {
|
|
96
|
+
const t = I();
|
|
97
|
+
if (t)
|
|
98
|
+
u(t, e);
|
|
101
99
|
else {
|
|
102
|
-
const n =
|
|
103
|
-
let
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
const n = S();
|
|
101
|
+
let o = p(n);
|
|
102
|
+
u(o, e), D(i, o), b(() => {
|
|
103
|
+
o.destroy(), o = null;
|
|
106
104
|
});
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
|
-
function
|
|
110
|
-
|
|
107
|
+
function Q(e) {
|
|
108
|
+
u(f, e);
|
|
111
109
|
}
|
|
112
|
-
function B(
|
|
113
|
-
|
|
114
|
-
const n =
|
|
115
|
-
|
|
110
|
+
function B(e, t) {
|
|
111
|
+
t.runWithContext(() => {
|
|
112
|
+
const n = _(
|
|
113
|
+
i,
|
|
116
114
|
null
|
|
117
115
|
);
|
|
118
116
|
if (n)
|
|
119
|
-
|
|
117
|
+
u(n, e);
|
|
120
118
|
else {
|
|
121
|
-
let o = p(
|
|
122
|
-
|
|
119
|
+
let o = p(f);
|
|
120
|
+
u(o, e), t.provide(i, o), t.onUnmount(() => {
|
|
123
121
|
o.destroy(), o = null;
|
|
124
122
|
});
|
|
125
123
|
}
|
|
126
124
|
});
|
|
127
125
|
}
|
|
128
|
-
function
|
|
129
|
-
return (
|
|
126
|
+
function X(e) {
|
|
127
|
+
return (t) => B(e, t);
|
|
130
128
|
}
|
|
131
|
-
function
|
|
132
|
-
const o = n.get,
|
|
129
|
+
function Z(e, t, n) {
|
|
130
|
+
const o = n.get, l = n.set;
|
|
133
131
|
return {
|
|
134
132
|
configurable: !0,
|
|
135
133
|
enumerable: !0,
|
|
136
134
|
get() {
|
|
137
|
-
const
|
|
138
|
-
let
|
|
139
|
-
if (!
|
|
140
|
-
const
|
|
141
|
-
get: () => o.call(
|
|
142
|
-
set: (
|
|
143
|
-
}) : v(() => o.call(
|
|
144
|
-
|
|
135
|
+
const r = d(this), s = Symbol.for(t);
|
|
136
|
+
let c = r[s];
|
|
137
|
+
if (!c) {
|
|
138
|
+
const R = w(r).run(() => l ? v({
|
|
139
|
+
get: () => o.call(r),
|
|
140
|
+
set: (g) => l.call(r, g)
|
|
141
|
+
}) : v(() => o.call(r)));
|
|
142
|
+
c = A({ value: R }), r[s] = c;
|
|
145
143
|
}
|
|
146
|
-
return
|
|
144
|
+
return c.value.value;
|
|
147
145
|
},
|
|
148
|
-
set(
|
|
149
|
-
const
|
|
150
|
-
|
|
146
|
+
set(r) {
|
|
147
|
+
const s = d(this), c = Symbol.for(t), a = s[c];
|
|
148
|
+
a && l && (a.value.value = r);
|
|
151
149
|
}
|
|
152
150
|
};
|
|
153
151
|
}
|
|
154
152
|
export {
|
|
155
|
-
|
|
156
|
-
$ as Computed,
|
|
153
|
+
Z as Computed,
|
|
157
154
|
k as FIND_CHILDREN_SERVICES,
|
|
158
155
|
W as FIND_CHILD_SERVICE,
|
|
159
156
|
B as declareAppProviders,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
X as declareAppProvidersPlugin,
|
|
158
|
+
M as declareProviders,
|
|
159
|
+
Q as declareRootProviders,
|
|
163
160
|
w as getEffectScope,
|
|
161
|
+
z as getRootService,
|
|
164
162
|
J as useAppService,
|
|
165
|
-
z as useRootService,
|
|
166
163
|
q as useService
|
|
167
164
|
};
|
package/dist/scope.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EffectScope } from 'vue';
|
|
2
2
|
export declare function createScope(obj: object): EffectScope;
|
|
3
3
|
export declare function getScope(obj: object): EffectScope | undefined;
|
|
4
|
-
export declare function getEffectScope(obj: object): EffectScope;
|
|
5
4
|
export declare function removeScope(obj: object): void;
|
|
5
|
+
export declare function getEffectScope(obj: object): EffectScope;
|
package/dist/scope.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EffectScope } from 'vue';
|
|
2
2
|
export declare function createScope(obj: object): EffectScope;
|
|
3
3
|
export declare function getScope(obj: object): EffectScope | undefined;
|
|
4
|
-
export declare function getEffectScope(obj: object): EffectScope;
|
|
5
4
|
export declare function removeScope(obj: object): void;
|
|
5
|
+
export declare function getEffectScope(obj: object): EffectScope;
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { Container } from '@kaokei/di';
|
|
2
|
-
|
|
3
|
-
export declare function createContainer(parent?: Container, instance?: ComponentInternalInstance | null): Container;
|
|
2
|
+
export declare function createContainer(parent?: Container): Container;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { Container } from '@kaokei/di';
|
|
2
|
-
|
|
3
|
-
export declare function createContainer(parent?: Container, instance?: ComponentInternalInstance | null): Container;
|
|
2
|
+
export declare function createContainer(parent?: Container): Container;
|
package/package.json
CHANGED