ivue 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -8
- package/coverage/clover.xml +174 -160
- package/coverage/coverage-final.json +1 -1
- package/coverage/index.html +18 -18
- package/coverage/{index.ts.html → ivue.ts.html} +221 -32
- package/dist/index.es.js +18 -18
- package/dist/index.umd.js +1 -1
- package/dist/src/ivue.d.ts +19 -13
- package/docs/docs/.vitepress/config.ts +10 -4
- package/docs/docs/.vitepress/dist/404.html +3 -3
- package/docs/docs/.vitepress/dist/api/ivue.html +7 -7
- package/docs/docs/.vitepress/dist/api/propsWithDefaults.html +7 -7
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.CZqok1oO.js → api_ivue.md.DyFbv52x.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.CZqok1oO.lean.js → api_ivue.md.DyFbv52x.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.DEcLH0d7.lean.js → api_propsWithDefaults.md.C6C7ZBZl.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.DEcLH0d7.js → api_propsWithDefaults.md.C6C7ZBZl.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{app.B0XSXAbt.js → app.CQ7kL6_f.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.DPHmCl-3.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/{Button.vue_vue_type_script_setup_true_lang.CPdVloYP.js → Button.vue_vue_type_script_setup_true_lang.Bynntqk6.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/{VPLocalSearchBox.Cy60THbt.js → VPLocalSearchBox.hM-bvSJA.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/framework.CvEKxEoK.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.BJUrCfJB.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/{theme.CU9x1gi1.js → theme.BQo6cm_A.js} +2 -2
- package/docs/docs/.vitepress/dist/assets/index.md.D-9TpgnJ.js +1 -0
- package/docs/docs/.vitepress/dist/assets/index.md.D-9TpgnJ.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/{pages_advanced-usage.md.BdjYKyP7.js → pages_advanced-usage.md.DsU0E8Oi.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_advanced-usage.md.BdjYKyP7.lean.js → pages_advanced-usage.md.DsU0E8Oi.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.CElVfYwg.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_api.md.CElVfYwg.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.BTo1NnoD.js → pages_browse-code.md.DhMpWRNv.js} +34 -27
- package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.BTo1NnoD.lean.js → pages_browse-code.md.DhMpWRNv.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.pKbgyjOJ.js → pages_getting-started.md.CRguJKe8.js} +35 -28
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.pKbgyjOJ.lean.js → pages_getting-started.md.CRguJKe8.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.e9uCeWU_.lean.js → pages_guidelines.md.yUFCB7mz.js} +19 -13
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.e9uCeWU_.js → pages_guidelines.md.yUFCB7mz.lean.js} +19 -13
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.DjBxE3iI.lean.js → pages_how-it-works.md.DDKhyGlo.js} +35 -28
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.DjBxE3iI.js → pages_how-it-works.md.DDKhyGlo.lean.js} +35 -28
- package/docs/docs/.vitepress/dist/assets/{pages_how-its-made.md.DGeFDBuv.js → pages_how-its-made.md.CCol99CD.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_how-its-made.md.DGeFDBuv.lean.js → pages_how-its-made.md.CCol99CD.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.CCkiQtfX.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.CCkiQtfX.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.CdQ0bAt8.js → pages_usage.md.EDa7wXde.js} +82 -32
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.CdQ0bAt8.lean.js → pages_usage.md.EDa7wXde.lean.js} +82 -32
- package/docs/docs/.vitepress/dist/assets/{style.Fgx7OB_D.css → style.Dtxde_a0.css} +1 -1
- package/docs/docs/.vitepress/dist/hashmap.json +1 -1
- package/docs/docs/.vitepress/dist/index.html +9 -9
- package/docs/docs/.vitepress/dist/pages/advanced-usage.html +7 -7
- package/docs/docs/.vitepress/dist/pages/api.html +9 -9
- package/docs/docs/.vitepress/dist/pages/browse-code.html +40 -33
- package/docs/docs/.vitepress/dist/pages/getting-started.html +41 -34
- package/docs/docs/.vitepress/dist/pages/guidelines.html +25 -19
- package/docs/docs/.vitepress/dist/pages/how-it-works.html +41 -34
- package/docs/docs/.vitepress/dist/pages/how-its-made.html +7 -7
- package/docs/docs/.vitepress/dist/pages/introduction.html +9 -9
- package/docs/docs/.vitepress/dist/pages/usage.html +88 -38
- package/docs/docs/.vitepress/theme/main.css +1 -1
- package/docs/docs/components/guidelines/CounterExternalRefsDetailed.vue +5 -5
- package/docs/docs/components/usage/CounterComposables.vue +10 -2
- package/docs/docs/components/usage/CounterComposablesDestructuring.vue +3 -3
- package/docs/docs/components/usage/CounterComposablesIvueDestructuring.vue +36 -0
- package/docs/docs/components/usage/CounterExternalRefs.vue +3 -3
- package/docs/docs/components/usage/classes/CustomMouse.ts +18 -0
- package/docs/docs/components/usage/functions/useCustomMouse.ts +31 -0
- package/docs/docs/index.md +37 -17
- package/docs/docs/pages/api.md +13 -13
- package/docs/docs/pages/guidelines.md +12 -6
- package/docs/docs/pages/how-it-works.md +24 -10
- package/docs/docs/pages/how-its-made.md +1 -1
- package/docs/docs/pages/introduction.md +10 -3
- package/docs/docs/pages/usage.md +24 -2
- package/docs/package.json +1 -1
- package/package.json +1 -1
- package/src/__tests__/ivue.vitest.spec.ts +22 -21
- package/src/ivue.ts +30 -17
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.c4Gx9TYS.js +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/framework.DwpdbuZp.js +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.Dhu93bg7.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.CLB_U8aI.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.CLB_U8aI.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.-RSHq6PR.js +0 -7
- package/docs/docs/.vitepress/dist/assets/pages_api.md.-RSHq6PR.lean.js +0 -7
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.BdBoAz6L.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.BdBoAz6L.lean.js +0 -1
- package/docs/docs/components/usage/functions/useMouse.ts +0 -26
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { onMounted, ref } from 'vue';
|
|
3
|
-
import { ivue } from 'ivue';
|
|
3
|
+
import { ivue, iref, iuse } from 'ivue';
|
|
4
4
|
|
|
5
5
|
type SpanRef = HTMLElement | null;
|
|
6
6
|
|
|
7
7
|
class Counter {
|
|
8
|
-
constructor(public span
|
|
8
|
+
constructor(public span?: SpanRef) {
|
|
9
9
|
// Do not do this in the constructor() because this.span
|
|
10
10
|
// still refers to this.span.value here:
|
|
11
11
|
// onMounted(() => {
|
|
@@ -19,17 +19,17 @@ class Counter {
|
|
|
19
19
|
(this.span as HTMLElement/*✅*/).innerHTML = 'Initial span text!';
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
count =
|
|
22
|
+
count = iref(0);
|
|
23
23
|
increment() {
|
|
24
24
|
this.count++;
|
|
25
25
|
(this.span as HTMLElement).innerHTML = String(this.count + 1);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const span = ref<SpanRef>();
|
|
29
|
+
const span = ref<SpanRef>(null);
|
|
30
30
|
const counter = ivue(
|
|
31
31
|
Counter,
|
|
32
|
-
span
|
|
32
|
+
iuse(span)
|
|
33
33
|
);
|
|
34
34
|
|
|
35
35
|
defineExpose<Counter>(counter);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { useMouse } from '@vueuse/core';
|
|
2
|
+
import { useMouse, usePointer } from '@vueuse/core';
|
|
3
3
|
import { ivue, iref, iuse } from 'ivue';
|
|
4
4
|
|
|
5
5
|
class Counter {
|
|
@@ -8,6 +8,7 @@ class Counter {
|
|
|
8
8
|
this.count++;
|
|
9
9
|
}
|
|
10
10
|
mouse = iuse(useMouse());
|
|
11
|
+
pointer = iuse(usePointer());
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
const counter = ivue(Counter);
|
|
@@ -15,5 +16,12 @@ const counter = ivue(Counter);
|
|
|
15
16
|
<template>
|
|
16
17
|
<a href="javascript:void(0)" @click="() => counter.increment()">Increment</a>
|
|
17
18
|
Count: {{ counter.count }} <br />
|
|
18
|
-
|
|
19
|
+
<br />
|
|
20
|
+
Mouse: <br />
|
|
21
|
+
X: {{ counter.mouse.x }} <br />
|
|
22
|
+
Y: {{ counter.mouse.y }} <br />
|
|
23
|
+
<br />
|
|
24
|
+
Pointer: <br />
|
|
25
|
+
X: {{ counter.pointer.x }} <br />
|
|
26
|
+
Y: {{ counter.pointer.y }} <br />
|
|
19
27
|
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { useCustomMouse } from './functions/useCustomMouse';
|
|
3
3
|
|
|
4
4
|
import { ivue, iuse, iref, type UseComposable } from 'ivue';
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ import { ivue, iuse, iref, type UseComposable } from 'ivue';
|
|
|
7
7
|
* Use the ivue Utility Type: UseComposable<typeof YourComposableFunctionName>
|
|
8
8
|
* to get he resulting unwrapped composable properties and functions.
|
|
9
9
|
*/
|
|
10
|
-
type UseMouse = UseComposable<typeof
|
|
10
|
+
type UseMouse = UseComposable<typeof useCustomMouse>;
|
|
11
11
|
|
|
12
12
|
class Counter {
|
|
13
13
|
count = iref(0);
|
|
@@ -29,7 +29,7 @@ class Counter {
|
|
|
29
29
|
y: this.y,
|
|
30
30
|
sum: this.sum,
|
|
31
31
|
total: this.total
|
|
32
|
-
} = iuse(
|
|
32
|
+
} = iuse(useCustomMouse()));
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { CustomMouse } from './classes/CustomMouse';
|
|
3
|
+
|
|
4
|
+
import { ivue, iref, iuse } from 'ivue';
|
|
5
|
+
|
|
6
|
+
class Counter {
|
|
7
|
+
count = iref(0);
|
|
8
|
+
|
|
9
|
+
increment() {
|
|
10
|
+
this.count++;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// x, y are Refs that will be unwrapped and destructured into this class
|
|
14
|
+
x: CustomMouse['x']; // Unwrapped Ref<number> becomes -> number
|
|
15
|
+
y: CustomMouse['y']; // Unwrapped Ref<number> becomes -> number
|
|
16
|
+
total: CustomMouse['total']; // Unwrapped Ref<number> becomes -> number
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
({
|
|
20
|
+
x: this.x,
|
|
21
|
+
y: this.y,
|
|
22
|
+
total: this.total,
|
|
23
|
+
} = iuse(CustomMouse, 5));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const counter = ivue(Counter);
|
|
28
|
+
</script>
|
|
29
|
+
<template>
|
|
30
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">Increment</a>
|
|
31
|
+
Count: {{ counter.count }} <br />
|
|
32
|
+
Mouse X: {{ counter.x }}, Y: {{ counter.y }}
|
|
33
|
+
<br />
|
|
34
|
+
Total (computed): {{ counter.total }}
|
|
35
|
+
<br />
|
|
36
|
+
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref } from 'vue';
|
|
3
|
-
import { ivue, iref } from 'ivue';
|
|
3
|
+
import { ivue, iref, iuse } from 'ivue';
|
|
4
4
|
|
|
5
5
|
type SpanRef = HTMLElement | null;
|
|
6
6
|
|
|
@@ -13,8 +13,8 @@ class Counter {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const span = ref<SpanRef>();
|
|
17
|
-
const counter = ivue(Counter, span
|
|
16
|
+
const span = ref<SpanRef>(null);
|
|
17
|
+
const counter = ivue(Counter, iuse(span));
|
|
18
18
|
|
|
19
19
|
defineExpose<Counter>(counter);
|
|
20
20
|
</script>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMouse } from '@vueuse/core';
|
|
2
|
+
import { iuse, type UseComposable } from 'ivue';
|
|
3
|
+
|
|
4
|
+
type UseMouse = UseComposable<typeof useMouse>
|
|
5
|
+
|
|
6
|
+
export class CustomMouse {
|
|
7
|
+
|
|
8
|
+
x: UseMouse['x'];
|
|
9
|
+
y: UseMouse['y'];
|
|
10
|
+
|
|
11
|
+
constructor(public test: number) {
|
|
12
|
+
({ x: this.x, y: this.y } = iuse(useMouse()))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get total() {
|
|
16
|
+
return this.x + this.y;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { computed, ref } from 'vue';
|
|
2
|
+
import { useMouse } from '@vueuse/core';
|
|
3
|
+
|
|
4
|
+
export function useCustomMouse() {
|
|
5
|
+
const { x, y } = useMouse();
|
|
6
|
+
|
|
7
|
+
const _sum = ref(0);
|
|
8
|
+
|
|
9
|
+
function sum() {
|
|
10
|
+
_sum.value = x.value + y.value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const _total = computed(() => {
|
|
14
|
+
// Returning without .value, not entirely correctly, but will still work in Vue template.
|
|
15
|
+
// This is to test the impressive IVue unwrapping capabilities of deeply nested and confusing Refs
|
|
16
|
+
return _sum;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const total = computed(() => {
|
|
20
|
+
// Returning without .value, not entirely correctly, but will still work in Vue template.
|
|
21
|
+
// This is to test the impressive IVue unwrapping capabilities of deeply nested and confusing Refs
|
|
22
|
+
return _total;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
x,
|
|
27
|
+
y,
|
|
28
|
+
sum,
|
|
29
|
+
total,
|
|
30
|
+
};
|
|
31
|
+
}
|
package/docs/docs/index.md
CHANGED
|
@@ -2,31 +2,51 @@
|
|
|
2
2
|
import Button from './components/Button.vue'
|
|
3
3
|
|
|
4
4
|
</script>
|
|
5
|
-
# Infinite Vue Documentation
|
|
5
|
+
# <span style="font-family: 'Public Sans'; ">ivue ∞ Infinite Vue</span> Documentation
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
## About
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
**<span style="font-family: 'Public Sans'; font-size: 125%;">ivue ∞ Infinite Vue</span>** is a class based composable architecture for Vue 3, that unlocks infinite scalability for Vue 3 based apps. It allows you to extend the regular Vue 3 in a simple and elegant Object Oriented way.
|
|
11
|
+
|
|
12
|
+
## `ivue` is
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<div style="padding-left:20px; font-size: 20px; line-height: 32px;">
|
|
16
|
+
∞ Simple like Options API<br />
|
|
17
|
+
∞ Flexible like Composition API<br />
|
|
18
|
+
∞ Extensible like TypeScript Class API<br />
|
|
19
|
+
∞ Robust, Minimal, Opaque & Unobtrusive<br />
|
|
20
|
+
∞ 100% VSCode / Intellij IDE Autocomplete Intellisence<br />
|
|
21
|
+
∞ 100% Vue 3 Compatible<br />
|
|
22
|
+
∞ 100% Test Covered<br />
|
|
23
|
+
∞ 100% Type Safe<br />
|
|
24
|
+
∞ Production Ready<br />
|
|
25
|
+
∞ Just <code>1.1kb</code> gzipped!<br />
|
|
26
|
+
</div>
|
|
27
|
+
|
|
11
28
|
|
|
12
29
|
## Features
|
|
13
|
-
<div style="padding-left:20px;">
|
|
14
|
-
&
|
|
15
|
-
&
|
|
16
|
-
&
|
|
17
|
-
&
|
|
18
|
-
&
|
|
19
|
-
&
|
|
20
|
-
&
|
|
21
|
-
– Can be used both as a Store and a ViewModel for Components<br />
|
|
22
|
-
– Provides Full TypeScript Support<br />
|
|
23
|
-
– Extends Vue 3 TypeScript Capability<br />
|
|
24
|
-
– 100% Tested<br />
|
|
25
|
-
– Zero dependencies except Vue 3<br />
|
|
26
|
-
– Only 1kb(gzipped) in size!<br />
|
|
27
|
-
– Production Ready<br />
|
|
30
|
+
<div style="padding-left:20px; font-size: 18px;line-height: 28px; ">
|
|
31
|
+
— Extensible Classes using JavaScript / TypeScript native Class API<br />
|
|
32
|
+
— Can be used as a Global Store and a ViewModel for Components<br />
|
|
33
|
+
— Enhances Extensibility of Props Defaults, Props, Slots<br />
|
|
34
|
+
— Improves DX by elegantly dealing with <code>.value</code><br />
|
|
35
|
+
— Allows for Fully Extensible Component Architecture<br />
|
|
36
|
+
— Extends Vue 3 TypeScript Capability<br />
|
|
37
|
+
— Zero dependencies except Vue 3<br />
|
|
28
38
|
</div>
|
|
29
39
|
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Philosophy
|
|
43
|
+
<center>
|
|
44
|
+
Perfection is achieved, not when there is nothing more to add, <br />
|
|
45
|
+
but when there is nothing left to take away.
|
|
46
|
+
|
|
47
|
+
<div style="padding-top: 5px; color:#888; font-size: 90%;">― Antoine de Saint-Exupéry</div>
|
|
48
|
+
</center>
|
|
49
|
+
|
|
30
50
|
## Next Step
|
|
31
51
|
|
|
32
52
|
<Button href="/pages/getting-started.html" label="Geting Started" /> or <Button href="/pages/introduction.html" label="Read Introduction" />
|
package/docs/docs/pages/api.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
## Core Functions
|
|
7
7
|
|
|
8
|
-
### ivue()
|
|
8
|
+
### `ivue()`
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -22,24 +22,24 @@ Core `ivue(className, ...args)` initializer is able to infer and validate the co
|
|
|
22
22
|
|
|
23
23
|
`ivue()` initializer function returns an extended Vue 3 `reactive()` object in which getters and setters are internally converted to computeds and adds `.toRefs()` method to the created object. Computeds auto-unwrap themselves when they are accessed as a reactive object property, so the `.value` properties and computeds get flattened in the resulting object and do not require `.value` to be accessed.
|
|
24
24
|
|
|
25
|
-
`ivue()` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.
|
|
25
|
+
`ivue()` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype ancestors chain thus supporting classical inheritance.
|
|
26
26
|
|
|
27
27
|
**Returns:** `<IVue<T>>` or `ivue` `reactive()` object of an `AnyClass` class with flattened (de-Refed) `Refs` and `ComputedRefs` as properties.
|
|
28
28
|
|
|
29
|
-
### iref()
|
|
29
|
+
### `iref()`
|
|
30
30
|
|
|
31
31
|
Create a regular `vue` Ref but cast the type to the internal unreactive type, because properties auto-unwrap in `reactive()` object that is being created by `ivue` upon initialization.
|
|
32
32
|
|
|
33
|
-
### iuse()
|
|
33
|
+
### `iuse()`
|
|
34
34
|
|
|
35
35
|
This function unwraps the type of any composable return to the bare values without `.value`, because properties auto-unwrap in `reactive()` object that is being created by `ivue` upon initialization.
|
|
36
36
|
|
|
37
|
-
###
|
|
37
|
+
### `.init()`
|
|
38
38
|
|
|
39
39
|
---
|
|
40
40
|
|
|
41
41
|
`.init()` method is auto-run on `ivue()` initialization after `constructor()` is run.
|
|
42
|
-
|
|
42
|
+
`.init()` has access to the reactive state of the object via `this`.
|
|
43
43
|
|
|
44
44
|
:::warning NOTICE
|
|
45
45
|
`.init()` method has no arguments and you should never need to run this method manually.
|
|
@@ -51,7 +51,7 @@ Use `async init()` if you need `await` functionality.
|
|
|
51
51
|
|
|
52
52
|
**Returns:** `void | Promise<void>`
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### `.toRefs()`
|
|
55
55
|
|
|
56
56
|
---
|
|
57
57
|
|
|
@@ -61,7 +61,7 @@ function toRefs(props?: (keyof InstanceType<T>)[]): IVueRefs<InstanceType<T>>;
|
|
|
61
61
|
|
|
62
62
|
Converts an `ivue` object to a Vue 3 Composable with nested refs.
|
|
63
63
|
|
|
64
|
-
:::tip You can pass the name of the properties to
|
|
64
|
+
:::tip You can pass the name of the properties to `.toRefs(properties)`
|
|
65
65
|
```ts
|
|
66
66
|
const { width, height } = ivue(Box).toRefs(['width', 'height']);
|
|
67
67
|
```
|
|
@@ -72,7 +72,7 @@ This improves performance if `box` has many other properties that we do not need
|
|
|
72
72
|
|
|
73
73
|
## Utility Functions
|
|
74
74
|
|
|
75
|
-
### propsWithDefaults()
|
|
75
|
+
### `propsWithDefaults()`
|
|
76
76
|
|
|
77
77
|
---
|
|
78
78
|
|
|
@@ -89,25 +89,25 @@ Combines statically written defaults object with the runtime type definition of
|
|
|
89
89
|
|
|
90
90
|
## Utility Types
|
|
91
91
|
|
|
92
|
-
### ExtractPropDefaultTypes
|
|
92
|
+
### `ExtractPropDefaultTypes`
|
|
93
93
|
|
|
94
94
|
Extracts types of the default types definition. This type can be used to validate against the actual defaults definition to make sure both definitions are in sync.
|
|
95
95
|
|
|
96
96
|
---
|
|
97
97
|
|
|
98
|
-
### ExtractEmitTypes
|
|
98
|
+
### `ExtractEmitTypes`
|
|
99
99
|
|
|
100
100
|
---
|
|
101
101
|
|
|
102
102
|
Extracts types of a runtime emits declaration.
|
|
103
103
|
|
|
104
|
-
### ExtendSlots
|
|
104
|
+
### `ExtendSlots`
|
|
105
105
|
|
|
106
106
|
---
|
|
107
107
|
|
|
108
108
|
Allows you to extend slots of a given slot interface.
|
|
109
109
|
|
|
110
|
-
### UseComposable
|
|
110
|
+
### `UseComposable`
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
@@ -15,11 +15,15 @@ class Counter {
|
|
|
15
15
|
/** ✓ Properly declared unwrapped composable. */
|
|
16
16
|
mouse: UseMouse;
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* ✓ Properly declared DOM Ref.
|
|
20
|
+
* ✓ Custom declared type of HTMLElement or null
|
|
21
|
+
*/
|
|
22
|
+
spanElementRef = iref<HTMLElement | null>(null);
|
|
20
23
|
|
|
21
24
|
constructor(public props: CounterProps, public emit: CounterEmit) {
|
|
22
|
-
|
|
25
|
+
/** ✓ Properly declared auto-unwrapped composable. */
|
|
26
|
+
this.mouse = iuse(useMouse());
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/** ✓ Properly declared init function. */
|
|
@@ -36,17 +40,18 @@ class Counter {
|
|
|
36
40
|
}
|
|
37
41
|
})
|
|
38
42
|
}
|
|
43
|
+
|
|
39
44
|
/**
|
|
40
45
|
* Use iref() for the property to be auto cast to number
|
|
41
46
|
* because refs auto-unwrap inside reactive().
|
|
42
47
|
*/
|
|
43
|
-
count = iref(0); // ✓ inferred type -> number
|
|
48
|
+
count = iref(0); // ✓ Properly inferred type -> number
|
|
44
49
|
|
|
45
50
|
/**
|
|
46
51
|
* Use iref() for the property to be auto cast to number
|
|
47
52
|
* because refs auto-unwrap inside reactive().
|
|
48
53
|
*/
|
|
49
|
-
timesClicked = iref(0); // ✓ inferred type -> number
|
|
54
|
+
timesClicked = iref(0); // ✓ Properly inferred type -> number
|
|
50
55
|
|
|
51
56
|
/** ✓ Properly declared function (not arrow function). */
|
|
52
57
|
increment() {
|
|
@@ -70,6 +75,7 @@ class Counter {
|
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
|
|
78
|
+
/** ✓ Properly intilized IVUE class runner. */
|
|
73
79
|
const counter = ivue(Counter, props, emit);
|
|
74
80
|
```
|
|
75
81
|
|
|
@@ -95,7 +101,7 @@ Arrow functions break full extensibility of classes because they carry their own
|
|
|
95
101
|
|
|
96
102
|
#### Use `constructor()` to assign properties of the class and cast Refs to Unwrapped bare types. <br />
|
|
97
103
|
|
|
98
|
-
#### Use `.init()` to declare reactive state functions like `watch`, `watchEffect`, and lifecycle hooks like `onMounted`, `onBeforeMount` etc, do assignments of reactive properties, since
|
|
104
|
+
#### 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 />
|
|
99
105
|
|
|
100
106
|
<hr />
|
|
101
107
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import CounterBasic from '../components/usage/CounterBasic.vue'
|
|
3
3
|
</script>
|
|
4
|
+
|
|
4
5
|
# How it works?
|
|
5
6
|
|
|
6
7
|
## What ivue is NOT?
|
|
@@ -8,30 +9,40 @@ import CounterBasic from '../components/usage/CounterBasic.vue'
|
|
|
8
9
|
To understand how ivue works and how it does it, it is important to understand what it does not do.
|
|
9
10
|
|
|
10
11
|
::: info `ivue` is different from other class based libraries
|
|
11
|
-
— `ivue` does NOT inherit from a base
|
|
12
|
-
— `ivue` does NOT use
|
|
13
|
-
— `ivue` does NOT alter Vue 3 underlying behavior, but rather relies on it
|
|
14
|
-
— `ivue` is NOT the same as
|
|
12
|
+
— `ivue` does NOT inherit from a base Class.<br />
|
|
13
|
+
— `ivue` does NOT use Decorators to achieve its objectives.<br />
|
|
14
|
+
— `ivue` does NOT alter Vue 3 underlying behavior, but rather relies on it.<br />
|
|
15
|
+
— `ivue` is NOT the same as Class Components (though you can build components with it).<br />
|
|
16
|
+
— `ivue` aims to be opaque, by giving the developer the Class API reactivity system.<br />
|
|
17
|
+
— `ivue` omits custom implementations of IOC Container, Decorators & Mixins, etc. by design.<br />
|
|
18
|
+
— `ivue` enforces a sane default standard of operation to contain the ever flexible Class API.<br />
|
|
19
|
+
:::
|
|
20
|
+
|
|
21
|
+
::: tip IVUE IMPLEMENTS MINIMAL API ARCHITECTURE
|
|
22
|
+
Things like IOC Container, Decorators, Traits, Mixins, etc. were omitted by design to slim down the surface area and scope of `ivue` core purpose, which was JavaScript / TypeScript Class API based reactivity. Any Traits, Decorators & IOC Container can be built around it using third-party libraries or roll your own systems. You are more than welcome to contribute in this area!
|
|
15
23
|
:::
|
|
16
24
|
|
|
17
25
|
## How it works?
|
|
26
|
+
|
|
18
27
|
```ts
|
|
19
28
|
export function ivue<T extends AnyClass>(
|
|
20
29
|
className: T,
|
|
21
30
|
...args: InferredArgs<T>
|
|
22
|
-
): IVue<T
|
|
31
|
+
): IVue<T>;
|
|
23
32
|
```
|
|
33
|
+
|
|
24
34
|
The main `ivue()` initializer function uses TypeScript to be able to infer and validate the constrcutor argument types of `AnyClass` and passes those arguments to the constructor of `AnyClass`.
|
|
25
35
|
|
|
26
36
|
`ivue` allows you to pass any number of arguments into the class `constructor(arg1, arg2, arg3, ...etc)`
|
|
27
37
|
|
|
28
38
|
`ivue()` initializer function returns an extended Vue 3 `reactive()` object in which getters and setters are internally converted to computeds and adds `.toRefs()` method to the created object. Computeds auto-unwrap themselves when they are accessed as a reactive object property, so the `.value` properties and computeds get flattened in the resulting object and do not require `.value` to be accessed.
|
|
29
39
|
|
|
30
|
-
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.
|
|
40
|
+
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype ancestors chain thus supporting classical inheritance.
|
|
31
41
|
|
|
32
|
-
`ivue` 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 `.init()`
|
|
42
|
+
`ivue` 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 `.init()`
|
|
33
43
|
|
|
34
44
|
## Usage Recommendation
|
|
45
|
+
|
|
35
46
|
`ivue` recommends all class properties to be defined as `ref()` to be able to interoperate with `defineExpose()`, if you simply pass reactive props which are not Refs through `defineExpose()`, they will lose reactivity. `ref()` refs just like computed refs get flattened into the `reactive()` object, so there is no need to worry about using `.value`. The `ref()` 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 `Ref<number>` is `number` in `ivue`, so rather than going in the direction of complexifying the types, we are going in the opposite direction towards simplification.
|
|
36
47
|
|
|
37
48
|
`ivue` recommends all class functions, getters and setters to be defined in plain full function style (not arrow functions), this allows all `ivue` 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.
|
|
@@ -40,7 +51,9 @@ See: [More Guidelines](/pages/guidelines.html)
|
|
|
40
51
|
|
|
41
52
|
## Minimal API Surface Area
|
|
42
53
|
|
|
43
|
-
`ivue()` initializer function is the main
|
|
54
|
+
`ivue()` initializer function is the main core function to initialize the `ivue` reactive object<br />
|
|
55
|
+
`iref()` ref initializer instantiates the Ref but Unwraps its type as the raw type of the Ref<br />
|
|
56
|
+
`iuse()` function converts the type of composables to they Unwraped raw types<br />
|
|
44
57
|
`.init()` method helps initialize the reactive state like `watch`, `onMount`, etc.<br />
|
|
45
58
|
`.toRefs()` method allows to interoperate with Vue 3 Composables<br />
|
|
46
59
|
Utility Types help to achieve the rest of `ivue` capabilities
|
|
@@ -52,11 +65,12 @@ Utility Types help to achieve the rest of `ivue` capabilities
|
|
|
52
65
|
Or [See on GitHub](https://github.com/infinite-system/ivue/blob/main/src/ivue.ts)
|
|
53
66
|
|
|
54
67
|
## 100% Vue 3 Compatible
|
|
68
|
+
|
|
55
69
|
`.toRefs()` allows the object to be converted to Vue 3 native composable structure with full `.value`s, so it can interoperate with native composables if needed. `.toRefs()` is also often used to get refs for `v-bind()` in css styles.
|
|
56
70
|
|
|
57
71
|
## 100% TypeScript Support
|
|
58
72
|
|
|
59
|
-
`ivue` is on the cutting edge of TypeScript and owes its capabilities to the latest developments in TypeScript.
|
|
73
|
+
`ivue` is on the cutting edge of TypeScript and owes its capabilities to the latest developments in TypeScript.
|
|
60
74
|
|
|
61
75
|
`ivue` provides a set of utility types to make working with `Vue 3` even easier and more scalable.
|
|
62
76
|
|
|
@@ -68,4 +82,4 @@ You can clone the project and run `yarn test` yourself and examine the tests.
|
|
|
68
82
|
|
|
69
83
|
## Zero Dependencies
|
|
70
84
|
|
|
71
|
-
`ivue` has zero dependencies except Vue 3.
|
|
85
|
+
`ivue` has zero dependencies except Vue 3.
|
|
@@ -19,7 +19,7 @@ After many iterations where I created a whole inversion of control library for `
|
|
|
19
19
|
|
|
20
20
|
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 `3` core functions: `ivue()`, `.init()`, `.toRefs()` only which are necessary to do everything `ivue` is set out to do.
|
|
21
21
|
|
|
22
|
-
Use Composition API composables inside
|
|
22
|
+
Use Composition API composables inside `.init()` function.
|
|
23
23
|
|
|
24
24
|
## Minimalism
|
|
25
25
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import Button from '../components/Button.vue'
|
|
3
3
|
</script>
|
|
4
|
-
# What is Infinite Vue
|
|
4
|
+
# What is <span style="font-family: 'Public Sans'; ">ivue ∞ Infinite Vue</span>?
|
|
5
5
|
|
|
6
6
|
## The Problem
|
|
7
7
|
|
|
@@ -17,7 +17,14 @@ See: [VueJs.org – Reactivity Transform](https://vuejs.org/guide/extras/rea
|
|
|
17
17
|
<div style="padding-left:20px; font-size: 1.2rem; line-height: 2rem;">
|
|
18
18
|
– Simple like Options API<br />
|
|
19
19
|
– Flexible like Composition API<br />
|
|
20
|
-
– Extensible like TypeScript
|
|
20
|
+
– Extensible like TypeScript Class API<br />
|
|
21
|
+
– Robust, Minimal, Opaque & Unobtrusive<br />
|
|
22
|
+
– 100% Vue 3 Compatible<br />
|
|
23
|
+
– 100% Test Covered<br />
|
|
24
|
+
– 100% Type Safe<br />
|
|
25
|
+
– Production Ready<br />
|
|
26
|
+
– Just <code>1.1kb</code> gzipped!<br />
|
|
27
|
+
– 100% VSCode / Intellij IDE Auto-complete Intellisence<br />
|
|
21
28
|
</div>
|
|
22
29
|
|
|
23
30
|
`ivue` is a powerful tool because it fully aligns itself with JavaScript / TypeScript Class API.
|
|
@@ -46,7 +53,7 @@ While procedural programming has its strength, it also comes with its own weakne
|
|
|
46
53
|
|
|
47
54
|
## Infinite Vue Class Achitecture
|
|
48
55
|
|
|
49
|
-
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.
|
|
56
|
+
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype ancestors chain thus supporting classical inheritance.
|
|
50
57
|
|
|
51
58
|
By using TypeScript we are able to infer the arguments of the main `ivue()` initializer function and pass the arguments to the constructor.
|
|
52
59
|
|
package/docs/docs/pages/usage.md
CHANGED
|
@@ -10,6 +10,7 @@ import CounterExternalRefs from '../components/usage/CounterExternalRefs.vue'
|
|
|
10
10
|
import CounterInternalRefs from '../components/usage/CounterInternalRefs.vue'
|
|
11
11
|
import CounterComposables from '../components/usage/CounterComposables.vue'
|
|
12
12
|
import CounterComposablesDestructuring from '../components/usage/CounterComposablesDestructuring.vue'
|
|
13
|
+
import CounterComposablesIvueDestructuring from '../components/usage/CounterComposablesIvueDestructuring.vue'
|
|
13
14
|
import CounterInsideComposables from '../components/usage/CounterInsideComposables.vue'
|
|
14
15
|
import CounterComputeds from '../components/usage/CounterComputeds.vue'
|
|
15
16
|
import CounterComputedsDisabled from '../components/usage/CounterComputedsDisabled.vue'
|
|
@@ -231,7 +232,7 @@ See the highlighted sections related to destructuring composable usage.
|
|
|
231
232
|
|
|
232
233
|
::: code-group
|
|
233
234
|
<<< @/components/usage/CounterComposablesDestructuring.vue{4,10,20-21,23-24,27-32 vue:line-numbers}
|
|
234
|
-
<<< @/components/usage/functions/
|
|
235
|
+
<<< @/components/usage/functions/useCustomMouse.ts{ts:line-numbers} [functions/useCustomMouse.ts]
|
|
235
236
|
:::
|
|
236
237
|
|
|
237
238
|
:::details For this example we initialize the component like this:
|
|
@@ -270,6 +271,27 @@ See the highlighted sections related to using `ivue` inside a composable.
|
|
|
270
271
|
|
|
271
272
|
<CounterInsideComposables />
|
|
272
273
|
|
|
274
|
+
## Using `ivue` Composables
|
|
275
|
+
|
|
276
|
+
See the highlighted sections related to using `ivue` based composables.
|
|
277
|
+
|
|
278
|
+
::: code-group
|
|
279
|
+
<<< @/components/usage/CounterComposablesIvueDestructuring.vue{14 vue:line-numbers}
|
|
280
|
+
:::
|
|
281
|
+
|
|
282
|
+
:::details For this example we initialize the component like this:
|
|
283
|
+
|
|
284
|
+
```vue
|
|
285
|
+
<template>
|
|
286
|
+
<CounterComposablesIvueDestructuring />
|
|
287
|
+
</template>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
:::
|
|
291
|
+
|
|
292
|
+
<div style="font-size: 18px; font-weight: 500;">Result</div>
|
|
293
|
+
|
|
294
|
+
<CounterComposablesIvueDestructuring />
|
|
273
295
|
|
|
274
296
|
## Using Computeds
|
|
275
297
|
|
|
@@ -329,7 +351,7 @@ See the highlighted sections related to using `init()` below:
|
|
|
329
351
|
|
|
330
352
|
## Using Lifecycle Hooks
|
|
331
353
|
|
|
332
|
-
To use `onMounted`, `onBeforeMount` and other lifecycle, declare `.init()` method in the class.
|
|
354
|
+
To use `onMounted`, `onBeforeMount` and other lifecycle hooks, declare `.init()` method in the class.
|
|
333
355
|
See the highlighted sections related to using `init()` below:
|
|
334
356
|
|
|
335
357
|
::: tip NOTICE:
|
package/docs/package.json
CHANGED