@kaokei/use-vue-service 4.0.0 → 4.0.1

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@kaokei/di"),o=require("vue"),P=new c.Token("FIND_CHILD_SERVICE"),m=new c.Token("FIND_CHILDREN_SERVICES"),C=Symbol("SCOPE_KEY"),s=Symbol("CONTAINER_TOKEN");function w(t){const e=t,n=o.effectScope(!0);return e[C]=n,n}function b(t){return t[C]}function j(t){const e=t;if(e){const n=b(e);n&&(n.stop(),delete e[C])}}function D(t){const e=b(t);return e||w(t)}function h(t,e,n,r){if(t){for(const i of t)if(i.isCurrentBound(e)&&(n.push(i.get(e)),r)||i.children&&h(i.children,e,n,r))return!0}return!1}function A(t,e){const n=[];return h(e.children,t,n,!0),n[0]}function T(t,e){const n=[];return h(e.children,t,n,!1),n}function V(t,e){return c.isObject(e)?o.reactive(e):e}function H(t){return j(t)}function k({container:t}){return e=>A(e,t)}function F({container:t}){return e=>T(e,t)}function g(t){let e;return t?e=t.createChild():e=new c.Container,e.bind(P).toDynamicValue(k),e.bind(m).toDynamicValue(F),e.onActivation(V),e.onDeactivation(H),e}const d=g();function a(t,e){if(typeof e=="function")e(t);else for(let n=0;n<e.length;n++)t.bind(e[n]).toSelf()}function N(){const t=o.getCurrentInstance();if(t){const e=s,n=t.provides,r=t.parent&&t.parent.provides;if(n&&n!==r&&c.hasOwn(n,e))return n[e]}}function v(){if(o.hasInjectionContext())return o.inject(s,d);throw new Error("getProvideContainer 只能在 setup 中使用")}function L(t){return(N()||v()).get(t)}function K(t){const e=N();if(e)a(e,t);else{const n=v();let r=g(n);a(r,t),o.provide(s,r),o.onUnmounted(()=>{r.destroy(),r=null})}}function q(t){return d.get(t)}function U(t){a(d,t)}function W(t,e){return e.runWithContext(()=>v().get(t))}function _(t,e){e.runWithContext(()=>{const n=o.inject(s,null);if(n)a(n,t);else{let r=g(d);a(r,t),e.provide(s,r),e.onUnmount(()=>{r.destroy(),r=null})}})}function Y(t){return e=>_(t,e)}function O(t,e){const n=e.name;return function(){const r=D(this),i=t,E=o.toRaw(this);let p,f=Object.getPrototypeOf(E);for(;f;){const u=Object.getOwnPropertyDescriptor(f,n);if(u&&u.set){p=u.set;break}f=Object.getPrototypeOf(f)}const S=this,I=p?r.run(()=>o.computed({get:()=>i.call(S),set:u=>p.call(S,u)})):r.run(()=>o.computed(()=>i.call(S)));return Object.defineProperty(E,n,{value:I,writable:!0,configurable:!0,enumerable:!0}),I.value}}function z(t,e){return typeof t=="function"&&(e==null?void 0:e.kind)==="getter"?O(t,e):O}function l(t){return c.isObject(t)?o.markRaw(t):t}function R(t,e){if(e.kind==="accessor")return{get(){return t.get.call(this)},set(r){t.set.call(this,l(r))},init:l};const n=e.name;return e.addInitializer(function(){let r;Object.defineProperty(this,n,{configurable:!0,enumerable:!0,get(){return r},set(i){r=l(i)}})}),l}function B(t,e){return(e==null?void 0:e.kind)==="field"||(e==null?void 0:e.kind)==="accessor"?R(t,e):R}function y(t,e){return function(...n){const i=D(this).run(()=>o.effectScope());return i.run(()=>t.call(this,...n)),i}}function G(t,e){return typeof t=="function"&&(e==null?void 0:e.kind)==="method"?y(t):y}exports.Computed=z;exports.FIND_CHILDREN_SERVICES=m;exports.FIND_CHILD_SERVICE=P;exports.Raw=B;exports.RunInScope=G;exports.declareAppProviders=_;exports.declareAppProvidersPlugin=Y;exports.declareProviders=K;exports.declareRootProviders=U;exports.useAppService=W;exports.useRootService=q;exports.useService=L;Object.keys(c).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>c[t]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@kaokei/di"),o=require("vue"),P=new c.Token("FIND_CHILD_SERVICE"),m=new c.Token("FIND_CHILDREN_SERVICES"),C=Symbol("SCOPE_KEY"),s=Symbol("CONTAINER_TOKEN");function _(t){const e=t,n=o.effectScope(!0);return e[C]=n,n}function b(t){return t[C]}function j(t){const e=t;if(e){const n=b(e);n&&(n.stop(),delete e[C])}}function w(t){const e=b(t);return e||_(t)}function h(t,e,n,r){if(t){for(const i of t)if(i.isCurrentBound(e)&&(n.push(i.get(e)),r)||i.children&&h(i.children,e,n,r))return!0}return!1}function A(t,e){const n=[];return h(e.children,t,n,!0),n[0]}function T(t,e){const n=[];return h(e.children,t,n,!1),n}function V(t,e){return c.isObject(e)?o.reactive(e):e}function H(t){return j(t)}function k({container:t}){return e=>A(e,t)}function F({container:t}){return e=>T(e,t)}function g(t){let e;return t?e=t.createChild():e=new c.Container,e.bind(P).toDynamicValue(k),e.bind(m).toDynamicValue(F),e.onActivation(V),e.onDeactivation(H),e}const d=g();function a(t,e){if(typeof e=="function")e(t);else for(let n=0;n<e.length;n++)t.bind(e[n]).toSelf()}function D(){const t=o.getCurrentInstance();if(t){const e=s,n=t.provides,r=t.parent&&t.parent.provides;if(n&&n!==r&&c.hasOwn(n,e))return n[e]}}function v(){if(o.hasInjectionContext())return o.inject(s,d);throw new Error("getProvideContainer 只能在 setup 中使用")}function L(t){return(D()||v()).get(t)}function K(t){const e=D();if(e)a(e,t);else{const n=v();let r=g(n);a(r,t),o.provide(s,r),o.onUnmounted(()=>{r.destroy(),r=null})}}function q(t){return d.get(t)}function U(t){a(d,t)}function W(t,e){return e.runWithContext(()=>v().get(t))}function N(t,e){e.runWithContext(()=>{const n=o.inject(s,null);if(n)a(n,t);else{let r=g(d);a(r,t),e.provide(s,r),e.onUnmount(()=>{r.destroy(),r=null})}})}function Y(t){return e=>N(t,e)}function R(t,e){const n=e.name;return function(){const r=w(this),i=t,E=o.toRaw(this);let p,f=Object.getPrototypeOf(E);for(;f;){const u=Object.getOwnPropertyDescriptor(f,n);if(u&&u.set){p=u.set;break}f=Object.getPrototypeOf(f)}const S=this,I=p?r.run(()=>o.computed({get:()=>i.call(S),set:u=>p.call(S,u)})):r.run(()=>o.computed(()=>i.call(S)));return Object.defineProperty(E,n,{value:I,writable:!0,configurable:!0,enumerable:!0}),I.value}}function z(t,e){return typeof t=="function"&&(e==null?void 0:e.kind)==="getter"?R(t,e):R}function l(t){return c.isObject(t)?o.markRaw(t):t}function O(t,e){if(e.kind==="accessor")return{get(){return t.get.call(o.toRaw(this))},set(r){t.set.call(o.toRaw(this),l(r))},init:l};const n=e.name;return e.addInitializer(function(){let r;Object.defineProperty(this,n,{configurable:!0,enumerable:!0,get(){return r},set(i){r=l(i)}})}),l}function B(t,e){return(e==null?void 0:e.kind)==="field"||(e==null?void 0:e.kind)==="accessor"?O(t,e):O}function y(t,e){return function(...n){const i=w(this).run(()=>o.effectScope());return i.run(()=>t.call(this,...n)),i}}function G(t,e){return typeof t=="function"&&(e==null?void 0:e.kind)==="method"?y(t):y}exports.Computed=z;exports.FIND_CHILDREN_SERVICES=m;exports.FIND_CHILD_SERVICE=P;exports.Raw=B;exports.RunInScope=G;exports.declareAppProviders=N;exports.declareAppProvidersPlugin=Y;exports.declareProviders=K;exports.declareRootProviders=U;exports.useAppService=W;exports.useRootService=q;exports.useService=L;Object.keys(c).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>c[t]})});
package/dist/index.js CHANGED
@@ -1,47 +1,47 @@
1
- import { Token as y, Container as _, isObject as R, hasOwn as k } from "@kaokei/di";
1
+ import { Token as R, Container as k, isObject as w, hasOwn as A } from "@kaokei/di";
2
2
  export * from "@kaokei/di";
3
- import { effectScope as w, reactive as A, inject as N, provide as T, onUnmounted as V, getCurrentInstance as H, hasInjectionContext as j, toRaw as F, computed as E, markRaw as K } from "vue";
4
- const L = new y(
3
+ import { effectScope as N, reactive as T, inject as P, provide as V, onUnmounted as H, getCurrentInstance as j, hasInjectionContext as F, toRaw as p, computed as I, markRaw as K } from "vue";
4
+ const L = new R(
5
5
  "FIND_CHILD_SERVICE"
6
- ), U = new y(
6
+ ), U = new R(
7
7
  "FIND_CHILDREN_SERVICES"
8
- ), p = Symbol("SCOPE_KEY"), c = Symbol("CONTAINER_TOKEN");
8
+ ), h = Symbol("SCOPE_KEY"), c = Symbol("CONTAINER_TOKEN");
9
9
  function W(n) {
10
- const e = n, t = w(!0);
11
- return e[p] = t, t;
10
+ const e = n, t = N(!0);
11
+ return e[h] = t, t;
12
12
  }
13
- function P(n) {
14
- return n[p];
13
+ function b(n) {
14
+ return n[h];
15
15
  }
16
16
  function Y(n) {
17
17
  const e = n;
18
18
  if (e) {
19
- const t = P(e);
20
- t && (t.stop(), delete e[p]);
19
+ const t = b(e);
20
+ t && (t.stop(), delete e[h]);
21
21
  }
22
22
  }
23
- function b(n) {
24
- const e = P(n);
23
+ function D(n) {
24
+ const e = b(n);
25
25
  return e || W(n);
26
26
  }
27
- function h(n, e, t, r) {
27
+ function C(n, e, t, r) {
28
28
  if (n) {
29
29
  for (const o of n)
30
- if (o.isCurrentBound(e) && (t.push(o.get(e)), r) || o.children && h(o.children, e, t, r))
30
+ if (o.isCurrentBound(e) && (t.push(o.get(e)), r) || o.children && C(o.children, e, t, r))
31
31
  return !0;
32
32
  }
33
33
  return !1;
34
34
  }
35
35
  function z(n, e) {
36
36
  const t = [];
37
- return h(e.children, n, t, !0), t[0];
37
+ return C(e.children, n, t, !0), t[0];
38
38
  }
39
39
  function B(n, e) {
40
40
  const t = [];
41
- return h(e.children, n, t, !1), t;
41
+ return C(e.children, n, t, !1), t;
42
42
  }
43
43
  function G(n, e) {
44
- return R(e) ? A(e) : e;
44
+ return w(e) ? T(e) : e;
45
45
  }
46
46
  function q(n) {
47
47
  return Y(n);
@@ -54,11 +54,11 @@ function M({
54
54
  }) {
55
55
  return (e) => B(e, n);
56
56
  }
57
- function C(n) {
57
+ function S(n) {
58
58
  let e;
59
- return n ? e = n.createChild() : e = new _(), e.bind(L).toDynamicValue(J), e.bind(U).toDynamicValue(M), e.onActivation(G), e.onDeactivation(q), e;
59
+ return n ? e = n.createChild() : e = new k(), e.bind(L).toDynamicValue(J), e.bind(U).toDynamicValue(M), e.onActivation(G), e.onDeactivation(q), e;
60
60
  }
61
- const a = C();
61
+ const a = S();
62
62
  function u(n, e) {
63
63
  if (typeof e == "function")
64
64
  e(n);
@@ -66,30 +66,30 @@ function u(n, e) {
66
66
  for (let t = 0; t < e.length; t++)
67
67
  n.bind(e[t]).toSelf();
68
68
  }
69
- function D() {
70
- const n = H();
69
+ function _() {
70
+ const n = j();
71
71
  if (n) {
72
72
  const e = c, t = n.provides, r = n.parent && n.parent.provides;
73
- if (t && t !== r && k(t, e))
73
+ if (t && t !== r && A(t, e))
74
74
  return t[e];
75
75
  }
76
76
  }
77
- function S() {
78
- if (j())
79
- return N(c, a);
77
+ function g() {
78
+ if (F())
79
+ return P(c, a);
80
80
  throw new Error("getProvideContainer 只能在 setup 中使用");
81
81
  }
82
82
  function $(n) {
83
- return (D() || S()).get(n);
83
+ return (_() || g()).get(n);
84
84
  }
85
85
  function x(n) {
86
- const e = D();
86
+ const e = _();
87
87
  if (e)
88
88
  u(e, n);
89
89
  else {
90
- const t = S();
91
- let r = C(t);
92
- u(r, n), T(c, r), V(() => {
90
+ const t = g();
91
+ let r = S(t);
92
+ u(r, n), V(c, r), H(() => {
93
93
  r.destroy(), r = null;
94
94
  });
95
95
  }
@@ -101,15 +101,15 @@ function ne(n) {
101
101
  u(a, n);
102
102
  }
103
103
  function te(n, e) {
104
- return e.runWithContext(() => S().get(n));
104
+ return e.runWithContext(() => g().get(n));
105
105
  }
106
106
  function Q(n, e) {
107
107
  e.runWithContext(() => {
108
- const t = N(c, null);
108
+ const t = P(c, null);
109
109
  if (t)
110
110
  u(t, n);
111
111
  else {
112
- let r = C(a);
112
+ let r = S(a);
113
113
  u(r, n), e.provide(c, r), e.onUnmount(() => {
114
114
  r.destroy(), r = null;
115
115
  });
@@ -119,11 +119,11 @@ function Q(n, e) {
119
119
  function re(n) {
120
120
  return (e) => Q(n, e);
121
121
  }
122
- function I(n, e) {
122
+ function O(n, e) {
123
123
  const t = e.name;
124
124
  return function() {
125
- const r = b(this), o = n, g = F(this);
126
- let l, s = Object.getPrototypeOf(g);
125
+ const r = D(this), o = n, m = p(this);
126
+ let l, s = Object.getPrototypeOf(m);
127
127
  for (; s; ) {
128
128
  const i = Object.getOwnPropertyDescriptor(s, t);
129
129
  if (i && i.set) {
@@ -132,34 +132,34 @@ function I(n, e) {
132
132
  }
133
133
  s = Object.getPrototypeOf(s);
134
134
  }
135
- const d = this, m = l ? r.run(
136
- () => E({
135
+ const d = this, E = l ? r.run(
136
+ () => I({
137
137
  get: () => o.call(d),
138
138
  set: (i) => l.call(d, i)
139
139
  })
140
- ) : r.run(() => E(() => o.call(d)));
141
- return Object.defineProperty(g, t, {
142
- value: m,
140
+ ) : r.run(() => I(() => o.call(d)));
141
+ return Object.defineProperty(m, t, {
142
+ value: E,
143
143
  writable: !0,
144
144
  configurable: !0,
145
145
  enumerable: !0
146
- }), m.value;
146
+ }), E.value;
147
147
  };
148
148
  }
149
149
  function oe(n, e) {
150
- return typeof n == "function" && (e == null ? void 0 : e.kind) === "getter" ? I(n, e) : I;
150
+ return typeof n == "function" && (e == null ? void 0 : e.kind) === "getter" ? O(n, e) : O;
151
151
  }
152
152
  function f(n) {
153
- return R(n) ? K(n) : n;
153
+ return w(n) ? K(n) : n;
154
154
  }
155
- function O(n, e) {
155
+ function v(n, e) {
156
156
  if (e.kind === "accessor")
157
157
  return {
158
158
  get() {
159
- return n.get.call(this);
159
+ return n.get.call(p(this));
160
160
  },
161
161
  set(r) {
162
- n.set.call(this, f(r));
162
+ n.set.call(p(this), f(r));
163
163
  },
164
164
  init: f
165
165
  };
@@ -179,16 +179,16 @@ function O(n, e) {
179
179
  }), f;
180
180
  }
181
181
  function ie(n, e) {
182
- return (e == null ? void 0 : e.kind) === "field" || (e == null ? void 0 : e.kind) === "accessor" ? O(n, e) : O;
182
+ return (e == null ? void 0 : e.kind) === "field" || (e == null ? void 0 : e.kind) === "accessor" ? v(n, e) : v;
183
183
  }
184
- function v(n, e) {
184
+ function y(n, e) {
185
185
  return function(...t) {
186
- const o = b(this).run(() => w());
186
+ const o = D(this).run(() => N());
187
187
  return o.run(() => n.call(this, ...t)), o;
188
188
  };
189
189
  }
190
190
  function ce(n, e) {
191
- return typeof n == "function" && (e == null ? void 0 : e.kind) === "method" ? v(n) : v;
191
+ return typeof n == "function" && (e == null ? void 0 : e.kind) === "method" ? y(n) : y;
192
192
  }
193
193
  export {
194
194
  oe as Computed,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaokei/use-vue-service",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
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",