ivue 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/codeStyles/Project.xml +65 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/ivue.iml +8 -0
- package/.idea/modules.xml +8 -0
- package/.idea/php.xml +19 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +23 -7
- package/coverage/clover.xml +159 -159
- package/coverage/coverage-final.json +1 -1
- package/coverage/index.html +17 -17
- package/coverage/index.ts.html +86 -107
- package/dist/index.es.js +74 -90
- package/dist/index.umd.js +1 -1
- package/dist/src/index.d.ts +1 -196
- package/dist/src/ivue.d.ts +218 -0
- package/docs/docs/.vitepress/config.ts +110 -22
- package/docs/docs/.vitepress/dist/404.html +4 -4
- package/docs/docs/.vitepress/dist/api/ivue.html +8 -8
- package/docs/docs/.vitepress/dist/api/propsWithDefaults.html +8 -8
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.BCZ4q_0D.js → api_ivue.md.MRwb9Lcb.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.BCZ4q_0D.lean.js → api_ivue.md.MRwb9Lcb.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.Cr5FwI9o.lean.js → api_propsWithDefaults.md.CeE4IC-K.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.Cr5FwI9o.js → api_propsWithDefaults.md.CeE4IC-K.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{app.DRiljpSE.js → app.ConZRsN0.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.CGLWArGd.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/Button.vue_vue_type_script_setup_true_lang.P7niV-n8.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/VPLocalSearchBox.C7VDyivS.js +7 -0
- package/docs/docs/.vitepress/dist/assets/chunks/framework.CNtPHGsN.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.DnWLDAUc.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/theme.B7n-r1TY.js +2 -0
- package/docs/docs/.vitepress/dist/assets/index.md.wPLoTLBY.js +1 -0
- package/docs/docs/.vitepress/dist/assets/index.md.wPLoTLBY.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_advanced-usage.md.BZgX-VP7.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_advanced-usage.md.BZgX-VP7.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_api.md.C_PvCZns.js +7 -0
- package/docs/docs/.vitepress/dist/assets/pages_api.md.C_PvCZns.lean.js +7 -0
- package/docs/docs/.vitepress/dist/assets/pages_browse-code.md.CPluoaap.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_browse-code.md.CPluoaap.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.knQcOZyP.js +8 -0
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.knQcOZyP.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_guidelines.md.DddPdPom.js +101 -0
- package/docs/docs/.vitepress/dist/assets/pages_guidelines.md.DddPdPom.lean.js +101 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.OJGcGEXF.js +4 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.OJGcGEXF.lean.js +4 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-its-made.md.Vv9Z9TEi.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-its-made.md.Vv9Z9TEi.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.DrDm-R8F.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.DrDm-R8F.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.zSOVjtFF.js +430 -0
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.zSOVjtFF.lean.js +430 -0
- package/docs/docs/.vitepress/dist/assets/style.Fgx7OB_D.css +1 -0
- package/docs/docs/.vitepress/dist/hashmap.json +1 -1
- package/docs/docs/.vitepress/dist/index.html +9 -8
- package/docs/docs/.vitepress/dist/pages/advanced-usage.html +24 -0
- package/docs/docs/.vitepress/dist/pages/api.html +30 -0
- package/docs/docs/.vitepress/dist/pages/browse-code.html +24 -0
- package/docs/docs/.vitepress/dist/pages/getting-started.html +11 -11
- package/docs/docs/.vitepress/dist/pages/guidelines.html +125 -0
- package/docs/docs/.vitepress/dist/pages/how-it-works.html +11 -8
- package/docs/docs/.vitepress/dist/pages/how-its-made.html +24 -0
- package/docs/docs/.vitepress/dist/pages/introduction.html +9 -8
- package/docs/docs/.vitepress/dist/pages/usage.html +428 -14
- package/docs/docs/.vitepress/theme/index.js +5 -0
- package/docs/docs/.vitepress/theme/main.css +29 -0
- package/docs/docs/components/Button.vue +1 -1
- package/docs/docs/components/guidelines/CounterExternalRefsDetailed.vue +41 -0
- package/docs/docs/components/usage/CounterBasic.vue +17 -0
- package/docs/docs/components/usage/CounterComposables.vue +19 -0
- package/docs/docs/components/usage/CounterComposablesDestructuring.vue +46 -0
- package/docs/docs/components/usage/CounterComputeds.vue +25 -0
- package/docs/docs/components/usage/CounterComputedsDisabled.vue +32 -0
- package/docs/docs/components/usage/CounterDefineExpose.vue +12 -0
- package/docs/docs/components/usage/CounterDefineExposeAdvanced.vue +25 -0
- package/docs/docs/components/usage/CounterDefineExposeClass.ts +11 -0
- package/docs/docs/components/usage/CounterExternalRefs.vue +25 -0
- package/docs/docs/components/usage/CounterInsideComposables.vue +27 -0
- package/docs/docs/components/usage/CounterInternalRefs.vue +26 -0
- package/docs/docs/components/usage/CounterLifecycleHooks.vue +22 -0
- package/docs/docs/components/usage/CounterWatch.vue +25 -0
- package/docs/docs/components/usage/CounterWithProps.vue +29 -0
- package/docs/docs/components/usage/CounterWithPropsAndEmits.vue +36 -0
- package/docs/docs/components/usage/functions/useMouse.ts +22 -0
- package/docs/docs/index.md +10 -9
- package/docs/docs/pages/advanced-usage.md +11 -0
- package/docs/docs/pages/api.md +106 -0
- package/docs/docs/pages/browse-code.md +18 -0
- package/docs/docs/pages/getting-started.md +23 -5
- package/docs/docs/pages/guidelines.md +128 -0
- package/docs/docs/pages/how-it-works.md +71 -0
- package/docs/docs/pages/how-its-made.md +32 -0
- package/docs/docs/pages/introduction.md +37 -20
- package/docs/docs/pages/usage.md +347 -10
- package/docs/package.json +4 -3
- package/package.json +4 -2
- package/src/__tests__/ivue.vitest.spec.ts +228 -132
- package/src/index.ts +1 -463
- package/src/ivue.ts +495 -0
- package/vite.config.ts +4 -0
- package/docs/.env +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/framework.CEhE-9HF.js +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/theme.CldUEgAJ.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.B1vDz5mb.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.B1vDz5mb.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.C7qtPEWU.js +0 -8
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.C7qtPEWU.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.DKizt6Ny.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.DKizt6Ny.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.Dkqu-XCz.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.Dkqu-XCz.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.qo7ICfLC.js +0 -17
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.qo7ICfLC.lean.js +0 -17
- package/docs/docs/.vitepress/dist/assets/style.BSZVsGuP.css +0 -1
- package/docs/docs/components/examples/Counter.vue +0 -17
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import{x as E}from"./chunks/index.es.DnWLDAUc.js";import{d as p,s as l,o as k,c as r,j as a,k as h,a as g,t as y,F as u,y as F,I as b,a5 as d}from"./chunks/framework.CNtPHGsN.js";const f=a("br",null,null,-1),m=p({__name:"CounterExternalRefsDetailed",setup(o,{expose:n}){class e{constructor(s){this.span=s,this.count=l(0)}init(){F(()=>{this.span.innerHTML="Initial span text!"})}increment(){this.count++,this.span.innerHTML=String(this.count+1)}}const t=l(),i=E(e,t);return n(i),(c,s)=>(k(),r(u,null,[a("a",{href:"javascript:void(0)",onClick:s[0]||(s[0]=()=>h(i).increment())},"Increment"),g(" Count: "+y(h(i).count)+" ",1),f,a("span",{ref_key:"span",ref:t},null,512)],64))}}),D=d(`<h1 id="guidelines" tabindex="-1">Guidelines <a class="header-anchor" href="#guidelines" aria-label="Permalink to "Guidelines""></a></h1><h2 id="dos-and-don-ts" tabindex="-1">Dos and Don'ts <a class="header-anchor" href="#dos-and-don-ts" aria-label="Permalink to "Dos and Don'ts""></a></h2><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseMouse</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseComposable</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">typeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> useMouse>;</span></span>
|
|
2
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/**</span></span>
|
|
3
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Example of a properly defined ivue class.</span></span>
|
|
4
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
5
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Counter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
6
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared unwrapped composable. */</span></span>
|
|
7
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> mouse</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseMouse</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
8
|
+
<span class="line"></span>
|
|
9
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> constructor</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> props</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> CounterProps</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> emit</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> CounterEmit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
|
10
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.mouse </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> useMouse</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseMouse</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // ✅ Properly declared unwrapped composable.</span></span>
|
|
11
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
12
|
+
<span class="line"></span>
|
|
13
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared init function. */</span></span>
|
|
14
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> init</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
15
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly set lifecycle hook. */</span></span>
|
|
16
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> onMounted</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
17
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
18
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span>
|
|
19
|
+
<span class="line"></span>
|
|
20
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly set watch function */</span></span>
|
|
21
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> watch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count, (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">newCount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
22
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (newCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">===</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
|
23
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> alert</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'You reached the count of '</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> newCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> '!'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
|
|
24
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
25
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> })</span></span>
|
|
26
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
27
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
|
|
28
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Use ref() for the property and cast it to number</span></span>
|
|
29
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * because refs auto-unwrap inside reactive().</span></span>
|
|
30
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
31
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// ✅</span></span>
|
|
32
|
+
<span class="line"></span>
|
|
33
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
|
|
34
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Use ref() for the property and cast it to number</span></span>
|
|
35
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * because refs auto-unwrap inside reactive().</span></span>
|
|
36
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
37
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> timesClicked</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// ✅</span></span>
|
|
38
|
+
<span class="line"></span>
|
|
39
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared function (not arrow function). */</span></span>
|
|
40
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
41
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
42
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
43
|
+
<span class="line"></span>
|
|
44
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared function (not arrow function). */</span></span>
|
|
45
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> click</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
46
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
|
|
47
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.timesClicked</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
48
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
49
|
+
<span class="line"></span>
|
|
50
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
|
|
51
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Do NOT use arrow functions, arrow functions are not extensible.</span></span>
|
|
52
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
53
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> increment</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> () </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ❌</span></span>
|
|
54
|
+
<span class="line"></span>
|
|
55
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared computed getter. */</span></span>
|
|
56
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> get</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> doubleCount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
57
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
58
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
59
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h3 id="use-ref-for-properties" tabindex="-1">Use ref() for properties <a class="header-anchor" href="#use-ref-for-properties" aria-label="Permalink to "Use ref() for properties""></a></h3><p><code>ivue</code> recommends all class properties to be defined as <code>ref()</code> to be able to interoperate with <code>defineExpose()</code>, if you simply pass reactive props which are not Refs through <code>defineExpose()</code>, they will lose reactivity. <code>ref()</code> refs just like computed refs get flattened into the <code>reactive()</code> object, so there is no need to worry about using <code>.value</code>. The <code>ref()</code> refs are necessary just internally for Vue 3 to know which refs to keep reactive.</p><h3 id="unwrap-de-ref-the-types" tabindex="-1">Unwrap (de-Ref) the types <a class="header-anchor" href="#unwrap-de-ref-the-types" aria-label="Permalink to "Unwrap (de-Ref) the types""></a></h3><p>Next, we convert the types back to their normal types as if they have no reactivity at all, so <code>Ref<number></code> is <code>number</code> in <code>ivue</code>, so rather than going in the direction of complexifying the types, we are going in the opposite direction towards simplification.</p><h3 id="use-standard-declaration-syntax-for-functions" tabindex="-1">Use standard declaration syntax for functions <a class="header-anchor" href="#use-standard-declaration-syntax-for-functions" aria-label="Permalink to "Use standard declaration syntax for functions""></a></h3><p><code>ivue</code> recommends all class functions to be defined in plain full function style (not arrow functions), this allows all <code>ivue</code> classes to be extensible at any point. By using plain standard functions, it allows the developer to be able to override them at any time by simply extending the class.</p><h3 id="do-not-use-arrow-functions-in-class-declarations" tabindex="-1">Do not use arrow functions in class declarations <a class="header-anchor" href="#do-not-use-arrow-functions-in-class-declarations" aria-label="Permalink to "Do not use arrow functions in class declarations""></a></h3><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Arrow functions break full extensibility of classes because they carry their own context at the point of declaration, so avoid using them inside of <code>ivue</code> classes.</p></div><h2 id="constructor-vs-init" tabindex="-1">constructor() vs .init() <a class="header-anchor" href="#constructor-vs-init" aria-label="Permalink to "constructor() vs .init()""></a></h2><h4 id="use-constructor-to-assign-properties-of-the-class-and-cast-refs-to-unwrapped-bare-types" tabindex="-1">Use <code>constructor()</code> to assign properties of the class and cast Refs to Unwrapped bare types. <br> <a class="header-anchor" href="#use-constructor-to-assign-properties-of-the-class-and-cast-refs-to-unwrapped-bare-types" aria-label="Permalink to "Use \`constructor()\` to assign properties of the class and cast Refs to Unwrapped bare types. <br />""></a></h4><h4 id="use-init-to-declare-reactive-state-functions-like-watch-watcheffect-and-lifecycle-hooks-like-onmounted-onbeforemount-etc-do-assignments-of-reactive-properties-since-init-already-has-access-to-reactive-state-through-this" tabindex="-1">Use <code>.init()</code> to declare reactive state functions like <code>watch</code>, <code>watchEffect</code>, and lifecycle hooks like <code>onMounted</code>, <code>onBeforeMount</code> etc, do assignments of reactive properties, since <code>init()</code> already has access to <code>reactive()</code> state through <code>this</code>.<br> <a class="header-anchor" href="#use-init-to-declare-reactive-state-functions-like-watch-watcheffect-and-lifecycle-hooks-like-onmounted-onbeforemount-etc-do-assignments-of-reactive-properties-since-init-already-has-access-to-reactive-state-through-this" aria-label="Permalink to "Use \`.init()\` to declare reactive state functions like \`watch\`, \`watchEffect\`, and lifecycle hooks like \`onMounted\`, \`onBeforeMount\` etc, do assignments of reactive properties, since \`init()\` already has access to \`reactive()\` state through \`this\`.<br />""></a></h4><hr><p>Inside the <code>constructor()</code> method you still have access to non-reactive state, because when <code>constructor()</code> is initialized, it does NOT yet have access to the reactive properties of the class, since it was not yet converted to <code>reactive()</code> by <code>ivue</code>, so if you use the properties like Refs or ComputedRefs inside <code>constructor()</code> you would have to use them with the <code>.value</code>.</p><p>As a general rule, there is no need to manipulate the values in the <code>constructor()</code>, use constructor only for assigning the properties and casting the types of those assigned properties to the unwrapped (de-Refed) final state of the resulting <code>reactive()</code> object.</p><p><strong>Let's look at a <code>constructor()</code> vs <code>.init()</code> example:</strong></p><div class="vp-code-group vp-adaptive-theme"><div class="tabs"><input type="radio" name="group-UgXuH" id="tab-hvXWMZk" checked><label for="tab-hvXWMZk">CounterExternalRefsDetailed.vue</label></div><div class="blocks"><div class="language-vue vp-adaptive-theme active line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">vue</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">script</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setup</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> lang</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"ts"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
60
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { onMounted, ref } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'vue'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
61
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { ivue } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'ivue'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
62
|
+
<span class="line"></span>
|
|
63
|
+
<span class="line highlighted"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SpanRef</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> HTMLElement</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> null</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
64
|
+
<span class="line"></span>
|
|
65
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Counter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
66
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> constructor</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> span</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SpanRef</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
|
67
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Do not do this in the constructor() because this.span </span></span>
|
|
68
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // still refers to this.span.value here:</span></span>
|
|
69
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // onMounted(() => { </span></span>
|
|
70
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // (this.span as HTMLElement /*❌*/).innerHTML = 'Initial span text!';</span></span>
|
|
71
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // });</span></span>
|
|
72
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
73
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> init</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
74
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Do this inside init() because this.span (.value) is now</span></span>
|
|
75
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // flattened & (this) is now reactive():</span></span>
|
|
76
|
+
<span class="line highlighted"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> onMounted</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
77
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.span </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> HTMLElement</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/*✅*/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">).innerHTML </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'Initial span text!'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
78
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span>
|
|
79
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
80
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
81
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
82
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
83
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.span </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> HTMLElement</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">).innerHTML </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> String</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
|
|
84
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
85
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
|
|
86
|
+
<span class="line"></span>
|
|
87
|
+
<span class="line highlighted"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> span</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">SpanRef</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>();</span></span>
|
|
88
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> counter</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ivue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span></span>
|
|
89
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Counter,</span></span>
|
|
90
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> span </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SpanRef</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** Unwrap Ref Manually */</span></span>
|
|
91
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
|
|
92
|
+
<span class="line"></span>
|
|
93
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">defineExpose</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Counter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>(counter);</span></span>
|
|
94
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">script</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
95
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
96
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">a</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> href</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"javascript:void(0)"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> @</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">click</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> counter.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>Increment</</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">a</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
97
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Count: {{ counter.count }} <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">br</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /></span></span>
|
|
98
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">span</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"span"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">span</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
99
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br></div></div></div></div><details class="details custom-block"><summary>For this example we initialize the component like this:</summary><div class="language-vue vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">vue</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
100
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">CounterExternalRefsDetailed</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /></span></span>
|
|
101
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></div></details><div style="font-size:18px;font-weight:500;">Result</div>`,21),A=d('<h2 id="unwrapping-refs" tabindex="-1">Unwrapping Refs <a class="header-anchor" href="#unwrapping-refs" aria-label="Permalink to "Unwrapping Refs""></a></h2><p>The key to working with <code>ivue</code> is understanding correctly the way Vue 3 does automatic Unwrapping of Refs when they are passed into the <code>reactive()</code> object. In that regard we are not relying on some magic <code>ivue</code> behavior but rather the default behavior of <code>reactive()</code> Vue 3 function.</p><p>To match that unwrapping behavior, our class needs to Unwrap (or de-Ref) the types of Composables, Refs, ComputedRefs, if they are being passed into the constructor, to get their raw basic types those Refs are pointing to, so that you can start operating in the <code>ivue</code> environment, where there is no need to worry about <code>.value</code>. This unwrapping should be mainly done inside the <code>constructor()</code> method.</p><h2 id="naming-conventions" tabindex="-1">Naming Conventions <a class="header-anchor" href="#naming-conventions" aria-label="Permalink to "Naming Conventions""></a></h2><p>To benefit from the full power of <code>ivue</code>, it is recommended to extract the classes into separate files. What has been an effective pattern is to name the classes and put them right beside components in the same folder that these classes are being used with. So if you have <code>CounterComponent.vue</code> component, it can have a class inside <code>CounterComponentClass.ts</code>, and you can store props, emits, and other runtime definitions inside <code>CounterComponentProps.ts</code>.</p>',5),w=JSON.parse('{"title":"Guidelines","description":"","frontmatter":{},"headers":[],"relativePath":"pages/guidelines.md","filePath":"pages/guidelines.md"}'),C={name:"pages/guidelines.md"},x=p({...C,setup(o){return(n,e)=>(k(),r("div",null,[D,b(m),A]))}});export{w as __pageData,x as default};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import{x as E}from"./chunks/index.es.DnWLDAUc.js";import{d as p,s as l,o as k,c as r,j as a,k as h,a as g,t as y,F as u,y as F,I as b,a5 as d}from"./chunks/framework.CNtPHGsN.js";const f=a("br",null,null,-1),m=p({__name:"CounterExternalRefsDetailed",setup(o,{expose:n}){class e{constructor(s){this.span=s,this.count=l(0)}init(){F(()=>{this.span.innerHTML="Initial span text!"})}increment(){this.count++,this.span.innerHTML=String(this.count+1)}}const t=l(),i=E(e,t);return n(i),(c,s)=>(k(),r(u,null,[a("a",{href:"javascript:void(0)",onClick:s[0]||(s[0]=()=>h(i).increment())},"Increment"),g(" Count: "+y(h(i).count)+" ",1),f,a("span",{ref_key:"span",ref:t},null,512)],64))}}),D=d(`<h1 id="guidelines" tabindex="-1">Guidelines <a class="header-anchor" href="#guidelines" aria-label="Permalink to "Guidelines""></a></h1><h2 id="dos-and-don-ts" tabindex="-1">Dos and Don'ts <a class="header-anchor" href="#dos-and-don-ts" aria-label="Permalink to "Dos and Don'ts""></a></h2><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseMouse</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseComposable</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">typeof</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> useMouse>;</span></span>
|
|
2
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/**</span></span>
|
|
3
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Example of a properly defined ivue class.</span></span>
|
|
4
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
5
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Counter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
6
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared unwrapped composable. */</span></span>
|
|
7
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> mouse</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseMouse</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
8
|
+
<span class="line"></span>
|
|
9
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> constructor</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> props</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> CounterProps</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> emit</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> CounterEmit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
|
10
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.mouse </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> useMouse</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> UseMouse</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // ✅ Properly declared unwrapped composable.</span></span>
|
|
11
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
12
|
+
<span class="line"></span>
|
|
13
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared init function. */</span></span>
|
|
14
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> init</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
15
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly set lifecycle hook. */</span></span>
|
|
16
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> onMounted</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
17
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
18
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span>
|
|
19
|
+
<span class="line"></span>
|
|
20
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly set watch function */</span></span>
|
|
21
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> watch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count, (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">newCount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
22
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (newCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">===</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
|
23
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> alert</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'You reached the count of '</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> newCount </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> '!'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
|
|
24
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
25
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> })</span></span>
|
|
26
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
27
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
|
|
28
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Use ref() for the property and cast it to number</span></span>
|
|
29
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * because refs auto-unwrap inside reactive().</span></span>
|
|
30
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
31
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// ✅</span></span>
|
|
32
|
+
<span class="line"></span>
|
|
33
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
|
|
34
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Use ref() for the property and cast it to number</span></span>
|
|
35
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * because refs auto-unwrap inside reactive().</span></span>
|
|
36
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
37
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> timesClicked</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// ✅</span></span>
|
|
38
|
+
<span class="line"></span>
|
|
39
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared function (not arrow function). */</span></span>
|
|
40
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
41
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
42
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
43
|
+
<span class="line"></span>
|
|
44
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared function (not arrow function). */</span></span>
|
|
45
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> click</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
46
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
|
|
47
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.timesClicked</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
48
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
49
|
+
<span class="line"></span>
|
|
50
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /**</span></span>
|
|
51
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> * Do NOT use arrow functions, arrow functions are not extensible.</span></span>
|
|
52
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
|
|
53
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> increment</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> () </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ❌</span></span>
|
|
54
|
+
<span class="line"></span>
|
|
55
|
+
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** ✅ Properly declared computed getter. */</span></span>
|
|
56
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> get</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> doubleCount</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
57
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
58
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
59
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h3 id="use-ref-for-properties" tabindex="-1">Use ref() for properties <a class="header-anchor" href="#use-ref-for-properties" aria-label="Permalink to "Use ref() for properties""></a></h3><p><code>ivue</code> recommends all class properties to be defined as <code>ref()</code> to be able to interoperate with <code>defineExpose()</code>, if you simply pass reactive props which are not Refs through <code>defineExpose()</code>, they will lose reactivity. <code>ref()</code> refs just like computed refs get flattened into the <code>reactive()</code> object, so there is no need to worry about using <code>.value</code>. The <code>ref()</code> refs are necessary just internally for Vue 3 to know which refs to keep reactive.</p><h3 id="unwrap-de-ref-the-types" tabindex="-1">Unwrap (de-Ref) the types <a class="header-anchor" href="#unwrap-de-ref-the-types" aria-label="Permalink to "Unwrap (de-Ref) the types""></a></h3><p>Next, we convert the types back to their normal types as if they have no reactivity at all, so <code>Ref<number></code> is <code>number</code> in <code>ivue</code>, so rather than going in the direction of complexifying the types, we are going in the opposite direction towards simplification.</p><h3 id="use-standard-declaration-syntax-for-functions" tabindex="-1">Use standard declaration syntax for functions <a class="header-anchor" href="#use-standard-declaration-syntax-for-functions" aria-label="Permalink to "Use standard declaration syntax for functions""></a></h3><p><code>ivue</code> recommends all class functions to be defined in plain full function style (not arrow functions), this allows all <code>ivue</code> classes to be extensible at any point. By using plain standard functions, it allows the developer to be able to override them at any time by simply extending the class.</p><h3 id="do-not-use-arrow-functions-in-class-declarations" tabindex="-1">Do not use arrow functions in class declarations <a class="header-anchor" href="#do-not-use-arrow-functions-in-class-declarations" aria-label="Permalink to "Do not use arrow functions in class declarations""></a></h3><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Arrow functions break full extensibility of classes because they carry their own context at the point of declaration, so avoid using them inside of <code>ivue</code> classes.</p></div><h2 id="constructor-vs-init" tabindex="-1">constructor() vs .init() <a class="header-anchor" href="#constructor-vs-init" aria-label="Permalink to "constructor() vs .init()""></a></h2><h4 id="use-constructor-to-assign-properties-of-the-class-and-cast-refs-to-unwrapped-bare-types" tabindex="-1">Use <code>constructor()</code> to assign properties of the class and cast Refs to Unwrapped bare types. <br> <a class="header-anchor" href="#use-constructor-to-assign-properties-of-the-class-and-cast-refs-to-unwrapped-bare-types" aria-label="Permalink to "Use \`constructor()\` to assign properties of the class and cast Refs to Unwrapped bare types. <br />""></a></h4><h4 id="use-init-to-declare-reactive-state-functions-like-watch-watcheffect-and-lifecycle-hooks-like-onmounted-onbeforemount-etc-do-assignments-of-reactive-properties-since-init-already-has-access-to-reactive-state-through-this" tabindex="-1">Use <code>.init()</code> to declare reactive state functions like <code>watch</code>, <code>watchEffect</code>, and lifecycle hooks like <code>onMounted</code>, <code>onBeforeMount</code> etc, do assignments of reactive properties, since <code>init()</code> already has access to <code>reactive()</code> state through <code>this</code>.<br> <a class="header-anchor" href="#use-init-to-declare-reactive-state-functions-like-watch-watcheffect-and-lifecycle-hooks-like-onmounted-onbeforemount-etc-do-assignments-of-reactive-properties-since-init-already-has-access-to-reactive-state-through-this" aria-label="Permalink to "Use \`.init()\` to declare reactive state functions like \`watch\`, \`watchEffect\`, and lifecycle hooks like \`onMounted\`, \`onBeforeMount\` etc, do assignments of reactive properties, since \`init()\` already has access to \`reactive()\` state through \`this\`.<br />""></a></h4><hr><p>Inside the <code>constructor()</code> method you still have access to non-reactive state, because when <code>constructor()</code> is initialized, it does NOT yet have access to the reactive properties of the class, since it was not yet converted to <code>reactive()</code> by <code>ivue</code>, so if you use the properties like Refs or ComputedRefs inside <code>constructor()</code> you would have to use them with the <code>.value</code>.</p><p>As a general rule, there is no need to manipulate the values in the <code>constructor()</code>, use constructor only for assigning the properties and casting the types of those assigned properties to the unwrapped (de-Refed) final state of the resulting <code>reactive()</code> object.</p><p><strong>Let's look at a <code>constructor()</code> vs <code>.init()</code> example:</strong></p><div class="vp-code-group vp-adaptive-theme"><div class="tabs"><input type="radio" name="group-UgXuH" id="tab-hvXWMZk" checked><label for="tab-hvXWMZk">CounterExternalRefsDetailed.vue</label></div><div class="blocks"><div class="language-vue vp-adaptive-theme active line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">vue</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">script</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setup</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> lang</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"ts"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
60
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { onMounted, ref } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'vue'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
61
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { ivue } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'ivue'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
62
|
+
<span class="line"></span>
|
|
63
|
+
<span class="line highlighted"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SpanRef</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> HTMLElement</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> null</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
64
|
+
<span class="line"></span>
|
|
65
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Counter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
66
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> constructor</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> span</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SpanRef</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
|
|
67
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Do not do this in the constructor() because this.span </span></span>
|
|
68
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // still refers to this.span.value here:</span></span>
|
|
69
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // onMounted(() => { </span></span>
|
|
70
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // (this.span as HTMLElement /*❌*/).innerHTML = 'Initial span text!';</span></span>
|
|
71
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // });</span></span>
|
|
72
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
73
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> init</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
74
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Do this inside init() because this.span (.value) is now</span></span>
|
|
75
|
+
<span class="line highlighted"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // flattened & (this) is now reactive():</span></span>
|
|
76
|
+
<span class="line highlighted"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> onMounted</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
|
77
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.span </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> HTMLElement</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/*✅*/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">).innerHTML </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'Initial span text!'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
78
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span>
|
|
79
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
80
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
81
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
|
82
|
+
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
|
|
83
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.span </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> HTMLElement</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">).innerHTML </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> String</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">this</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
|
|
84
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
|
85
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
|
|
86
|
+
<span class="line"></span>
|
|
87
|
+
<span class="line highlighted"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> span</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">SpanRef</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>();</span></span>
|
|
88
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> counter</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ivue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span></span>
|
|
89
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Counter,</span></span>
|
|
90
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> span </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">as</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> unknown</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> SpanRef</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /** Unwrap Ref Manually */</span></span>
|
|
91
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
|
|
92
|
+
<span class="line"></span>
|
|
93
|
+
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">defineExpose</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Counter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>(counter);</span></span>
|
|
94
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">script</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
95
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
96
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">a</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> href</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"javascript:void(0)"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> @</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">click</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> counter.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>Increment</</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">a</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
97
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Count: {{ counter.count }} <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">br</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /></span></span>
|
|
98
|
+
<span class="line highlighted"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">span</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ref</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"span"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">span</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
99
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br></div></div></div></div><details class="details custom-block"><summary>For this example we initialize the component like this:</summary><div class="language-vue vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">vue</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
100
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> <</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">CounterExternalRefsDetailed</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /></span></span>
|
|
101
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"></</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">template</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></div></details><div style="font-size:18px;font-weight:500;">Result</div>`,21),A=d('<h2 id="unwrapping-refs" tabindex="-1">Unwrapping Refs <a class="header-anchor" href="#unwrapping-refs" aria-label="Permalink to "Unwrapping Refs""></a></h2><p>The key to working with <code>ivue</code> is understanding correctly the way Vue 3 does automatic Unwrapping of Refs when they are passed into the <code>reactive()</code> object. In that regard we are not relying on some magic <code>ivue</code> behavior but rather the default behavior of <code>reactive()</code> Vue 3 function.</p><p>To match that unwrapping behavior, our class needs to Unwrap (or de-Ref) the types of Composables, Refs, ComputedRefs, if they are being passed into the constructor, to get their raw basic types those Refs are pointing to, so that you can start operating in the <code>ivue</code> environment, where there is no need to worry about <code>.value</code>. This unwrapping should be mainly done inside the <code>constructor()</code> method.</p><h2 id="naming-conventions" tabindex="-1">Naming Conventions <a class="header-anchor" href="#naming-conventions" aria-label="Permalink to "Naming Conventions""></a></h2><p>To benefit from the full power of <code>ivue</code>, it is recommended to extract the classes into separate files. What has been an effective pattern is to name the classes and put them right beside components in the same folder that these classes are being used with. So if you have <code>CounterComponent.vue</code> component, it can have a class inside <code>CounterComponentClass.ts</code>, and you can store props, emits, and other runtime definitions inside <code>CounterComponentProps.ts</code>.</p>',5),w=JSON.parse('{"title":"Guidelines","description":"","frontmatter":{},"headers":[],"relativePath":"pages/guidelines.md","filePath":"pages/guidelines.md"}'),C={name:"pages/guidelines.md"},x=p({...C,setup(o){return(n,e)=>(k(),r("div",null,[D,b(m),A]))}});export{w as __pageData,x as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{d as e,c as i,o as t,a5 as s}from"./chunks/framework.CNtPHGsN.js";const a=s(`<h1 id="how-it-works" tabindex="-1">How it works? <a class="header-anchor" href="#how-it-works" aria-label="Permalink to "How it works?""></a></h1><h2 id="what-ivue-is-not" tabindex="-1">What ivue is NOT? <a class="header-anchor" href="#what-ivue-is-not" aria-label="Permalink to "What ivue is NOT?""></a></h2><p>To understand how ivue works and how it does it, it is important to understand what it does not do.</p><div class="info custom-block"><p class="custom-block-title"><code>ivue</code> is different from other class based libraries</p><p>— <code>ivue</code> does NOT inherit from a base class<br> — <code>ivue</code> does NOT use decorators to achieve its objectives<br> — <code>ivue</code> does NOT alter Vue 3 underlying behavior, but rather relies on it<br> — <code>ivue</code> is NOT the same as class components (though you can build components with it)</p></div><h2 id="how-it-works-1" tabindex="-1">How it works? <a class="header-anchor" href="#how-it-works-1" aria-label="Permalink to "How it works?""></a></h2><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> function</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ivue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">T</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> extends</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> AnyClass</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>(</span></span>
|
|
2
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> className</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> T</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
|
3
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ...</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> InferredArgs</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">T</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
4
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> IVue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">T</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></div><p>The main <code>ivue()</code> initializer function uses TypeScript to be able to infer and validate the constrcutor argument types of <code>AnyClass</code> and passes those arguments to the constructor of <code>AnyClass</code>.</p><p><code>ivue</code> allows you to pass any number of arguments into the class <code>constructor(arg1, arg2, arg3, ...etc)</code></p><p><code>ivue()</code> initializer function returns an extended Vue 3 <code>reactive()</code> object in which getters and setters are internally converted to computeds and adds <code>.toRefs()</code> method to the created object. Computeds auto-unwrap themselves when they are accessed as a reactive object property, so the <code>.value</code> properties and computeds get flattened in the resulting object and do not require <code>.value</code> to be accessed.</p><p><code>ivue</code> replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.</p><p><code>ivue</code> aims to be opaque and minimal, just doing the minimum to convert a class to a reactive object, leaving the rest to be implemented using Vue 3 Composition API inside an initializer function called <code>.init()</code></p><h2 id="usage-recommendation" tabindex="-1">Usage Recommendation <a class="header-anchor" href="#usage-recommendation" aria-label="Permalink to "Usage Recommendation""></a></h2><p><code>ivue</code> recommends all class properties to be defined as <code>ref()</code> to be able to interoperate with <code>defineExpose()</code>, if you simply pass reactive props which are not Refs through <code>defineExpose()</code>, they will lose reactivity. <code>ref()</code> refs just like computed refs get flattened into the <code>reactive()</code> object, so there is no need to worry about using <code>.value</code>. The <code>ref()</code> refs are necessary just internally for Vue 3 to know which refs to keep reactive, and we just convert the types back to their normal types as if they have no reactivity at all, so <code>Ref<number></code> is <code>number</code> in <code>ivue</code>, so rather than going in the direction of complexifying the types, we are going in the opposite direction towards simplification.</p><p><code>ivue</code> recommends all class functions, getters and setters to be defined in plain full function style (not arrow functions), this allows all <code>ivue</code> classes to be extensible at any point. By using plain standard functions, getters and setters allows for any getter, setter, function or property to be overriden by extending this class. Arrow functions break full extensibility of classes, so avoid using them inside of classes.</p><p>See: <a href="/ivue/pages/guidelines.html">More Guidelines</a></p><h2 id="minimal-api-surface-area" tabindex="-1">Minimal API Surface Area <a class="header-anchor" href="#minimal-api-surface-area" aria-label="Permalink to "Minimal API Surface Area""></a></h2><p><code>ivue()</code> initializer function is the main API<br><code>.init()</code> method helps initialize the reactive state like <code>watch</code>, <code>onMount</code>, etc.<br><code>.toRefs()</code> method allows to interoperate with Vue 3 Composables<br> Utility Types help to achieve the rest of <code>ivue</code> capabilities</p><details class="details custom-block"><summary>Click to see the whole latest <code>ivue</code> source code from github main branch below:</summary><div class="vp-code-group vp-adaptive-theme"><div class="tabs"><input type="radio" name="group-vjsvp" id="tab-SbEpbcc" checked><label for="tab-SbEpbcc">ivue.ts</label></div><div class="blocks"><div class="language-ts vp-adaptive-theme active line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> './ivue'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div></div></div></details><p>Or <a href="https://github.com/infinite-system/ivue/blob/main/src/index.ts" target="_blank" rel="noreferrer">See on GitHub</a></p><h2 id="_100-vue-3-compatible" tabindex="-1">100% Vue 3 Compatible <a class="header-anchor" href="#_100-vue-3-compatible" aria-label="Permalink to "100% Vue 3 Compatible""></a></h2><p><code>.toRefs()</code> allows the object to be converted to Vue 3 native composable structure with full <code>.value</code>s, so it can interoperate with native composables if needed. <code>.toRefs()</code> is also often used to get refs for <code>v-bind()</code> in css styles.</p><h2 id="_100-typescript-support" tabindex="-1">100% TypeScript Support <a class="header-anchor" href="#_100-typescript-support" aria-label="Permalink to "100% TypeScript Support""></a></h2><p><code>ivue</code> is on the cutting edge of TypeScript and owes its capabilities to the latest developments in TypeScript.</p><p><code>ivue</code> provides a set of utility types to make working with <code>Vue 3</code> even easier and more scalable.</p><h2 id="_100-unit-tested-architecture" tabindex="-1">100% Unit Tested Architecture <a class="header-anchor" href="#_100-unit-tested-architecture" aria-label="Permalink to "100% Unit Tested Architecture""></a></h2><p>At the current stage all of the code that is used to build <code>ivue</code> is 100% tested with 100% coverage, and aims to keep being at 100% always.</p><p>You can clone the project and run <code>yarn test</code> yourself and examine the tests.</p><h2 id="zero-dependencies" tabindex="-1">Zero Dependencies <a class="header-anchor" href="#zero-dependencies" aria-label="Permalink to "Zero Dependencies""></a></h2><p><code>ivue</code> has zero dependencies except Vue 3.</p>`,29),o=[a],h=JSON.parse('{"title":"How it works?","description":"","frontmatter":{},"headers":[],"relativePath":"pages/how-it-works.md","filePath":"pages/how-it-works.md"}'),n={name:"pages/how-it-works.md"},p=e({...n,setup(r){return(c,d)=>(t(),i("div",null,o))}});export{h as __pageData,p as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{d as e,c as i,o as t,a5 as s}from"./chunks/framework.CNtPHGsN.js";const a=s(`<h1 id="how-it-works" tabindex="-1">How it works? <a class="header-anchor" href="#how-it-works" aria-label="Permalink to "How it works?""></a></h1><h2 id="what-ivue-is-not" tabindex="-1">What ivue is NOT? <a class="header-anchor" href="#what-ivue-is-not" aria-label="Permalink to "What ivue is NOT?""></a></h2><p>To understand how ivue works and how it does it, it is important to understand what it does not do.</p><div class="info custom-block"><p class="custom-block-title"><code>ivue</code> is different from other class based libraries</p><p>— <code>ivue</code> does NOT inherit from a base class<br> — <code>ivue</code> does NOT use decorators to achieve its objectives<br> — <code>ivue</code> does NOT alter Vue 3 underlying behavior, but rather relies on it<br> — <code>ivue</code> is NOT the same as class components (though you can build components with it)</p></div><h2 id="how-it-works-1" tabindex="-1">How it works? <a class="header-anchor" href="#how-it-works-1" aria-label="Permalink to "How it works?""></a></h2><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> function</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ivue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">T</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> extends</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> AnyClass</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">>(</span></span>
|
|
2
|
+
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> className</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> T</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
|
3
|
+
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ...</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> InferredArgs</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">T</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span>
|
|
4
|
+
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> IVue</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">T</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">></span></span></code></pre></div><p>The main <code>ivue()</code> initializer function uses TypeScript to be able to infer and validate the constrcutor argument types of <code>AnyClass</code> and passes those arguments to the constructor of <code>AnyClass</code>.</p><p><code>ivue</code> allows you to pass any number of arguments into the class <code>constructor(arg1, arg2, arg3, ...etc)</code></p><p><code>ivue()</code> initializer function returns an extended Vue 3 <code>reactive()</code> object in which getters and setters are internally converted to computeds and adds <code>.toRefs()</code> method to the created object. Computeds auto-unwrap themselves when they are accessed as a reactive object property, so the <code>.value</code> properties and computeds get flattened in the resulting object and do not require <code>.value</code> to be accessed.</p><p><code>ivue</code> replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.</p><p><code>ivue</code> aims to be opaque and minimal, just doing the minimum to convert a class to a reactive object, leaving the rest to be implemented using Vue 3 Composition API inside an initializer function called <code>.init()</code></p><h2 id="usage-recommendation" tabindex="-1">Usage Recommendation <a class="header-anchor" href="#usage-recommendation" aria-label="Permalink to "Usage Recommendation""></a></h2><p><code>ivue</code> recommends all class properties to be defined as <code>ref()</code> to be able to interoperate with <code>defineExpose()</code>, if you simply pass reactive props which are not Refs through <code>defineExpose()</code>, they will lose reactivity. <code>ref()</code> refs just like computed refs get flattened into the <code>reactive()</code> object, so there is no need to worry about using <code>.value</code>. The <code>ref()</code> refs are necessary just internally for Vue 3 to know which refs to keep reactive, and we just convert the types back to their normal types as if they have no reactivity at all, so <code>Ref<number></code> is <code>number</code> in <code>ivue</code>, so rather than going in the direction of complexifying the types, we are going in the opposite direction towards simplification.</p><p><code>ivue</code> recommends all class functions, getters and setters to be defined in plain full function style (not arrow functions), this allows all <code>ivue</code> classes to be extensible at any point. By using plain standard functions, getters and setters allows for any getter, setter, function or property to be overriden by extending this class. Arrow functions break full extensibility of classes, so avoid using them inside of classes.</p><p>See: <a href="/ivue/pages/guidelines.html">More Guidelines</a></p><h2 id="minimal-api-surface-area" tabindex="-1">Minimal API Surface Area <a class="header-anchor" href="#minimal-api-surface-area" aria-label="Permalink to "Minimal API Surface Area""></a></h2><p><code>ivue()</code> initializer function is the main API<br><code>.init()</code> method helps initialize the reactive state like <code>watch</code>, <code>onMount</code>, etc.<br><code>.toRefs()</code> method allows to interoperate with Vue 3 Composables<br> Utility Types help to achieve the rest of <code>ivue</code> capabilities</p><details class="details custom-block"><summary>Click to see the whole latest <code>ivue</code> source code from github main branch below:</summary><div class="vp-code-group vp-adaptive-theme"><div class="tabs"><input type="radio" name="group-vjsvp" id="tab-SbEpbcc" checked><label for="tab-SbEpbcc">ivue.ts</label></div><div class="blocks"><div class="language-ts vp-adaptive-theme active line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> './ivue'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div></div></div></details><p>Or <a href="https://github.com/infinite-system/ivue/blob/main/src/index.ts" target="_blank" rel="noreferrer">See on GitHub</a></p><h2 id="_100-vue-3-compatible" tabindex="-1">100% Vue 3 Compatible <a class="header-anchor" href="#_100-vue-3-compatible" aria-label="Permalink to "100% Vue 3 Compatible""></a></h2><p><code>.toRefs()</code> allows the object to be converted to Vue 3 native composable structure with full <code>.value</code>s, so it can interoperate with native composables if needed. <code>.toRefs()</code> is also often used to get refs for <code>v-bind()</code> in css styles.</p><h2 id="_100-typescript-support" tabindex="-1">100% TypeScript Support <a class="header-anchor" href="#_100-typescript-support" aria-label="Permalink to "100% TypeScript Support""></a></h2><p><code>ivue</code> is on the cutting edge of TypeScript and owes its capabilities to the latest developments in TypeScript.</p><p><code>ivue</code> provides a set of utility types to make working with <code>Vue 3</code> even easier and more scalable.</p><h2 id="_100-unit-tested-architecture" tabindex="-1">100% Unit Tested Architecture <a class="header-anchor" href="#_100-unit-tested-architecture" aria-label="Permalink to "100% Unit Tested Architecture""></a></h2><p>At the current stage all of the code that is used to build <code>ivue</code> is 100% tested with 100% coverage, and aims to keep being at 100% always.</p><p>You can clone the project and run <code>yarn test</code> yourself and examine the tests.</p><h2 id="zero-dependencies" tabindex="-1">Zero Dependencies <a class="header-anchor" href="#zero-dependencies" aria-label="Permalink to "Zero Dependencies""></a></h2><p><code>ivue</code> has zero dependencies except Vue 3.</p>`,29),o=[a],h=JSON.parse('{"title":"How it works?","description":"","frontmatter":{},"headers":[],"relativePath":"pages/how-it-works.md","filePath":"pages/how-it-works.md"}'),n={name:"pages/how-it-works.md"},p=e({...n,setup(r){return(c,d)=>(t(),i("div",null,o))}});export{h as __pageData,p as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,c as o,o as t,a5 as a}from"./chunks/framework.CNtPHGsN.js";const f=JSON.parse(`{"title":"How it's made","description":"","frontmatter":{},"headers":[],"relativePath":"pages/how-its-made.md","filePath":"pages/how-its-made.md"}`),i={name:"pages/how-its-made.md"},s=a('<h1 id="how-it-s-made" tabindex="-1">How it's made <a class="header-anchor" href="#how-it-s-made" aria-label="Permalink to "How it's made""></a></h1><h2 id="original-inspiration" tabindex="-1">Original Inspiration <a class="header-anchor" href="#original-inspiration" aria-label="Permalink to "Original Inspiration""></a></h2><p>The original inspiration for <code>ivue</code> comes from <code>MobX</code> React state management library, where something similar is attempted to create a class based reactive observable architecture.</p><h2 id="epiphany" tabindex="-1">Epiphany <a class="header-anchor" href="#epiphany" aria-label="Permalink to "Epiphany""></a></h2><p>After building several ports from <code>MobX</code> state management library to <code>VueJS</code> to reactivity system I realized that Vue itself is far superior in its design and perfomance and can solve the same problem without relying on second hand-library, but for that my evolution of understanding of how JavaScript getters and setters work needed to happen.</p><p>And one lucky and sunny day driving back from work in an eureka moment of light it occured to me how to use Vue 3 computeds in place of getters in classes (Yes, apparently my brain does coding while driving a car).</p><p><code>ivue</code> relies on this very simple discovery of how to elegantly convert getters into Vue 3 computeds.</p><h2 id="simplicity" tabindex="-1">Simplicity <a class="header-anchor" href="#simplicity" aria-label="Permalink to "Simplicity""></a></h2><p>After many iterations where I created a whole inversion of control library for <code>ivue</code>, using lots of different decorators and event Traits, I realized that simplicity is paramount to good architecture.</p><p>In that sweep of clarity, I got rid of 95% of the code that was just extra stuff and not the essence and left only <code>3</code> core functions: <code>ivue()</code>, <code>.init()</code>, <code>.toRefs()</code> only which are necessary to do everything <code>ivue</code> is set out to do.</p><p>Use Composition API composables inside <code>init()</code> function.</p><h2 id="minimalism" tabindex="-1">Minimalism <a class="header-anchor" href="#minimalism" aria-label="Permalink to "Minimalism""></a></h2><p>Thus <code>ivue</code> has minimal surface area of the API making it very robust and easy to test. By default <code>ivue</code> does not rely on decorators, though you can use decorators if you wish to.</p><h2 id="the-rest-is-up-to-you" tabindex="-1">The Rest is Up To You <a class="header-anchor" href="#the-rest-is-up-to-you" aria-label="Permalink to "The Rest is Up To You""></a></h2><p><code>ivue</code> is like a small mustard seed core for the big tree trunk of Class Based Reactive applications to be built around it, that's why the path of utter simplicity was chosen. Everything else like an Inversion of Control (IOC) system, Traits, Mixins, Decorators can be built around the core <code>ivue</code> architecture and is upto the community of enthusiatic open source contributors, please share with us your vision of how you and all of can use <code>ivue</code> better.</p>',15),r=[s];function n(c,d,l,h,u,p){return t(),o("div",null,r)}const y=e(i,[["render",n]]);export{f as __pageData,y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,c as o,o as t,a5 as a}from"./chunks/framework.CNtPHGsN.js";const f=JSON.parse(`{"title":"How it's made","description":"","frontmatter":{},"headers":[],"relativePath":"pages/how-its-made.md","filePath":"pages/how-its-made.md"}`),i={name:"pages/how-its-made.md"},s=a("",15),r=[s];function n(c,d,l,h,u,p){return t(),o("div",null,r)}const y=e(i,[["render",n]]);export{f as __pageData,y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as i}from"./chunks/Button.vue_vue_type_script_setup_true_lang.P7niV-n8.js";import{d as o,c as a,j as e,a as t,I as s,a5 as n,o as c}from"./chunks/framework.CNtPHGsN.js";const r=n('<h1 id="what-is-infinite-vue" tabindex="-1">What is Infinite Vue? <a class="header-anchor" href="#what-is-infinite-vue" aria-label="Permalink to "What is Infinite Vue?""></a></h1><h2 id="the-problem" tabindex="-1">The Problem <a class="header-anchor" href="#the-problem" aria-label="Permalink to "The Problem""></a></h2><p>With the development of React hooks and Vue following in its footsteps with introduction of Vue 3 Composition API, the ecosystem has moved away from Options API.</p><p>While providing greater flexibility and composability the Composition API has its own downsides, one of them is having to use <code>.value</code> to refer to the reactive variables which makes the development process more clunky when the App reaches a certain size.</p><p>As you may know, <code>reactvity-transform</code> macros were an attempt to mitigate those issues, which turned out to create even more issues, and was discontinued.</p><p>See: <a href="https://vuejs.org/guide/extras/reactivity-transform.html" target="_blank" rel="noreferrer">VueJs.org – Reactivity Transform</a></p><h2 id="ivue-is" tabindex="-1"><code>ivue</code> is <a class="header-anchor" href="#ivue-is" aria-label="Permalink to "`ivue` is""></a></h2><div style="padding-left:20px;font-size:1.2rem;line-height:2rem;"> – Simple like Options API<br> – Flexible like Composition API<br> – Extensible like TypeScript Classes API<br></div><p><code>ivue</code> is a powerful tool because it fully aligns itself with JavaScript / TypeScript Class API.</p><p><code>ivue</code> gives you a class based Composable capabilities with Inheritance and all the power of TypeScript Classes.</p><p><code>ivue</code> mitigates the downsides of both Composition API and Options API, uses only their strengths and brings back Object Oriented Programming to allow the development of complex and scalable apps.</p><p><code>ivue</code> is fully interoperable with Composition API and does not work against, but rather with it, so you can use all of ecosystems composables seamlessly.</p><p><code>ivue</code> also offers a set of functions and utility types to make extensible & exportable props defaults, extensible emits and extensible slots possible.</p><h2 id="classes-in-the-ecosystem" tabindex="-1">Classes in the Ecosystem <a class="header-anchor" href="#classes-in-the-ecosystem" aria-label="Permalink to "Classes in the Ecosystem""></a></h2><p>With failed implementations of classes in React and also failed implementations using class components in Vue 2 / 3, the ecosystem decided that classes are bad and moved to pure procedural designs.</p><p>While procedural programming has its strength, it also comes with its own weaknesses, like lack of inheritance, lack of <code>this</code> context, and thus lack of true composition.</p><div class="info custom-block"><p class="custom-block-title">IVUE IS DIFFERENT</p><p>– <code>ivue</code> does NOT inherit from a base class<br> – <code>ivue</code> does NOT use decorators to achieve its objectives<br> – <code>ivue</code> does NOT alter Vue 3 underlying behavior<br> – <code>ivue</code> is NOT the same as class components (though you can build components with it)<br></p></div><h2 id="infinite-vue-class-achitecture" tabindex="-1">Infinite Vue Class Achitecture <a class="header-anchor" href="#infinite-vue-class-achitecture" aria-label="Permalink to "Infinite Vue Class Achitecture""></a></h2><p><code>ivue</code> replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.</p><p>By using TypeScript we are able to infer the arguments of the main <code>ivue()</code> initializer function and pass the arguments to the constructor.</p><p><code>ivue()</code> initializer function returns a reactive object with getters converted to computeds and adds <code>.toRefs()</code> method to the object, <code>.toRefs()</code> allows the object to be converted to native composable structure, so it can interoperate as a composable if needed.</p><p><code>ivue</code> aims to be opaque and minimal, just doing the minimum to convert a class to a reactive object, leaving the rest to be implemented using Vue 3 Composition API inside an initializer function called <code>.init()</code></p>',22),l=e("code",null,"ivue",-1),d=e("h2",{id:"when-to-use-infinite-vue",tabindex:"-1"},[t("When to use Infinite Vue? "),e("a",{class:"header-anchor",href:"#when-to-use-infinite-vue","aria-label":'Permalink to "When to use Infinite Vue?"'},"")],-1),h=e("p",null,[t("When the complexity of your app or components becomes very high using "),e("code",null,"ivue"),t(" can become a natural choice to deal with that complexity. Because "),e("code",null,".value"),t(" is abstracted away in "),e("code",null,"ivue"),t(", everything is simply a reactive object of Refs.")],-1),g=JSON.parse('{"title":"What is Infinite Vue?","description":"","frontmatter":{},"headers":[],"relativePath":"pages/introduction.md","filePath":"pages/introduction.md"}'),p={name:"pages/introduction.md"},y=o({...p,setup(u){return(m,f)=>(c(),a("div",null,[r,e("p",null,[t("You can read more about "),l,t(" internal architecture in "),s(i,{href:"/pages/how-it-works",label:"How it works?"}),t(" page.")]),d,h]))}});export{g as __pageData,y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as i}from"./chunks/Button.vue_vue_type_script_setup_true_lang.P7niV-n8.js";import{d as o,c as a,j as e,a as t,I as s,a5 as n,o as c}from"./chunks/framework.CNtPHGsN.js";const r=n('<h1 id="what-is-infinite-vue" tabindex="-1">What is Infinite Vue? <a class="header-anchor" href="#what-is-infinite-vue" aria-label="Permalink to "What is Infinite Vue?""></a></h1><h2 id="the-problem" tabindex="-1">The Problem <a class="header-anchor" href="#the-problem" aria-label="Permalink to "The Problem""></a></h2><p>With the development of React hooks and Vue following in its footsteps with introduction of Vue 3 Composition API, the ecosystem has moved away from Options API.</p><p>While providing greater flexibility and composability the Composition API has its own downsides, one of them is having to use <code>.value</code> to refer to the reactive variables which makes the development process more clunky when the App reaches a certain size.</p><p>As you may know, <code>reactvity-transform</code> macros were an attempt to mitigate those issues, which turned out to create even more issues, and was discontinued.</p><p>See: <a href="https://vuejs.org/guide/extras/reactivity-transform.html" target="_blank" rel="noreferrer">VueJs.org – Reactivity Transform</a></p><h2 id="ivue-is" tabindex="-1"><code>ivue</code> is <a class="header-anchor" href="#ivue-is" aria-label="Permalink to "`ivue` is""></a></h2><div style="padding-left:20px;font-size:1.2rem;line-height:2rem;"> – Simple like Options API<br> – Flexible like Composition API<br> – Extensible like TypeScript Classes API<br></div><p><code>ivue</code> is a powerful tool because it fully aligns itself with JavaScript / TypeScript Class API.</p><p><code>ivue</code> gives you a class based Composable capabilities with Inheritance and all the power of TypeScript Classes.</p><p><code>ivue</code> mitigates the downsides of both Composition API and Options API, uses only their strengths and brings back Object Oriented Programming to allow the development of complex and scalable apps.</p><p><code>ivue</code> is fully interoperable with Composition API and does not work against, but rather with it, so you can use all of ecosystems composables seamlessly.</p><p><code>ivue</code> also offers a set of functions and utility types to make extensible & exportable props defaults, extensible emits and extensible slots possible.</p><h2 id="classes-in-the-ecosystem" tabindex="-1">Classes in the Ecosystem <a class="header-anchor" href="#classes-in-the-ecosystem" aria-label="Permalink to "Classes in the Ecosystem""></a></h2><p>With failed implementations of classes in React and also failed implementations using class components in Vue 2 / 3, the ecosystem decided that classes are bad and moved to pure procedural designs.</p><p>While procedural programming has its strength, it also comes with its own weaknesses, like lack of inheritance, lack of <code>this</code> context, and thus lack of true composition.</p><div class="info custom-block"><p class="custom-block-title">IVUE IS DIFFERENT</p><p>– <code>ivue</code> does NOT inherit from a base class<br> – <code>ivue</code> does NOT use decorators to achieve its objectives<br> – <code>ivue</code> does NOT alter Vue 3 underlying behavior<br> – <code>ivue</code> is NOT the same as class components (though you can build components with it)<br></p></div><h2 id="infinite-vue-class-achitecture" tabindex="-1">Infinite Vue Class Achitecture <a class="header-anchor" href="#infinite-vue-class-achitecture" aria-label="Permalink to "Infinite Vue Class Achitecture""></a></h2><p><code>ivue</code> replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.</p><p>By using TypeScript we are able to infer the arguments of the main <code>ivue()</code> initializer function and pass the arguments to the constructor.</p><p><code>ivue()</code> initializer function returns a reactive object with getters converted to computeds and adds <code>.toRefs()</code> method to the object, <code>.toRefs()</code> allows the object to be converted to native composable structure, so it can interoperate as a composable if needed.</p><p><code>ivue</code> aims to be opaque and minimal, just doing the minimum to convert a class to a reactive object, leaving the rest to be implemented using Vue 3 Composition API inside an initializer function called <code>.init()</code></p>',22),l=e("code",null,"ivue",-1),d=e("h2",{id:"when-to-use-infinite-vue",tabindex:"-1"},[t("When to use Infinite Vue? "),e("a",{class:"header-anchor",href:"#when-to-use-infinite-vue","aria-label":'Permalink to "When to use Infinite Vue?"'},"")],-1),h=e("p",null,[t("When the complexity of your app or components becomes very high using "),e("code",null,"ivue"),t(" can become a natural choice to deal with that complexity. Because "),e("code",null,".value"),t(" is abstracted away in "),e("code",null,"ivue"),t(", everything is simply a reactive object of Refs.")],-1),g=JSON.parse('{"title":"What is Infinite Vue?","description":"","frontmatter":{},"headers":[],"relativePath":"pages/introduction.md","filePath":"pages/introduction.md"}'),p={name:"pages/introduction.md"},y=o({...p,setup(u){return(m,f)=>(c(),a("div",null,[r,e("p",null,[t("You can read more about "),l,t(" internal architecture in "),s(i,{href:"/pages/how-it-works",label:"How it works?"}),t(" page.")]),d,h]))}});export{g as __pageData,y as default};
|