ivue 0.1.1 → 0.1.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/.idea/modules.xml +1 -1
- package/PLAN.md +39 -0
- package/README.md +4 -1
- package/demo/components/IVueTest.vue +4 -1
- package/demo/main.ts +3 -1
- package/demo/tests/IVueTests.ts +10 -0
- package/dist/index.es.js +2 -1
- package/dist/index.umd.js +1 -1
- package/dist/src/kernel.d.ts +4 -4
- package/package.json +1 -1
- package/src/App/App.ts +3 -0
- package/src/App/BlackBox.ts +11 -4
- package/src/App/Services/Routing/Router.ts +3 -2
- package/src/kernel.ts +6 -4
- package/src/tests/auth.spec.ts +52 -13
- package/src/types/core.ts +3 -1
- package/src/utils/extend.ts +4 -3
- /package/.idea/{infinite-vue.iml → ivue.iml} +0 -0
package/.idea/modules.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ProjectModuleManager">
|
|
4
4
|
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/../
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/../ivue/.idea/ivue.iml" filepath="$PROJECT_DIR$/../ivue/.idea/ivue.iml" />
|
|
6
6
|
</modules>
|
|
7
7
|
</component>
|
|
8
8
|
</project>
|
package/PLAN.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
## Test ivue
|
|
2
|
+
|
|
3
|
+
### Test basic reactivity
|
|
4
|
+
- make sure basic reactivity works
|
|
5
|
+
- primitives, objects, arrays
|
|
6
|
+
|
|
7
|
+
### Test nested component instantiation and unloading reactivity
|
|
8
|
+
- ☑ tested now to 2 levels deep
|
|
9
|
+
- test it to 3-4 levels deep
|
|
10
|
+
- if components using use(ClassName) function are mounted/unmounted properly
|
|
11
|
+
|
|
12
|
+
### Test traits
|
|
13
|
+
- convert existing inside component tests to real automated tests
|
|
14
|
+
|
|
15
|
+
### Test getter computeds
|
|
16
|
+
- test getter computeds to at least 3 levels deep
|
|
17
|
+
|
|
18
|
+
### Test getters with use() and init() inside
|
|
19
|
+
- the variables instantiated within init() method should not cause a recompute
|
|
20
|
+
|
|
21
|
+
### Test behaviors
|
|
22
|
+
- class initialization before/after
|
|
23
|
+
- method call before/after
|
|
24
|
+
- test conditional before/after class/method substitution
|
|
25
|
+
|
|
26
|
+
### Test Kernel
|
|
27
|
+
- test bind() points to bound object
|
|
28
|
+
- use() should instantiate a singleton
|
|
29
|
+
- init() should instantiate a transient
|
|
30
|
+
- get() should instantiate non-reactive js singleton
|
|
31
|
+
- make() should instantiate non-reactive js transient
|
|
32
|
+
|
|
33
|
+
### Test ivue utils
|
|
34
|
+
- test extend function as props assignment
|
|
35
|
+
- test extend with .props as a property
|
|
36
|
+
- or when extend, extends the base class properties
|
|
37
|
+
- which approach is better (the second one becomes closer to vue 2 options api)
|
|
38
|
+
- extend function should have 'extendClasses' option
|
|
39
|
+
- so we can enable extension of class based objects as well, by default we only extend simple objects not class objects
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, provide, onUnmounted, onBeforeUnmount, getCurrentInstance, onMounted } from 'vue';
|
|
2
|
+
import { computed, provide, onUnmounted, onBeforeUnmount, getCurrentInstance, onMounted, markRaw } from 'vue';
|
|
3
3
|
import { IVueTests } from "../tests/IVueTests";
|
|
4
4
|
import { bind, ivue, use, init, pre, kernel } from '@/index'
|
|
5
5
|
import SubComponent2 from './SubComponent2.vue'
|
|
@@ -7,12 +7,15 @@ import TraitsComponent from './TraitsComponent.vue'
|
|
|
7
7
|
import { Mouse } from '../tests/Mouse';
|
|
8
8
|
import { getPrototypeGetters } from '../../src/utils/getters';
|
|
9
9
|
|
|
10
|
+
console.log('loaded')
|
|
10
11
|
let vm: IVueTests = use(IVueTests)
|
|
11
12
|
provide('mouse', ivue(Mouse))
|
|
12
13
|
const localComputedValue = computed(() => {
|
|
13
14
|
return vm.computedVariable?.[0]?.test + ' + local append'
|
|
14
15
|
})
|
|
15
16
|
|
|
17
|
+
vm.setTest('yes')
|
|
18
|
+
console.log(vm.test)
|
|
16
19
|
const hugeId = 2646049
|
|
17
20
|
|
|
18
21
|
function hey () {
|
package/demo/main.ts
CHANGED
|
@@ -7,12 +7,14 @@ import AppComponent from "./App.vue";
|
|
|
7
7
|
import { App } from '@/App/App';
|
|
8
8
|
import { Auth } from '@/App/Auth/Auth';
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
const app = use(App).load()
|
|
11
12
|
setup({ router: app.router, debug: true })
|
|
12
13
|
|
|
13
14
|
use(Auth)
|
|
15
|
+
export const vue = createApp(AppComponent);
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
console.log('vue', vue);
|
|
16
18
|
|
|
17
19
|
vue.use(app.router)
|
|
18
20
|
|
package/demo/tests/IVueTests.ts
CHANGED
|
@@ -8,9 +8,17 @@ import { onUnmounted, toRaw, watch, onBeforeUnmount } from "vue";
|
|
|
8
8
|
import { generateHugeArray } from "@/App/Generators/generators";
|
|
9
9
|
import { TField } from "./TField";
|
|
10
10
|
import { use, init, IVUE, unraw, before, ivue } from "@/index";
|
|
11
|
+
import type { ComponentPublicInstance } from 'vue';
|
|
11
12
|
|
|
12
13
|
export class IVueTests extends ParentIVueTests {
|
|
13
14
|
|
|
15
|
+
test = 1
|
|
16
|
+
setTest(value){
|
|
17
|
+
this.test = value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
instance
|
|
21
|
+
|
|
14
22
|
static behavior = {
|
|
15
23
|
init: IVUE.SCOPED_INTERCEPT,
|
|
16
24
|
nonReactiveProp: IVUE.OFF
|
|
@@ -56,6 +64,8 @@ export class IVueTests extends ParentIVueTests {
|
|
|
56
64
|
|
|
57
65
|
init () {
|
|
58
66
|
|
|
67
|
+
console.log('init')
|
|
68
|
+
|
|
59
69
|
watch(() => this.primitive, newValue => {
|
|
60
70
|
if (newValue === 10) {
|
|
61
71
|
console.log('watch matched value: 10 =', newValue)
|
package/dist/index.es.js
CHANGED
|
@@ -24,7 +24,7 @@ function m(t2, e2, n2 = null) {
|
|
|
24
24
|
const r2 = e2.shift();
|
|
25
25
|
if (y(t2) && y(r2))
|
|
26
26
|
for (const e3 in r2)
|
|
27
|
-
y(r2[e3]) && "Object" === r2[e3].constructor.name ? n2.has(r2[e3]) || null !== (o2 = r2[e3]) && "object" == typeof o2 && "function" == typeof o2.then && "function" == typeof o2.catch || void 0 === t2[e3] ? t2[e3] = r2[e3] : y(t2[e3])
|
|
27
|
+
y(r2[e3]) && "Object" === r2[e3].constructor.name ? n2.has(r2[e3]) || null !== (o2 = r2[e3]) && "object" == typeof o2 && "function" == typeof o2.then && "function" == typeof o2.catch || void 0 === t2[e3] ? t2[e3] = r2[e3] : y(t2[e3]) && t2[e3].constructor === Object ? m(t2[e3], [r2[e3]], n2) : t2[e3] = r2[e3] : t2[e3] = r2[e3];
|
|
28
28
|
var o2;
|
|
29
29
|
return m(t2, e2, n2);
|
|
30
30
|
}
|
|
@@ -269,6 +269,7 @@ class U {
|
|
|
269
269
|
}
|
|
270
270
|
use(s2, ...u2) {
|
|
271
271
|
let a2, f2, l2, h2, p2, b2, g2, d2 = e();
|
|
272
|
+
console.log("className", s2.name);
|
|
272
273
|
if (this.subscribers.set(s2, (this.subscribers.get(s2) || 0) + 1), d2 && i(() => {
|
|
273
274
|
var _a;
|
|
274
275
|
const t2 = (this.subscribers.get(s2) || 0) - 1;
|
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])?"Object"!==e[u].constructor.name?e[u]=i[u]: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=[];for(;e&&"Object"!==e.constructor.name;)n.push.apply(n,Object.entries(Object.getOwnPropertyDescriptors(e))),e=Object.getPrototypeOf(e.constructor.prototype);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,...i){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(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(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 W{}i(W,[x,$]);class J{constructor(){__publicField(this,"$emit",((...e)=>{}))}}class z{constructor(){__publicField(this,"$nextTick",t.nextTick)}}class A{constructor(e){var t;T(t=e),U(t),M(t)}}i(A,[W,N,J,z,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=J,e.UseInstance=I,e.UseMounting=N,e.UseRefs=D,e.UseRoute=$,e.UseRouter=x,e.UseRouting=W,e.UseTick=z,e.UseVue=A,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,...r);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=[];for(;e&&"Object"!==e.constructor.name;)n.push.apply(n,Object.entries(Object.getOwnPropertyDescriptors(e))),e=Object.getPrototypeOf(e.constructor.prototype);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,...i){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(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 W{}i(W,[x,$]);class J{constructor(){__publicField(this,"$emit",((...e)=>{}))}}class z{constructor(){__publicField(this,"$nextTick",t.nextTick)}}class A{constructor(e){var t;T(t=e),U(t),M(t)}}i(A,[W,N,J,z,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=J,e.UseInstance=I,e.UseMounting=N,e.UseRefs=D,e.UseRoute=$,e.UseRouter=x,e.UseRouting=W,e.UseTick=z,e.UseVue=A,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,...r);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/dist/src/kernel.d.ts
CHANGED
|
@@ -173,10 +173,10 @@ export declare const bind: any;
|
|
|
173
173
|
/**
|
|
174
174
|
* Kernel container getters for plain JavaScript classes.
|
|
175
175
|
*/
|
|
176
|
-
export declare const get:
|
|
177
|
-
export declare const make:
|
|
176
|
+
export declare const get: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => InstanceType<T>;
|
|
177
|
+
export declare const make: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => InstanceType<T>;
|
|
178
178
|
/**
|
|
179
179
|
* Kernel container getters for ivue reactive JavaScript classes.
|
|
180
180
|
*/
|
|
181
|
-
export declare const use:
|
|
182
|
-
export declare const init:
|
|
181
|
+
export declare const use: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => IVue<T>;
|
|
182
|
+
export declare const init: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => IVue<T>;
|
package/package.json
CHANGED
package/src/App/App.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Router } from './Services/Routing/Router'
|
|
|
6
6
|
import routes from './Services/Routing/Routes'
|
|
7
7
|
import { Auth } from './Auth/Auth'
|
|
8
8
|
import { User } from './Auth/User'
|
|
9
|
+
import { IVueTests } from '../../demo/tests/IVueTests'
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
export class App {
|
|
@@ -18,6 +19,8 @@ export class App {
|
|
|
18
19
|
|
|
19
20
|
get message () { return use(Message) }
|
|
20
21
|
|
|
22
|
+
get ivue () { return use(IVueTests) }
|
|
23
|
+
|
|
21
24
|
load () {
|
|
22
25
|
this.router.$.register(routes)
|
|
23
26
|
return this
|
package/src/App/BlackBox.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createApp } from "vue";
|
|
2
|
+
import { mount, type VueWrapper} from '@vue/test-utils'
|
|
2
3
|
import { vi } from 'vitest'
|
|
3
4
|
import { setup, bind, use } from '@/index'
|
|
4
5
|
import AppComponent from "../../demo/App.vue";
|
|
@@ -11,6 +12,7 @@ import { Router } from './Services/Routing/Router'
|
|
|
11
12
|
import { Auth } from './Auth/Auth.js'
|
|
12
13
|
|
|
13
14
|
import { SingleBooksResultStub } from './Stubs/SingleBooksResultStub'
|
|
15
|
+
import { VueDd } from "vue-dd";
|
|
14
16
|
|
|
15
17
|
export class BlackBox {
|
|
16
18
|
|
|
@@ -22,7 +24,7 @@ export class BlackBox {
|
|
|
22
24
|
|
|
23
25
|
router!: Router
|
|
24
26
|
|
|
25
|
-
vue!:
|
|
27
|
+
vue!: VueWrapper
|
|
26
28
|
|
|
27
29
|
init() {
|
|
28
30
|
|
|
@@ -32,12 +34,17 @@ export class BlackBox {
|
|
|
32
34
|
this.app = use(App).load()
|
|
33
35
|
setup({ router: this.app.router })
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
this.vue = mount(AppComponent, {
|
|
38
|
+
global: {
|
|
39
|
+
components: {VueDd},
|
|
40
|
+
plugins: [this.app.router]
|
|
41
|
+
}
|
|
42
|
+
});
|
|
36
43
|
|
|
37
|
-
// console.log('router', this.app.router)
|
|
44
|
+
// // console.log('router', this.app.router)
|
|
38
45
|
// this.vue.use(this.app.router)
|
|
39
46
|
|
|
40
|
-
// this.vue.mount("
|
|
47
|
+
// this.vue.mount(document.createElement("div"));
|
|
41
48
|
|
|
42
49
|
|
|
43
50
|
// Object.defineProperty(Router.prototype, 'push', {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { unref } from 'vue';
|
|
1
|
+
import { getCurrentScope, unref } from 'vue';
|
|
2
2
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
3
3
|
import { Traits, UseCapsule, use } from '@/index'
|
|
4
4
|
import { $Message } from '../Message/Message'
|
|
@@ -7,6 +7,7 @@ import type { RouteLocationNormalized } from 'vue-router';
|
|
|
7
7
|
import type { Null, AnyObj, Params } from '@/types/core';
|
|
8
8
|
import type { Router as VueRouter } from 'vue-router'
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
const __$Router__ = ($ = $Router.prototype) => ([
|
|
11
12
|
// Other
|
|
12
13
|
$.user,
|
|
@@ -63,7 +64,7 @@ export class $Router {
|
|
|
63
64
|
// console.log('this.flatRoutes', this.flatRoutes)
|
|
64
65
|
|
|
65
66
|
this.routeConfig = this.setup(this.routes)
|
|
66
|
-
console.log('routeConfig', this.routeConfig)
|
|
67
|
+
// console.log('routeConfig', this.routeConfig)
|
|
67
68
|
|
|
68
69
|
this.router = createRouter({ history: createWebHistory(), routes: this.routes })
|
|
69
70
|
|
package/src/kernel.ts
CHANGED
|
@@ -273,6 +273,7 @@ export class Kernel {
|
|
|
273
273
|
computeds: Computeds | any,
|
|
274
274
|
intercept: Intercept | any,
|
|
275
275
|
fns: any
|
|
276
|
+
console.log('className', className.name)
|
|
276
277
|
/**
|
|
277
278
|
* Advanced garabage collection and disposal mechanism.
|
|
278
279
|
*/
|
|
@@ -802,10 +803,11 @@ export const bind = kernel.bind.bind(kernel)
|
|
|
802
803
|
/**
|
|
803
804
|
* Kernel container getters for plain JavaScript classes.
|
|
804
805
|
*/
|
|
805
|
-
export
|
|
806
|
-
export
|
|
806
|
+
export const get: <T extends AnyClass> (className: T, ...args: InferredArgs<T>) => InstanceType<T> = kernel.get.bind(kernel)
|
|
807
|
+
export const make: <T extends AnyClass> (className: T, ...args: InferredArgs<T>) => InstanceType<T> = kernel.make.bind(kernel)
|
|
808
|
+
|
|
807
809
|
/**
|
|
808
810
|
* Kernel container getters for ivue reactive JavaScript classes.
|
|
809
811
|
*/
|
|
810
|
-
export
|
|
811
|
-
export
|
|
812
|
+
export const use: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => IVue<T> = kernel.use.bind(kernel);
|
|
813
|
+
export const init: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => IVue<T> = kernel.init.bind(kernel);
|
package/src/tests/auth.spec.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { describe, it, beforeEach, expect, vi } from 'vitest'
|
|
2
2
|
import { BlackBox } from '../App/BlackBox'
|
|
3
3
|
import type { App } from '@/App/App';
|
|
4
|
+
import type { VueWrapper } from '@vue/test-utils';
|
|
5
|
+
|
|
6
|
+
export default function sleep (ms) {
|
|
7
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
8
|
+
}
|
|
4
9
|
|
|
5
10
|
let box: BlackBox
|
|
6
11
|
let app: App
|
|
12
|
+
let vue: VueWrapper
|
|
7
13
|
|
|
8
14
|
function wait () {
|
|
9
15
|
return setTimeout(() => {})
|
|
@@ -13,18 +19,44 @@ describe('--- auth test ----', () => {
|
|
|
13
19
|
|
|
14
20
|
beforeEach(() => {
|
|
15
21
|
box = new BlackBox().init()
|
|
22
|
+
vue = box.vue
|
|
16
23
|
app = box.app
|
|
17
24
|
})
|
|
18
25
|
|
|
19
|
-
it('root route redirects to login', async () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
// it('root route redirects to login', async () => {
|
|
27
|
+
// await app.router.push({ name: 'root' })
|
|
28
|
+
// // console.log(app.router)
|
|
29
|
+
// expect(app.router.active.name).toBe('login')
|
|
30
|
+
// })
|
|
31
|
+
|
|
32
|
+
// it('successful login redirects to homepage', async () => {
|
|
33
|
+
// await app.router.push({ name: 'root' })
|
|
34
|
+
|
|
35
|
+
// app.auth.email = 'ekalashnikov@gmail.com'
|
|
36
|
+
// app.auth.password = 'test1234'
|
|
37
|
+
|
|
38
|
+
// const spy = vi.spyOn(app.router, 'push')
|
|
39
|
+
|
|
40
|
+
// await app.auth.login()
|
|
41
|
+
|
|
42
|
+
// expect(spy).toHaveBeenCalledTimes(1)
|
|
43
|
+
// expect(spy).toHaveBeenCalledWith({ name: 'home' })
|
|
44
|
+
|
|
45
|
+
// expect(app.message.appMessages).toEqual(['User logged in'])
|
|
23
46
|
|
|
24
|
-
|
|
47
|
+
// expect(app.user.email).toBe('ekalashnikov@gmail.com')
|
|
48
|
+
// expect(app.user.token).toBe('1234ekalashnikov@gmail.com')
|
|
49
|
+
|
|
50
|
+
// await app.router.isLoaded()
|
|
51
|
+
|
|
52
|
+
// expect(app.router.currentRoute.name).toBe('home')
|
|
53
|
+
// })
|
|
54
|
+
|
|
55
|
+
it('load ivue component context', async () => {
|
|
25
56
|
await app.router.push({ name: 'root' })
|
|
26
57
|
|
|
27
|
-
|
|
58
|
+
// console.log('instance', app.ivue.test)
|
|
59
|
+
app.auth.email = 'ekalashnikov@gmail.com'
|
|
28
60
|
app.auth.password = 'test1234'
|
|
29
61
|
|
|
30
62
|
const spy = vi.spyOn(app.router, 'push')
|
|
@@ -33,15 +65,22 @@ describe('--- auth test ----', () => {
|
|
|
33
65
|
|
|
34
66
|
expect(spy).toHaveBeenCalledTimes(1)
|
|
35
67
|
expect(spy).toHaveBeenCalledWith({ name: 'home' })
|
|
36
|
-
|
|
37
|
-
expect(app.message.appMessages).toEqual(['User logged in'])
|
|
38
68
|
|
|
39
|
-
expect(app.
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
// expect(app.message.appMessages).toEqual(['User logged in'])
|
|
70
|
+
|
|
71
|
+
await app.router.push({ name: 'ivue' })
|
|
72
|
+
|
|
73
|
+
console.log('ivue', app.ivue.test)
|
|
42
74
|
await app.router.isLoaded()
|
|
43
|
-
|
|
44
|
-
|
|
75
|
+
|
|
76
|
+
const sub = vue.getComponent({ name: 'IVueTest' }).getComponent({ name: 'SubComponent2' })
|
|
77
|
+
console.log('sub.vm.v', sub.vm.v)
|
|
78
|
+
|
|
79
|
+
//console.log('IVueTest', )
|
|
80
|
+
|
|
81
|
+
// console.log('box.vue', box.vue)
|
|
82
|
+
|
|
83
|
+
expect(app.router.currentRoute.name).toBe('ivue')
|
|
45
84
|
})
|
|
46
85
|
|
|
47
86
|
})
|
package/src/types/core.ts
CHANGED
|
@@ -61,4 +61,6 @@ export type AnyObj = Record<string | number | symbol, any>
|
|
|
61
61
|
export type Params<T extends (...args: any) => any> = Parameters<T>
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
export type Computeds = Record<string | symbol | number, ComputedRef>
|
|
64
|
+
export type Computeds = Record<string | symbol | number, ComputedRef>
|
|
65
|
+
|
|
66
|
+
|
package/src/utils/extend.ts
CHANGED
|
@@ -39,6 +39,7 @@ function _extend<K, V> (target: any, sources: any[], parents: Map<K, V> | null |
|
|
|
39
39
|
if (isObject(target) && isObject(source)) {
|
|
40
40
|
|
|
41
41
|
for (const key in source) {
|
|
42
|
+
|
|
42
43
|
if (isObject(source[key]) && source[key].constructor.name === 'Object') {
|
|
43
44
|
// detect circular references using Map parents object
|
|
44
45
|
if (parents.has(source[key])) {
|
|
@@ -65,10 +66,10 @@ function _extend<K, V> (target: any, sources: any[], parents: Map<K, V> | null |
|
|
|
65
66
|
target[key] = source[key]
|
|
66
67
|
} else {
|
|
67
68
|
// Only simple objects can extend the target
|
|
68
|
-
if (target[key].constructor
|
|
69
|
-
target[key] = source[key]
|
|
70
|
-
} else {
|
|
69
|
+
if (target[key].constructor === Object) {
|
|
71
70
|
_extend(target[key], [source[key]], parents)
|
|
71
|
+
} else {
|
|
72
|
+
target[key] = source[key]
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
}
|
|
File without changes
|