ivue 0.1.7 → 0.1.9
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.es.js +4 -4
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/ivue.ts +5 -5
- package/src/kernel.ts +3 -3
package/dist/index.es.js
CHANGED
|
@@ -151,7 +151,7 @@ function $(t2, e2, n2, r2, o2, i2, s2) {
|
|
|
151
151
|
function D(t2, ...s2) {
|
|
152
152
|
let u2 = e(), c2 = n(!!u2), a2 = P(t2.prototype), f2 = a2.size ? {} : null, l2 = new Proxy(r(new t2(...s2)), { get: (t3, e2) => {
|
|
153
153
|
var _a, _b;
|
|
154
|
-
return a2.has(e2) && ((_b = (_a = l2.constructor) == null ? void 0 : _a.behavior) == null ? void 0 : _b[e2]) !== R.OFF ? (e2 in f2 || (c2 == null ? void 0 : c2.run(() => f2[e2] = o(() => a2.get(e2).get.bind(l2)()))), f2[e2].value) : "toRefs" === e2 ? W(l2, a2, f2, c2) : t3[e2];
|
|
154
|
+
return a2.has(e2) && ((_b = (_a = l2 == null ? void 0 : l2.constructor) == null ? void 0 : _a.behavior) == null ? void 0 : _b[e2]) !== R.OFF ? (e2 in f2 || (c2 == null ? void 0 : c2.run(() => f2[e2] = o(() => a2.get(e2).get.bind(l2)()))), f2[e2].value) : "toRefs" === e2 ? W(l2, a2, f2, c2) : t3 == null ? void 0 : t3[e2];
|
|
155
155
|
} });
|
|
156
156
|
return "init" in l2 && c2.run(() => l2.init()), u2 && i(() => {
|
|
157
157
|
let t3;
|
|
@@ -181,10 +181,10 @@ function x(t2) {
|
|
|
181
181
|
function A(t2, e2, n2, r2) {
|
|
182
182
|
return new Proxy(t2, { get: (i2, s2) => {
|
|
183
183
|
var _a, _b;
|
|
184
|
-
return e2.has(s2) && ((_b = (_a = t2.constructor) == null ? void 0 : _a.behavior) == null ? void 0 : _b[s2]) !== R.OFF ? (s2 in n2 || (r2 == null ? void 0 : r2.run(() => n2[s2] = o(() => {
|
|
184
|
+
return e2.has(s2) && ((_b = (_a = t2 == null ? void 0 : t2.constructor) == null ? void 0 : _a.behavior) == null ? void 0 : _b[s2]) !== R.OFF ? (s2 in n2 || (r2 == null ? void 0 : r2.run(() => n2[s2] = o(() => {
|
|
185
185
|
var _a2;
|
|
186
186
|
return (_a2 = e2.get(s2)) == null ? void 0 : _a2.get.bind(t2)();
|
|
187
|
-
}))), n2[s2].value) : "toRefs" === s2 ? W(t2, e2, n2, r2) : i2[s2];
|
|
187
|
+
}))), n2[s2].value) : "toRefs" === s2 ? W(t2, e2, n2, r2) : i2 == null ? void 0 : i2[s2];
|
|
188
188
|
} });
|
|
189
189
|
}
|
|
190
190
|
function W(t2, e2, n2, r2) {
|
|
@@ -330,7 +330,7 @@ class U {
|
|
|
330
330
|
f2 = b2.size ? {} : null;
|
|
331
331
|
let g2 = new Proxy(r(new s2(...u2)), { get: (t2, e2) => {
|
|
332
332
|
var _a, _b;
|
|
333
|
-
return b2.has(e2) && ((_b = (_a = g2.constructor) == null ? void 0 : _a.behavior) == null ? void 0 : _b[e2]) !== R.OFF ? (e2 in f2 || (p2 == null ? void 0 : p2.run(() => f2[e2] = o(() => b2.get(e2).get.bind(g2)()))), f2[e2].value) : "toRefs" === e2 ? W(g2, b2, f2, p2) : t2[e2];
|
|
333
|
+
return b2.has(e2) && ((_b = (_a = g2 == null ? void 0 : g2.constructor) == null ? void 0 : _a.behavior) == null ? void 0 : _b[e2]) !== R.OFF ? (e2 in f2 || (p2 == null ? void 0 : p2.run(() => f2[e2] = o(() => b2.get(e2).get.bind(g2)()))), f2[e2].value) : "toRefs" === e2 ? W(g2, b2, f2, p2) : t2 == null ? void 0 : t2[e2];
|
|
334
334
|
} });
|
|
335
335
|
if ("behavior" in g2.constructor) {
|
|
336
336
|
for (const e2 in g2.constructor.behavior)
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __defProp=Object.defineProperty,__defNormalProp=(e,t,n)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__publicField=(e,t,n)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,n),n);!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ivue={},e.Vue)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&!Array.isArray(e)}function r(e,...t){return o(e,[...t],new WeakMap)}function o(e,t,r=null){if(!t.length)return e;r.set(e,!0);const i=t.shift();if(n(e)&&n(i))for(const u in i)n(i[u])&&"Object"===i[u].constructor.name?r.has(i[u])||null!==(s=i[u])&&"object"==typeof s&&"function"==typeof s.then&&"function"==typeof s.catch||void 0===e[u]?e[u]=i[u]:n(e[u])&&e[u].constructor===Object?o(e[u],[i[u]],r):e[u]=i[u]:e[u]=i[u];var s;return o(e,t,r)}function i(e,t){const n={},r=Object.getOwnPropertyNames(e.prototype).reduce(((t,r)=>{const o=Object.getOwnPropertyDescriptor(e.prototype,r);let i=!1;return(null==o?void 0:o.set)&&!(null==o?void 0:o.get)&&(n[r]=null==o?void 0:o.set,i=!0),i||(t[r]=!0),t}),{}),o={};t.reverse().forEach((t=>{const i=new t(e);for(const n in i)n in r||(o[n]=!0),n in o&&Object.defineProperty(e.prototype,n,{value:i[n],writable:!0});Object.getOwnPropertyNames(t.prototype).forEach((i=>{if("constructor"!==i&&(i in r||(o[i]=!0),i in o)){const r=Object.getOwnPropertyDescriptor(t.prototype,i)||Object.create(null);(null==r?void 0:r.set)&&!(i in n)&&(n[i]=null==r?void 0:r.set),(null==r?void 0:r.get)&&!(null==r?void 0:r.set)&&i in n&&(r.set=n[i]),Object.defineProperty(e.prototype,i,r)}}))}))}const s=new Map;function u(e){if(s.has(e))return s.get(e);const t=e,n=[];n.push.apply(n,Object.entries(Object.getOwnPropertyDescriptors(e)));const r=new Map;for(let o=0;o<n.length;o++)"__proto__"!==n[o][0]&&"function"==typeof n[o][1].get&&r.set(n[o][0],n[o][1]);return s.set(t,r),r}function c(e){let t="";try{t=(null==e?void 0:e.name)||String(e)}catch(n){t="Unknown[failed to convert to string]"}return t}let l={router:null,debug:!1};const a={before:new Map,after:new Map};function f(e,t,n){const r=a[e].get(t);for(let o=0;o<(null==r?void 0:r.length);o++)if(!0===r[o](n,...n.args))return n.return}function p(e,t,n,r){var o;a[e].has(t)?null==(o=a[e].get(t))||o[r.top?"unshift":"push"](n):a[e].set(t,[n])}function h(e,t){var n;if(Array.isArray(e)){if("function"!=typeof e[0])throw new Error("ivue.kernel.behavior: Cannot autobind intercept to "+e[0]+". Supply a valid Class to autobind behavior.");if("function"==typeof e[1]){const n=e[1].toString();if("class"!==n.substring(0,5)){const r=n.indexOf("(");n.substring(0,r).split(" "),e[0].behavior={..."object"==typeof e[0].behavior?e[0].behavior:{},funcName:t?"SCOPED_INTERCEPT":"INTERCEPT"}}return e[1]}throw new Error('ivue.kernel.behavior: Cannot autobind intercept "'+e[1]+'" to '+((null==(n=e[0])?void 0:n.name)??e[0]))}return e}function b(e,t,n={top:!1,scoped:!1}){p("after",h(e,n.scoped),t,n)}function d(e,t,n,r,o){let i=a[e].get(t.constructor.prototype[n]);for(let s=0;s<(null==i?void 0:i.length);s++)if(!0===i[s](o,...r))return!0;i=a[e].get(t[n]);for(let s=0;s<(null==i?void 0:i.length);s++)if(!0===i[s](o,...r))return!0}var g,v=((g=v||{}).SCOPED="SCOPED",g.SCOPED_INTERCEPT="SCOPED_INTERCEPT",g.INTERCEPT="INTERCEPT",g.OFF="OFF",g);function m(e,t,n,r,o,i,s){let u;if("SCOPED"===t)return Object.defineProperty(r,o,{value:function(...e){return i.run((()=>u=n.bind(r)(...e))),u},writable:!0,configurable:!0,enumerable:!1});const c=(...t)=>(!0===d("before",r,o,t,s={mapping:e,self:r,return:u,name:o,args:t})||(u=n.bind(r)(...t),s.return=u,d("after",r,o,t,s)),s.return);switch(t){case"INTERCEPT":return Object.defineProperty(r,o,{value:function(...e){return c(...e)},writable:!0,configurable:!0,enumerable:!1});case"SCOPED_INTERCEPT":return Object.defineProperty(r,o,{value:function(...e){return i.run((()=>u=c(...e))),u},writable:!0,configurable:!0,enumerable:!1})}}function y(e,n,r,o){return new Proxy(e,{get:(i,s)=>{var u,c;return n.has(s)&&(null==(c=null==(u=e.constructor)?void 0:u.behavior)?void 0:c[s])!==v.OFF?(s in r||(null==o||o.run((()=>r[s]=t.computed((()=>{var t;return null==(t=n.get(s))?void 0:t.get.bind(e)()}))))),r[s].value):"toRefs"===s?_(e,n,r,o):i[s]}})}function _(e,n,r,o){return function(i){const s={};if(Array.isArray(i)&&i.length)for(let u=0;u<i.length;u++){const c=i[u];n.has(c)?c in r?s[c]=r[c]:o.run((()=>s[c]=r[c]=t.computed((()=>{var t;return null==(t=n.get(c))?void 0:t.get.bind(e)()})))):"function"==typeof e[c]?s[c]=e[c].bind(e):s[c]=t.toRef(e,c)}else{for(const r in e)n.has(r)||("function"==typeof e[r]?s[r]=e[r].bind(e):s[r]=t.toRef(e,r));n.forEach(((n,i)=>{i in r?s[i]=r[i]:o.run((()=>s[i]=r[i]=t.computed((()=>n.get.bind(e)()))))}))}return new Proxy(e,{get:(t,n)=>n in s?s[n]:n in t?t[n].bind(e):void 0})}}const w=e=>{let n=t.toRaw(e),r=Object.getOwnPropertyNames(n);for(let t=0;t<r.length;t++)delete n[r[t]];n=null,r=null};class O{constructor(e){__publicField(this,"to"),__publicField(this,"scope","singleton"),__publicField(this,"type","generic"),__publicField(this,"onInit",S),this.from=e,this.to=e}}class F{constructor(){__publicField(this,"transients",new WeakMap),__publicField(this,"singletons",new WeakMap),__publicField(this,"instances",new WeakMap),__publicField(this,"subscribers",new WeakMap),__publicField(this,"effectScopes",new WeakMap),__publicField(this,"current")}bind(e){return this.current=new O(e),this}to(e){return this.current.to=e,this}singleton(){return this.current.scope="singleton",this[this.current.scope+"s"].set(this.current.from,this.current),this}transient(){return this.current.scope="transient",this[this.current.scope+"s"].set(this.current.from,this.current),this}type(e){return this.current.type=e,this}ivue(){return this.current.type="ivue",this.current.onInit=()=>{},this}onInit(e){return this.current.onInit=e,this}get(e,...t){if(this.instances.has(e))return this.instances.get(e);let n=this.singletons.get(e);n||(this.bind(e).singleton(),n=this.singletons.get(e));const r=n.onInit(n,...t);return this.instances.set(e,r),r}make(e,...t){let n=this.transients.get(e);return n||(this.bind(e).transient(),n=this.transients.get(e)),n.onInit(n,...t)}use(e,...r){let o,i,s,p,h,b,d,g=t.getCurrentScope();if(console.log("className",e.name),this.subscribers.set(e,(this.subscribers.get(e)||0)+1),g&&t.onScopeDispose((()=>{var t;const n=(this.subscribers.get(e)||0)-1;if(this.subscribers.set(e,n),this.effectScopes.has(e)&&n<=0){let n;if(null==(t=this.effectScopes.get(e))||t.stop(),s)for(n in s)delete s[n];if(h)for(n in h)delete h[n];if(b)for(n in b)delete b[n];if(d)for(n in d)delete d[n];s&&w(s),g=o=i=s=h=b=d=n=null,this.effectScopes.delete(e),this.instances.delete(e),this.subscribers.delete(e),l.debug&&console.log("ivue.kernel: instance deleted:",e.name)}})),this.instances.has(e))return this.instances.get(e);{if(i=this.singletons.get(e),i){if("ivue"!==i.type)throw new Error("ivue.kernel: use("+c(e)+") method should be used only with 'ivue' mappings, use get("+c(e)+") method for standard JavaScript singleton Kernel mappings.")}else this.bind(e).singleton().ivue(),i=this.singletons.get(e);if(o=t.effectScope(!!g),this.effectScopes.set(e,o),a.before.has(i.to)&&(b={mapping:i,self:null,return:null,name:i.to.constructor.name,args:r},!0===f("before",i.to,b)))return this.instances.set(e,b.return),b.return;p=u(i.to.prototype),h=p.size?{}:null;let s=new Proxy(t.reactive(new e(...r)),{get:(e,n)=>{var r,i;return p.has(n)&&(null==(i=null==(r=s.constructor)?void 0:r.behavior)?void 0:i[n])!==v.OFF?(n in h||(null==o||o.run((()=>h[n]=t.computed((()=>p.get(n).get.bind(s)()))))),h[n].value):"toRefs"===n?_(s,p,h,o):e[n]}});if("behavior"in s.constructor)for(const e in s.constructor.behavior)if(!p.has(e))if("function"==typeof s[e]){if(s.constructor.behavior[e]===v.OFF)continue;n(d)||(d={}),d[e]=s[e],m(i,s.constructor.behavior[e],d[e],s,e,o,b)}else s.constructor.behavior[e]===v.OFF&&(null==s?void 0:s[e])&&"object"==typeof s[e]&&(s[e]=t.markRaw(s[e]));return a.after.has(i.to)&&(b={mapping:i,self:s,name:i.to.constructor.name,return:s,args:r},!0===f("after",i.to,b))?(this.instances.set(e,b.return),b.return):("init"in s&&o.run((()=>s.init())),this.instances.set(e,s),l.debug&&console.log("ivue.kernel: instance created:",e.name,"current scope",t.getCurrentScope(),"current instance",t.getCurrentInstance()),s)}}init(e,...r){let o=this.transients.get(e);if(o){if("ivue"!==o.type)throw new Error("ivue.kernel: init("+c(e)+") method should be used only with 'ivue' mappings, use make("+c(e)+") method for standard JavaScript transient Kernel mappings.")}else this.bind(e).transient().ivue(),o=this.transients.get(e);let i,s,l,p=t.getCurrentScope(),h=t.effectScope(!!p);if(a.before.has(o.to)&&(i={mapping:o,self:null,return:null,name:o.to.constructor.name,args:r},!0===f("before",o.to,i)))return i.return;let b=u(o.to.prototype);s=b.size?{}:null;let d=new Proxy(t.reactive(new e(...r)),{get:(e,n)=>{var r,o;return b.has(n)&&(null==(o=null==(r=d.constructor)?void 0:r.behavior)?void 0:o[n])!==v.OFF?(n in s||(null==h||h.run((()=>s[n]=t.computed((()=>b.get(n).get.bind(d)()))))),s[n].value):"toRefs"===n?_(d,b,s,h):e[n]}});if("behavior"in d.constructor)for(const u in d.constructor.behavior)if(!b.has(u))if("function"==typeof d[u]){if(d.constructor.behavior[u]===v.OFF)continue;n(l)||(l={}),l[u]=d[u],m(o,d.constructor.behavior[u],l[u],d,u,h,i)}else d.constructor.behavior[u]===v.OFF&&(null==d?void 0:d[u])&&"object"==typeof d[u]&&(d[u]=t.markRaw(d[u]));return a.after.has(o.to)&&(i={mapping:o,self:d,return:d,name:o.to.constructor.name,args:r},!0===f("after",o.to,i))?i.return:("init"in d&&h.run((()=>d.init())),p&&t.onScopeDispose((()=>{let e;if(null==h||h.stop(),w(d),i)for(e in i)delete i[e];if(s)for(e in s)delete s[e];if(l)for(e in l)delete l[e];p=h=d=o=s=i=l=e=null})),d)}}function S(e,...r){if(a.before.has(e.to)){const t={mapping:e,self:null,return:null,name:e.to.constructor.name,args:r};if(!0===f("before",e.to,t))return t.return}let o,i=new e.to(...r);const s=u(e.to.prototype);if("behavior"in i.constructor&&"object"==typeof i.constructor.behavior)for(const u in i.constructor.behavior)if(!s.has(u)&&"function"==typeof i[u]){if(i.constructor.behavior[u]===v.OFF)continue;n(o)||(o={}),o[u]=i[u],m(e,i.constructor.behavior[u],o[u],i,u,t.effectScope(!!t.getCurrentScope()),void 0)}if(a.after.has(e.to)){const t={mapping:e,self:i,return:i,name:e.to.constructor.name,args:r};if(!0===f("after",e.to,t))return t.return}return i}const P=new F,C=P.bind.bind(P),E=P.get.bind(P),j=P.make.bind(P),k=P.use.bind(P),R=P.init.bind(P);function T(e,t){e.behavior=r(e.behavior??{},{$instance:v.OFF})}class I{get $instance(){return t.getCurrentInstance()}constructor(e){T(e)}}function M(e,n){b(e,(({self:e})=>{"beforeMount"in e&&t.onBeforeMount((()=>e.beforeMount())),"mounted"in e&&t.onMounted((()=>e.mounted())),"beforeUnmount"in e&&t.onBeforeUnmount((()=>e.beforeUnmount())),"unmounted"in e&&t.onUnmounted((()=>e.unmounted()))}))}class N{constructor(e){__publicField(this,"beforeMount",(function(){})),__publicField(this,"mounted",(function(){})),__publicField(this,"beforeUnmount",(function(){})),__publicField(this,"unmounted",(function(){})),M(e)}}function U(e,t){e.behavior=r(e.behavior??{},{$refs:v.OFF})}class D{get $refs(){var e;return null==(e=t.getCurrentInstance())?void 0:e.refs}constructor(e){U(e)}}class ${get route(){var e;return t.toValue(null==(e=l.router)?void 0:e.currentRoute)}}class x{get router(){return l.router}}class A{}i(A,[x,$]);class W{constructor(){__publicField(this,"$emit",((...e)=>{}))}}class J{constructor(){__publicField(this,"$nextTick",t.nextTick)}}class z{constructor(e){var t;T(t=e),U(t),M(t)}}i(z,[A,N,W,J,D,I]),e.IVUE=v,e.Kernel=F,e.Mapping=O,e.Traits=i,e.UseCapsule=class{constructor(){__publicField(this,"$"),__publicField(this,"capsule")}useCapsule(e=[]){this.$=k(this.capsule,this,...e),t.markRaw(this.$)}initCapsule(e=[]){this.$=R(this.capsule,this,...e),t.markRaw(this.$)}getCapsule(e=[]){this.$=E(this.capsule,this,...e)}makeCapsule(e=[]){this.$=j(this.capsule,this,...e)}},e.UseEmit=W,e.UseInstance=I,e.UseMounting=N,e.UseRefs=D,e.UseRoute=$,e.UseRouter=x,e.UseRouting=A,e.UseTick=J,e.UseVue=z,e.after=b,e.before=function(e,t,n={top:!1,scoped:!1}){p("before",h(e,n.scoped),t,n)},e.bind=C,e.config=l,e.extend=r,e.get=E,e.init=R,e.iobj=function(e){let n=t.getCurrentScope(),r=t.effectScope(!!n),o=function(e){const t=new Map,n=Object.entries(Object.getOwnPropertyDescriptors(e));for(let r=0;r<n.length;r++)"function"==typeof n[r][1].get&&"__proto__"!==n[r][0]&&t.set(n[r][0],n[r][1]);return t}(e),i=o.size?{}:null,s=y(t.reactive(e),o,i,r);return"init"in s&&r.run((()=>s.init())),n&&t.onScopeDispose((()=>{let t;for(t in null==r||r.stop(),s)delete s[t];for(t in i)delete i[t];n=r=o=i=e=s=t=null})),s},e.ivue=function(e,...n){let r=t.getCurrentScope(),o=t.effectScope(!!r),i=u(e.prototype),s=i.size?{}:null,c=new Proxy(t.reactive(new e(...n)),{get:(e,n)=>{var r,u;return i.has(n)&&(null==(u=null==(r=c.constructor)?void 0:r.behavior)?void 0:u[n])!==v.OFF?(n in s||(null==o||o.run((()=>s[n]=t.computed((()=>i.get(n).get.bind(c)()))))),s[n].value):"toRefs"===n?_(c,i,s,o):e[n]}});return"init"in c&&o.run((()=>c.init())),r&&t.onScopeDispose((()=>{let e;for(e in null==o||o.stop(),c)delete c[e];for(e in s)delete s[e];r=o=i=s=c=e=null})),c},e.ivueInversify=function(e,n,...r){let o=t.effectScope(!!t.getCurrentScope()),i=u(Reflect.getPrototypeOf(n)),s=i.value?{}:null,c=y(t.reactive(Object.create(n)),i,s,o);var l;return"function"==typeof c.init&&o.run((()=>c.init())),l=()=>{null==o||o.stop(),w(c),o=c=null},t.getCurrentScope()&&t.onScopeDispose(l),c},e.ivueTransform=y,e.kernel=P,e.make=j,e.pre=function(e,t=2){const n=new Set;return JSON.stringify(e,(function(e,t){if("object"==typeof t&&null!==t){if(n.has(t))try{return JSON.parse(JSON.stringify(t))}catch(r){return"[**circular**]"}n.add(t)}return t}),t)},e.raw=function(e){return t.markRaw(e)},e.setup=function(e={}){r(l,e)},e.unraw=function(e){delete e.__v_skip},e.use=k,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
var __defProp=Object.defineProperty,__defNormalProp=(e,t,n)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__publicField=(e,t,n)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,n),n);!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ivue={},e.Vue)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&!Array.isArray(e)}function r(e,...t){return o(e,[...t],new WeakMap)}function o(e,t,r=null){if(!t.length)return e;r.set(e,!0);const i=t.shift();if(n(e)&&n(i))for(const u in i)n(i[u])&&"Object"===i[u].constructor.name?r.has(i[u])||null!==(s=i[u])&&"object"==typeof s&&"function"==typeof s.then&&"function"==typeof s.catch||void 0===e[u]?e[u]=i[u]:n(e[u])&&e[u].constructor===Object?o(e[u],[i[u]],r):e[u]=i[u]:e[u]=i[u];var s;return o(e,t,r)}function i(e,t){const n={},r=Object.getOwnPropertyNames(e.prototype).reduce(((t,r)=>{const o=Object.getOwnPropertyDescriptor(e.prototype,r);let i=!1;return(null==o?void 0:o.set)&&!(null==o?void 0:o.get)&&(n[r]=null==o?void 0:o.set,i=!0),i||(t[r]=!0),t}),{}),o={};t.reverse().forEach((t=>{const i=new t(e);for(const n in i)n in r||(o[n]=!0),n in o&&Object.defineProperty(e.prototype,n,{value:i[n],writable:!0});Object.getOwnPropertyNames(t.prototype).forEach((i=>{if("constructor"!==i&&(i in r||(o[i]=!0),i in o)){const r=Object.getOwnPropertyDescriptor(t.prototype,i)||Object.create(null);(null==r?void 0:r.set)&&!(i in n)&&(n[i]=null==r?void 0:r.set),(null==r?void 0:r.get)&&!(null==r?void 0:r.set)&&i in n&&(r.set=n[i]),Object.defineProperty(e.prototype,i,r)}}))}))}const s=new Map;function u(e){if(s.has(e))return s.get(e);const t=e,n=[];n.push.apply(n,Object.entries(Object.getOwnPropertyDescriptors(e)));const r=new Map;for(let o=0;o<n.length;o++)"__proto__"!==n[o][0]&&"function"==typeof n[o][1].get&&r.set(n[o][0],n[o][1]);return s.set(t,r),r}function c(e){let t="";try{t=(null==e?void 0:e.name)||String(e)}catch(n){t="Unknown[failed to convert to string]"}return t}let l={router:null,debug:!1};const a={before:new Map,after:new Map};function f(e,t,n){const r=a[e].get(t);for(let o=0;o<(null==r?void 0:r.length);o++)if(!0===r[o](n,...n.args))return n.return}function p(e,t,n,r){var o;a[e].has(t)?null==(o=a[e].get(t))||o[r.top?"unshift":"push"](n):a[e].set(t,[n])}function h(e,t){var n;if(Array.isArray(e)){if("function"!=typeof e[0])throw new Error("ivue.kernel.behavior: Cannot autobind intercept to "+e[0]+". Supply a valid Class to autobind behavior.");if("function"==typeof e[1]){const n=e[1].toString();if("class"!==n.substring(0,5)){const r=n.indexOf("(");n.substring(0,r).split(" "),e[0].behavior={..."object"==typeof e[0].behavior?e[0].behavior:{},funcName:t?"SCOPED_INTERCEPT":"INTERCEPT"}}return e[1]}throw new Error('ivue.kernel.behavior: Cannot autobind intercept "'+e[1]+'" to '+((null==(n=e[0])?void 0:n.name)??e[0]))}return e}function d(e,t,n={top:!1,scoped:!1}){p("after",h(e,n.scoped),t,n)}function b(e,t,n,r,o){let i=a[e].get(t.constructor.prototype[n]);for(let s=0;s<(null==i?void 0:i.length);s++)if(!0===i[s](o,...r))return!0;i=a[e].get(t[n]);for(let s=0;s<(null==i?void 0:i.length);s++)if(!0===i[s](o,...r))return!0}var g,v=((g=v||{}).SCOPED="SCOPED",g.SCOPED_INTERCEPT="SCOPED_INTERCEPT",g.INTERCEPT="INTERCEPT",g.OFF="OFF",g);function m(e,t,n,r,o,i,s){let u;if("SCOPED"===t)return Object.defineProperty(r,o,{value:function(...e){return i.run((()=>u=n.bind(r)(...e))),u},writable:!0,configurable:!0,enumerable:!1});const c=(...t)=>(!0===b("before",r,o,t,s={mapping:e,self:r,return:u,name:o,args:t})||(u=n.bind(r)(...t),s.return=u,b("after",r,o,t,s)),s.return);switch(t){case"INTERCEPT":return Object.defineProperty(r,o,{value:function(...e){return c(...e)},writable:!0,configurable:!0,enumerable:!1});case"SCOPED_INTERCEPT":return Object.defineProperty(r,o,{value:function(...e){return i.run((()=>u=c(...e))),u},writable:!0,configurable:!0,enumerable:!1})}}function y(e,n,r,o){return new Proxy(e,{get:(i,s)=>{var u,c;return n.has(s)&&(null==(c=null==(u=null==e?void 0:e.constructor)?void 0:u.behavior)?void 0:c[s])!==v.OFF?(s in r||(null==o||o.run((()=>r[s]=t.computed((()=>{var t;return null==(t=n.get(s))?void 0:t.get.bind(e)()}))))),r[s].value):"toRefs"===s?_(e,n,r,o):null==i?void 0:i[s]}})}function _(e,n,r,o){return function(i){const s={};if(Array.isArray(i)&&i.length)for(let u=0;u<i.length;u++){const c=i[u];n.has(c)?c in r?s[c]=r[c]:o.run((()=>s[c]=r[c]=t.computed((()=>{var t;return null==(t=n.get(c))?void 0:t.get.bind(e)()})))):"function"==typeof e[c]?s[c]=e[c].bind(e):s[c]=t.toRef(e,c)}else{for(const r in e)n.has(r)||("function"==typeof e[r]?s[r]=e[r].bind(e):s[r]=t.toRef(e,r));n.forEach(((n,i)=>{i in r?s[i]=r[i]:o.run((()=>s[i]=r[i]=t.computed((()=>n.get.bind(e)()))))}))}return new Proxy(e,{get:(t,n)=>n in s?s[n]:n in t?t[n].bind(e):void 0})}}const w=e=>{let n=t.toRaw(e),r=Object.getOwnPropertyNames(n);for(let t=0;t<r.length;t++)delete n[r[t]];n=null,r=null};class O{constructor(e){__publicField(this,"to"),__publicField(this,"scope","singleton"),__publicField(this,"type","generic"),__publicField(this,"onInit",S),this.from=e,this.to=e}}class F{constructor(){__publicField(this,"transients",new WeakMap),__publicField(this,"singletons",new WeakMap),__publicField(this,"instances",new WeakMap),__publicField(this,"subscribers",new WeakMap),__publicField(this,"effectScopes",new WeakMap),__publicField(this,"current")}bind(e){return this.current=new O(e),this}to(e){return this.current.to=e,this}singleton(){return this.current.scope="singleton",this[this.current.scope+"s"].set(this.current.from,this.current),this}transient(){return this.current.scope="transient",this[this.current.scope+"s"].set(this.current.from,this.current),this}type(e){return this.current.type=e,this}ivue(){return this.current.type="ivue",this.current.onInit=()=>{},this}onInit(e){return this.current.onInit=e,this}get(e,...t){if(this.instances.has(e))return this.instances.get(e);let n=this.singletons.get(e);n||(this.bind(e).singleton(),n=this.singletons.get(e));const r=n.onInit(n,...t);return this.instances.set(e,r),r}make(e,...t){let n=this.transients.get(e);return n||(this.bind(e).transient(),n=this.transients.get(e)),n.onInit(n,...t)}use(e,...r){let o,i,s,p,h,d,b,g=t.getCurrentScope();if(console.log("className",e.name),this.subscribers.set(e,(this.subscribers.get(e)||0)+1),g&&t.onScopeDispose((()=>{var t;const n=(this.subscribers.get(e)||0)-1;if(this.subscribers.set(e,n),this.effectScopes.has(e)&&n<=0){let n;if(null==(t=this.effectScopes.get(e))||t.stop(),s)for(n in s)delete s[n];if(h)for(n in h)delete h[n];if(d)for(n in d)delete d[n];if(b)for(n in b)delete b[n];s&&w(s),g=o=i=s=h=d=b=n=null,this.effectScopes.delete(e),this.instances.delete(e),this.subscribers.delete(e),l.debug&&console.log("ivue.kernel: instance deleted:",e.name)}})),this.instances.has(e))return this.instances.get(e);{if(i=this.singletons.get(e),i){if("ivue"!==i.type)throw new Error("ivue.kernel: use("+c(e)+") method should be used only with 'ivue' mappings, use get("+c(e)+") method for standard JavaScript singleton Kernel mappings.")}else this.bind(e).singleton().ivue(),i=this.singletons.get(e);if(o=t.effectScope(!!g),this.effectScopes.set(e,o),a.before.has(i.to)&&(d={mapping:i,self:null,return:null,name:i.to.constructor.name,args:r},!0===f("before",i.to,d)))return this.instances.set(e,d.return),d.return;p=u(i.to.prototype),h=p.size?{}:null;let s=new Proxy(t.reactive(new e(...r)),{get:(e,n)=>{var r,i;return p.has(n)&&(null==(i=null==(r=s.constructor)?void 0:r.behavior)?void 0:i[n])!==v.OFF?(n in h||(null==o||o.run((()=>h[n]=t.computed((()=>p.get(n).get.bind(s)()))))),h[n].value):"toRefs"===n?_(s,p,h,o):e[n]}});if("behavior"in s.constructor)for(const e in s.constructor.behavior)if(!p.has(e))if("function"==typeof s[e]){if(s.constructor.behavior[e]===v.OFF)continue;n(b)||(b={}),b[e]=s[e],m(i,s.constructor.behavior[e],b[e],s,e,o,d)}else s.constructor.behavior[e]===v.OFF&&(null==s?void 0:s[e])&&"object"==typeof s[e]&&(s[e]=t.markRaw(s[e]));return a.after.has(i.to)&&(d={mapping:i,self:s,name:i.to.constructor.name,return:s,args:r},!0===f("after",i.to,d))?(this.instances.set(e,d.return),d.return):("init"in s&&o.run((()=>s.init())),this.instances.set(e,s),l.debug&&console.log("ivue.kernel: instance created:",e.name,"current scope",t.getCurrentScope(),"current instance",t.getCurrentInstance()),s)}}init(e,...r){let o=this.transients.get(e);if(o){if("ivue"!==o.type)throw new Error("ivue.kernel: init("+c(e)+") method should be used only with 'ivue' mappings, use make("+c(e)+") method for standard JavaScript transient Kernel mappings.")}else this.bind(e).transient().ivue(),o=this.transients.get(e);let i,s,l,p=t.getCurrentScope(),h=t.effectScope(!!p);if(a.before.has(o.to)&&(i={mapping:o,self:null,return:null,name:o.to.constructor.name,args:r},!0===f("before",o.to,i)))return i.return;let d=u(o.to.prototype);s=d.size?{}:null;let b=new Proxy(t.reactive(new e(...r)),{get:(e,n)=>{var r,o;return d.has(n)&&(null==(o=null==(r=null==b?void 0:b.constructor)?void 0:r.behavior)?void 0:o[n])!==v.OFF?(n in s||(null==h||h.run((()=>s[n]=t.computed((()=>d.get(n).get.bind(b)()))))),s[n].value):"toRefs"===n?_(b,d,s,h):null==e?void 0:e[n]}});if("behavior"in b.constructor)for(const u in b.constructor.behavior)if(!d.has(u))if("function"==typeof b[u]){if(b.constructor.behavior[u]===v.OFF)continue;n(l)||(l={}),l[u]=b[u],m(o,b.constructor.behavior[u],l[u],b,u,h,i)}else b.constructor.behavior[u]===v.OFF&&(null==b?void 0:b[u])&&"object"==typeof b[u]&&(b[u]=t.markRaw(b[u]));return a.after.has(o.to)&&(i={mapping:o,self:b,return:b,name:o.to.constructor.name,args:r},!0===f("after",o.to,i))?i.return:("init"in b&&h.run((()=>b.init())),p&&t.onScopeDispose((()=>{let e;if(null==h||h.stop(),w(b),i)for(e in i)delete i[e];if(s)for(e in s)delete s[e];if(l)for(e in l)delete l[e];p=h=b=o=s=i=l=e=null})),b)}}function S(e,...r){if(a.before.has(e.to)){const t={mapping:e,self:null,return:null,name:e.to.constructor.name,args:r};if(!0===f("before",e.to,t))return t.return}let o,i=new e.to(...r);const s=u(e.to.prototype);if("behavior"in i.constructor&&"object"==typeof i.constructor.behavior)for(const u in i.constructor.behavior)if(!s.has(u)&&"function"==typeof i[u]){if(i.constructor.behavior[u]===v.OFF)continue;n(o)||(o={}),o[u]=i[u],m(e,i.constructor.behavior[u],o[u],i,u,t.effectScope(!!t.getCurrentScope()),void 0)}if(a.after.has(e.to)){const t={mapping:e,self:i,return:i,name:e.to.constructor.name,args:r};if(!0===f("after",e.to,t))return t.return}return i}const P=new F,C=P.bind.bind(P),E=P.get.bind(P),j=P.make.bind(P),k=P.use.bind(P),R=P.init.bind(P);function T(e,t){e.behavior=r(e.behavior??{},{$instance:v.OFF})}class I{get $instance(){return t.getCurrentInstance()}constructor(e){T(e)}}function M(e,n){d(e,(({self:e})=>{"beforeMount"in e&&t.onBeforeMount((()=>e.beforeMount())),"mounted"in e&&t.onMounted((()=>e.mounted())),"beforeUnmount"in e&&t.onBeforeUnmount((()=>e.beforeUnmount())),"unmounted"in e&&t.onUnmounted((()=>e.unmounted()))}))}class N{constructor(e){__publicField(this,"beforeMount",(function(){})),__publicField(this,"mounted",(function(){})),__publicField(this,"beforeUnmount",(function(){})),__publicField(this,"unmounted",(function(){})),M(e)}}function U(e,t){e.behavior=r(e.behavior??{},{$refs:v.OFF})}class D{get $refs(){var e;return null==(e=t.getCurrentInstance())?void 0:e.refs}constructor(e){U(e)}}class ${get route(){var e;return t.toValue(null==(e=l.router)?void 0:e.currentRoute)}}class x{get router(){return l.router}}class A{}i(A,[x,$]);class W{constructor(){__publicField(this,"$emit",((...e)=>{}))}}class J{constructor(){__publicField(this,"$nextTick",t.nextTick)}}class z{constructor(e){var t;T(t=e),U(t),M(t)}}i(z,[A,N,W,J,D,I]),e.IVUE=v,e.Kernel=F,e.Mapping=O,e.Traits=i,e.UseCapsule=class{constructor(){__publicField(this,"$"),__publicField(this,"capsule")}useCapsule(e=[]){this.$=k(this.capsule,this,...e),t.markRaw(this.$)}initCapsule(e=[]){this.$=R(this.capsule,this,...e),t.markRaw(this.$)}getCapsule(e=[]){this.$=E(this.capsule,this,...e)}makeCapsule(e=[]){this.$=j(this.capsule,this,...e)}},e.UseEmit=W,e.UseInstance=I,e.UseMounting=N,e.UseRefs=D,e.UseRoute=$,e.UseRouter=x,e.UseRouting=A,e.UseTick=J,e.UseVue=z,e.after=d,e.before=function(e,t,n={top:!1,scoped:!1}){p("before",h(e,n.scoped),t,n)},e.bind=C,e.config=l,e.extend=r,e.get=E,e.init=R,e.iobj=function(e){let n=t.getCurrentScope(),r=t.effectScope(!!n),o=function(e){const t=new Map,n=Object.entries(Object.getOwnPropertyDescriptors(e));for(let r=0;r<n.length;r++)"function"==typeof n[r][1].get&&"__proto__"!==n[r][0]&&t.set(n[r][0],n[r][1]);return t}(e),i=o.size?{}:null,s=y(t.reactive(e),o,i,r);return"init"in s&&r.run((()=>s.init())),n&&t.onScopeDispose((()=>{let t;for(t in null==r||r.stop(),s)delete s[t];for(t in i)delete i[t];n=r=o=i=e=s=t=null})),s},e.ivue=function(e,...n){let r=t.getCurrentScope(),o=t.effectScope(!!r),i=u(e.prototype),s=i.size?{}:null,c=new Proxy(t.reactive(new e(...n)),{get:(e,n)=>{var r,u;return i.has(n)&&(null==(u=null==(r=null==c?void 0:c.constructor)?void 0:r.behavior)?void 0:u[n])!==v.OFF?(n in s||(null==o||o.run((()=>s[n]=t.computed((()=>i.get(n).get.bind(c)()))))),s[n].value):"toRefs"===n?_(c,i,s,o):null==e?void 0:e[n]}});return"init"in c&&o.run((()=>c.init())),r&&t.onScopeDispose((()=>{let e;for(e in null==o||o.stop(),c)delete c[e];for(e in s)delete s[e];r=o=i=s=c=e=null})),c},e.ivueInversify=function(e,n,...r){let o=t.effectScope(!!t.getCurrentScope()),i=u(Reflect.getPrototypeOf(n)),s=i.value?{}:null,c=y(t.reactive(Object.create(n)),i,s,o);var l;return"function"==typeof c.init&&o.run((()=>c.init())),l=()=>{null==o||o.stop(),w(c),o=c=null},t.getCurrentScope()&&t.onScopeDispose(l),c},e.ivueTransform=y,e.kernel=P,e.make=j,e.pre=function(e,t=2){const n=new Set;return JSON.stringify(e,(function(e,t){if("object"==typeof t&&null!==t){if(n.has(t))try{return JSON.parse(JSON.stringify(t))}catch(r){return"[**circular**]"}n.add(t)}return t}),t)},e.raw=function(e){return t.markRaw(e)},e.setup=function(e={}){r(l,e)},e.unraw=function(e){delete e.__v_skip},e.use=k,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
package/src/ivue.ts
CHANGED
|
@@ -32,13 +32,13 @@ export function ivue<T extends AnyClass> (className: T, ...args: InferredArgs<T>
|
|
|
32
32
|
*/
|
|
33
33
|
// @ts-ignore
|
|
34
34
|
let vue = new Proxy(reactive(new className(...args)), {
|
|
35
|
-
get (target, prop) {
|
|
35
|
+
get (target, prop): any {
|
|
36
36
|
/**
|
|
37
37
|
* Is the prop a getter?
|
|
38
38
|
*/
|
|
39
39
|
if (
|
|
40
40
|
getters.has(prop) // Prop is a getter
|
|
41
|
-
&& vue
|
|
41
|
+
&& vue?.constructor?.behavior?.[prop] !== IVUE.OFF // Prop is not disabled
|
|
42
42
|
) {
|
|
43
43
|
/**
|
|
44
44
|
* Convert getters to computeds lazily.
|
|
@@ -68,7 +68,7 @@ export function ivue<T extends AnyClass> (className: T, ...args: InferredArgs<T>
|
|
|
68
68
|
/**
|
|
69
69
|
* Return the default reactive vue prop.
|
|
70
70
|
*/
|
|
71
|
-
return target[prop]
|
|
71
|
+
return target?.[prop]
|
|
72
72
|
}
|
|
73
73
|
})
|
|
74
74
|
/**
|
|
@@ -151,7 +151,7 @@ export function ivueTransform<T extends AnyClass>(vue: any, getters: Getters, co
|
|
|
151
151
|
*/
|
|
152
152
|
if (
|
|
153
153
|
getters.has(prop) // Prop is a getter
|
|
154
|
-
&& vue
|
|
154
|
+
&& vue?.constructor?.behavior?.[prop] !== IVUE.OFF // Prop is not disabled
|
|
155
155
|
) {
|
|
156
156
|
/**
|
|
157
157
|
* Convert getters to computeds lazily.
|
|
@@ -181,7 +181,7 @@ export function ivueTransform<T extends AnyClass>(vue: any, getters: Getters, co
|
|
|
181
181
|
/**
|
|
182
182
|
* Return the default reactive vue prop.
|
|
183
183
|
*/
|
|
184
|
-
return target[prop]
|
|
184
|
+
return target?.[prop]
|
|
185
185
|
}
|
|
186
186
|
})
|
|
187
187
|
}
|
package/src/kernel.ts
CHANGED
|
@@ -569,13 +569,13 @@ export class Kernel {
|
|
|
569
569
|
*/
|
|
570
570
|
// @ts-ignore
|
|
571
571
|
let vue = new Proxy(reactive(new className(...args)), {
|
|
572
|
-
get (target, prop) {
|
|
572
|
+
get (target, prop): any {
|
|
573
573
|
/**
|
|
574
574
|
* Convert getters to computeds lazily.
|
|
575
575
|
*/
|
|
576
576
|
if (
|
|
577
577
|
getters.has(prop) // Prop is a getter
|
|
578
|
-
&& vue
|
|
578
|
+
&& vue?.constructor?.behavior?.[prop] !== IVUE.OFF // Prop is not disabled
|
|
579
579
|
) {
|
|
580
580
|
if (prop in computeds) {
|
|
581
581
|
/**
|
|
@@ -602,7 +602,7 @@ export class Kernel {
|
|
|
602
602
|
/**
|
|
603
603
|
* Return default reactive vue prop.
|
|
604
604
|
*/
|
|
605
|
-
return target[prop]
|
|
605
|
+
return target?.[prop]
|
|
606
606
|
}
|
|
607
607
|
})
|
|
608
608
|
/**
|