ivue 1.2.2 → 1.2.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/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/src/ivue.d.ts +4 -4
- package/docs/docs/.vitepress/config.ts +8 -2
- package/docs/docs/.vitepress/dist/404.html +2 -2
- package/docs/docs/.vitepress/dist/api/ivue.html +4 -4
- package/docs/docs/.vitepress/dist/api/propsWithDefaults.html +4 -4
- package/docs/docs/.vitepress/dist/assets/{app.2nR_jJ6K.js → app.D_gfERxK.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.ChoKIVFM.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/{VPLocalSearchBox.DkPjtbh1.js → VPLocalSearchBox.BzoUb0RV.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.D191XnPH.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/{theme.DoTp8yA-.js → theme.CzkYYfOm.js} +2 -2
- package/docs/docs/.vitepress/dist/assets/pages_api.md.bOEtTo1m.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_api.md.bOEtTo1m.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.D-gTrMhG.js → pages_browse-code.md.BhmYOQjE.js} +2 -2
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.COvbcFGT.js → pages_getting-started.md.C8UElRkE.js} +2 -2
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.BI1PexCc.lean.js → pages_guidelines.md.C2kOmJCV.js} +18 -18
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.BI1PexCc.js → pages_guidelines.md.C2kOmJCV.lean.js} +18 -18
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.NImDvDby.js → pages_how-it-works.md.D6PSCfuz.js} +4 -4
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.NImDvDby.lean.js → pages_how-it-works.md.D6PSCfuz.lean.js} +4 -4
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.MtnX0UvH.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.MtnX0UvH.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.DRJXyExt.js → pages_usage.md.Dw6OzuOj.js} +105 -73
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.DRJXyExt.lean.js → pages_usage.md.Dw6OzuOj.lean.js} +105 -73
- package/docs/docs/.vitepress/dist/hashmap.json +1 -1
- package/docs/docs/.vitepress/dist/index.html +4 -4
- package/docs/docs/.vitepress/dist/pages/advanced-usage.html +4 -4
- package/docs/docs/.vitepress/dist/pages/api.html +7 -7
- package/docs/docs/.vitepress/dist/pages/browse-code.html +6 -6
- package/docs/docs/.vitepress/dist/pages/getting-started.html +7 -7
- package/docs/docs/.vitepress/dist/pages/guidelines.html +23 -23
- package/docs/docs/.vitepress/dist/pages/how-it-works.html +7 -7
- package/docs/docs/.vitepress/dist/pages/how-its-made.html +4 -4
- package/docs/docs/.vitepress/dist/pages/introduction.html +5 -5
- package/docs/docs/.vitepress/dist/pages/usage.html +110 -78
- package/docs/docs/components/usage/CounterBasic.vue +3 -1
- package/docs/docs/components/usage/CounterComposables.vue +5 -3
- package/docs/docs/components/usage/CounterComposablesDestructuring.vue +15 -11
- package/docs/docs/components/usage/CounterComposablesIvue.vue +7 -3
- package/docs/docs/components/usage/CounterComposablesIvueDestructuring.vue +4 -2
- package/docs/docs/components/usage/CounterComputeds.vue +3 -1
- package/docs/docs/components/usage/CounterComputedsDisabled.vue +6 -4
- package/docs/docs/components/usage/CounterExternalRefs.vue +4 -2
- package/docs/docs/components/usage/CounterInsideComposables.vue +3 -1
- package/docs/docs/components/usage/CounterInternalRefs.vue +3 -1
- package/docs/docs/components/usage/CounterLifecycleHooks.vue +3 -1
- package/docs/docs/components/usage/CounterWatch.vue +3 -1
- package/docs/docs/components/usage/CounterWithProps.vue +4 -2
- package/docs/docs/components/usage/CounterWithPropsAndEmits.vue +3 -1
- package/docs/docs/components/usage/classes/CustomMouse.ts +2 -2
- package/docs/docs/pages/api.md +17 -6
- package/docs/docs/pages/guidelines.md +9 -9
- package/docs/docs/pages/how-it-works.md +0 -20
- package/docs/docs/pages/introduction.md +21 -7
- package/docs/docs/pages/usage.md +7 -7
- package/docs/package.json +1 -1
- package/package.json +1 -1
- package/src/ivue.ts +8 -8
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.yrRWVEzw.js +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.CUL6WvM-.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.CElVfYwg.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.CElVfYwg.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.CCkiQtfX.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.CCkiQtfX.lean.js +0 -1
- /package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.D-gTrMhG.lean.js → pages_browse-code.md.BhmYOQjE.lean.js} +0 -0
- /package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.COvbcFGT.lean.js → pages_getting-started.md.C8UElRkE.lean.js} +0 -0
|
@@ -11,6 +11,8 @@ class Counter {
|
|
|
11
11
|
const counter = ivue(Counter);
|
|
12
12
|
</script>
|
|
13
13
|
<template>
|
|
14
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
14
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
15
|
+
Increment
|
|
16
|
+
</a>
|
|
15
17
|
Count: {{ counter.count }}
|
|
16
18
|
</template>
|
|
@@ -14,13 +14,15 @@ class Counter {
|
|
|
14
14
|
const counter = ivue(Counter);
|
|
15
15
|
</script>
|
|
16
16
|
<template>
|
|
17
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
17
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
18
|
+
Increment
|
|
19
|
+
</a>
|
|
18
20
|
Count: {{ counter.count }} <br />
|
|
19
21
|
<br />
|
|
20
22
|
Mouse: <br />
|
|
21
23
|
X: {{ counter.mouse.x }} <br />
|
|
22
|
-
Y: {{ counter.mouse.y }} <br />
|
|
23
|
-
<br />
|
|
24
|
+
Y: {{ counter.mouse.y }} <br />
|
|
25
|
+
<br />
|
|
24
26
|
Pointer: <br />
|
|
25
27
|
X: {{ counter.pointer.x }} <br />
|
|
26
28
|
Y: {{ counter.pointer.y }} <br />
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { useCustomMouse } from './functions/useCustomMouse';
|
|
3
3
|
|
|
4
|
-
import { ivue, iuse, iref, type
|
|
4
|
+
import { ivue, iuse, iref, type Use } from 'ivue';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Use the ivue Utility Type:
|
|
7
|
+
* Use the ivue Utility Type: Use<typeof YourComposableFunctionName>
|
|
8
8
|
* to get he resulting unwrapped composable properties and functions.
|
|
9
9
|
*/
|
|
10
|
-
type UseCustomMouse =
|
|
10
|
+
type UseCustomMouse = Use<typeof useCustomMouse>;
|
|
11
11
|
|
|
12
12
|
class Counter {
|
|
13
13
|
count = iref(0);
|
|
@@ -18,22 +18,22 @@ class Counter {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* 'x', 'y', 'sum', 'total' are Refs that will be unwrapped to their bare raw types and destructured into the class.
|
|
21
|
-
* Even though unwrapped (de-Refed), they will maintain their behavior as Refs and thus will maintain reactivity
|
|
22
|
-
* and at the same time get destructured into this class root level scope because
|
|
21
|
+
* Even though unwrapped (de-Refed), they will maintain their behavior as Refs and thus will maintain reactivity
|
|
22
|
+
* and at the same time get destructured into this class root level scope because
|
|
23
23
|
* Vue 3's `reactive()` Proxy will be able to resolve those Refs internally.
|
|
24
24
|
*/
|
|
25
25
|
x: UseCustomMouse['x']; // Unwrapped Ref<number> becomes -> number
|
|
26
26
|
y: UseCustomMouse['y']; // Unwrapped Ref<number> becomes -> number
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
sum: UseCustomMouse['sum']; // 'sum' method that will be destructured into this class on construct()
|
|
29
|
-
total: UseCustomMouse['total'];
|
|
29
|
+
total: UseCustomMouse['total']; // 'total' computed Ref that will also be destructured into this class on construct()
|
|
30
30
|
|
|
31
31
|
constructor() {
|
|
32
32
|
({
|
|
33
33
|
x: this.x,
|
|
34
34
|
y: this.y,
|
|
35
35
|
sum: this.sum,
|
|
36
|
-
total: this.total
|
|
36
|
+
total: this.total,
|
|
37
37
|
} = iuse(useCustomMouse, 5));
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -41,11 +41,15 @@ class Counter {
|
|
|
41
41
|
const counter = ivue(Counter);
|
|
42
42
|
</script>
|
|
43
43
|
<template>
|
|
44
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
44
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
45
|
+
Increment
|
|
46
|
+
</a>
|
|
45
47
|
Count: {{ counter.count }} <br />
|
|
46
|
-
Mouse X: {{ counter.x }}, Y: {{ counter.y }}
|
|
48
|
+
Mouse X: {{ counter.x }}, Y: {{ counter.y }}
|
|
47
49
|
<br />
|
|
48
50
|
Total (computed): {{ counter.total }}
|
|
49
51
|
<br />
|
|
50
|
-
<button class="button" @click="() => counter.sum()">
|
|
52
|
+
<button class="button" @click="() => counter.sum()">
|
|
53
|
+
Click This Big Sum Button To Total X + Y
|
|
54
|
+
</button>
|
|
51
55
|
</template>
|
|
@@ -10,17 +10,21 @@ class Counter {
|
|
|
10
10
|
this.count++;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
mouse = ivue(CustomMouse, 5)
|
|
13
|
+
mouse = ivue(CustomMouse, 5);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const counter = ivue(Counter);
|
|
17
17
|
</script>
|
|
18
18
|
<template>
|
|
19
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
19
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
20
|
+
Increment
|
|
21
|
+
</a>
|
|
20
22
|
Count: {{ counter.count }} <br />
|
|
21
23
|
Mouse X: {{ counter.mouse.x }}, Y: {{ counter.mouse.y }}
|
|
22
24
|
<br />
|
|
23
25
|
Total (computed): {{ counter.mouse.total }}
|
|
24
26
|
<br />
|
|
25
|
-
<button class="button" @click="() => counter.mouse.sum()">
|
|
27
|
+
<button class="button" @click="() => counter.mouse.sum()">
|
|
28
|
+
Click This Big Sum Button To Total X + Y
|
|
29
|
+
</button>
|
|
26
30
|
</template>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { CustomMouse } from './classes/CustomMouse';
|
|
3
3
|
|
|
4
|
-
import { ivue, iref } from '
|
|
4
|
+
import { ivue, iref } from 'ivue';
|
|
5
5
|
|
|
6
6
|
class Counter {
|
|
7
7
|
count = iref(0);
|
|
@@ -34,7 +34,9 @@ class Counter {
|
|
|
34
34
|
const counter = ivue(Counter);
|
|
35
35
|
</script>
|
|
36
36
|
<template>
|
|
37
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
37
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
38
|
+
Increment
|
|
39
|
+
</a>
|
|
38
40
|
Count: {{ counter.count }} <br />
|
|
39
41
|
Mouse X: {{ counter.x }}, Y: {{ counter.y }}
|
|
40
42
|
<br />
|
|
@@ -17,7 +17,9 @@ class Counter {
|
|
|
17
17
|
const counter = ivue(Counter);
|
|
18
18
|
</script>
|
|
19
19
|
<template>
|
|
20
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
20
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
21
|
+
Increment
|
|
22
|
+
</a>
|
|
21
23
|
Count: {{ counter.count }} <br />
|
|
22
24
|
Double Count: {{ counter.doubleCount }} <br />
|
|
23
25
|
Quad Count: {{ counter.quadCount }} <br />
|
|
@@ -3,12 +3,12 @@ import { ivue, iref } from 'ivue';
|
|
|
3
3
|
|
|
4
4
|
class Counter {
|
|
5
5
|
/**
|
|
6
|
-
* Use static ivue property to disable computed
|
|
6
|
+
* Use static ivue property to disable computed
|
|
7
7
|
* behavior for certain getters.
|
|
8
8
|
*/
|
|
9
9
|
static ivue = {
|
|
10
|
-
doubleCount: false // doubleCount is a regular getter now
|
|
11
|
-
}
|
|
10
|
+
doubleCount: false, // doubleCount is a regular getter now
|
|
11
|
+
};
|
|
12
12
|
count = iref(0);
|
|
13
13
|
increment() {
|
|
14
14
|
this.count++;
|
|
@@ -24,7 +24,9 @@ class Counter {
|
|
|
24
24
|
const counter = ivue(Counter);
|
|
25
25
|
</script>
|
|
26
26
|
<template>
|
|
27
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
27
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
28
|
+
Increment
|
|
29
|
+
</a>
|
|
28
30
|
Count: {{ counter.count }} <br />
|
|
29
31
|
Double Count: {{ counter.doubleCount }} <br />
|
|
30
32
|
Quad Count: {{ counter.quadCount }} <br />
|
|
@@ -19,7 +19,9 @@ const counter = ivue(Counter, iuse(span));
|
|
|
19
19
|
defineExpose<Counter>(counter);
|
|
20
20
|
</script>
|
|
21
21
|
<template>
|
|
22
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
23
|
-
|
|
22
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
23
|
+
Increment
|
|
24
|
+
</a>
|
|
25
|
+
Count: {{ counter.count }}
|
|
24
26
|
<span ref="span"></span>
|
|
25
27
|
</template>
|
|
@@ -21,6 +21,8 @@ function useCounter() {
|
|
|
21
21
|
const { count, increment } = useCounter();
|
|
22
22
|
</script>
|
|
23
23
|
<template>
|
|
24
|
-
<a href="javascript:void(0)" @click="increment">
|
|
24
|
+
<a href="javascript:void(0)" @click="increment">
|
|
25
|
+
Increment
|
|
26
|
+
</a>
|
|
25
27
|
Count: {{ count }} <br />
|
|
26
28
|
</template>
|
|
@@ -19,7 +19,9 @@ const { span } = counter.toRefs(['span']);
|
|
|
19
19
|
*/
|
|
20
20
|
</script>
|
|
21
21
|
<template>
|
|
22
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
22
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
23
|
+
Increment
|
|
24
|
+
</a>
|
|
23
25
|
Count: {{ counter.count }}
|
|
24
26
|
<span ref="span"></span>
|
|
25
27
|
</template>
|
|
@@ -17,6 +17,8 @@ class Counter {
|
|
|
17
17
|
const counter = ivue(Counter);
|
|
18
18
|
</script>
|
|
19
19
|
<template>
|
|
20
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
20
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
21
|
+
Increment
|
|
22
|
+
</a>
|
|
21
23
|
Count: {{ counter.count }} (onMounted we set it to 100)
|
|
22
24
|
</template>
|
|
@@ -23,6 +23,8 @@ class Counter {
|
|
|
23
23
|
const counter = ivue(Counter);
|
|
24
24
|
</script>
|
|
25
25
|
<template>
|
|
26
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
26
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
27
|
+
Increment
|
|
28
|
+
</a>
|
|
27
29
|
Count: {{ counter.count }} (Click 5 times to get an alert)
|
|
28
30
|
</template>
|
|
@@ -17,12 +17,14 @@ class Counter {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* NOTICE that: ivue(ClassName, ...args) uses TypeScript to infer
|
|
20
|
+
* NOTICE that: ivue(ClassName, ...args) uses TypeScript to infer
|
|
21
21
|
* the correct argument types that you need to pass to the constructor.
|
|
22
22
|
*/
|
|
23
23
|
const counter = ivue(Counter, props);
|
|
24
24
|
</script>
|
|
25
25
|
<template>
|
|
26
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
26
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
27
|
+
Increment
|
|
28
|
+
</a>
|
|
27
29
|
Count: {{ counter.count }}
|
|
28
30
|
</template>
|
|
@@ -30,6 +30,8 @@ class Counter {
|
|
|
30
30
|
const counter = ivue(Counter, props, emit);
|
|
31
31
|
</script>
|
|
32
32
|
<template>
|
|
33
|
-
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
33
|
+
<a href="javascript:void(0)" @click="() => counter.increment()">
|
|
34
|
+
Increment
|
|
35
|
+
</a>
|
|
34
36
|
Count: {{ counter.count }}
|
|
35
37
|
</template>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMouse } from '@vueuse/core';
|
|
2
|
-
import { iref, iuse, type
|
|
2
|
+
import { iref, iuse, type Use } from 'ivue';
|
|
3
3
|
|
|
4
|
-
type UseMouse =
|
|
4
|
+
type UseMouse = Use<typeof useMouse>;
|
|
5
5
|
|
|
6
6
|
export class CustomMouse {
|
|
7
7
|
x: UseMouse['x'];
|
package/docs/docs/pages/api.md
CHANGED
|
@@ -32,13 +32,18 @@ Create a regular `vue` Ref but cast the type to the internal unreactive type, be
|
|
|
32
32
|
|
|
33
33
|
### `iuse()`
|
|
34
34
|
|
|
35
|
+
|
|
35
36
|
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
37
|
|
|
38
|
+
## Core Methods
|
|
39
|
+
### `.constructor()`
|
|
40
|
+
Native Class API `.constructor()` is mainly used to assign and cast Vue 3 Refs back to their original types. `.constructor()` should not be used to work with reactive state. Use `.init()` for reactive purposes.
|
|
41
|
+
|
|
37
42
|
### `.init()`
|
|
38
43
|
|
|
39
44
|
---
|
|
40
45
|
|
|
41
|
-
`.init()` method is auto-run on `ivue()` initialization after
|
|
46
|
+
`.init()` method is auto-run on `ivue()` initialization after `.constructor()` is run.
|
|
42
47
|
`.init()` has access to the reactive state of the object via `this`.
|
|
43
48
|
|
|
44
49
|
:::warning NOTICE
|
|
@@ -70,6 +75,13 @@ This improves performance if `box` has many other properties that we do not need
|
|
|
70
75
|
|
|
71
76
|
**Returns:** `IVueRefs<InstanceType<T>>`
|
|
72
77
|
|
|
78
|
+
## Core Types
|
|
79
|
+
|
|
80
|
+
### `IVue`
|
|
81
|
+
|
|
82
|
+
### `Use`
|
|
83
|
+
|
|
84
|
+
|
|
73
85
|
## Utility Functions
|
|
74
86
|
|
|
75
87
|
### `propsWithDefaults()`
|
|
@@ -89,6 +101,10 @@ Combines statically written defaults object with the runtime type definition of
|
|
|
89
101
|
|
|
90
102
|
## Utility Types
|
|
91
103
|
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
Extracts and unwraps (de-Refs) the real types of Vue 3 composable definition to make it compatible with `ivue`.
|
|
107
|
+
|
|
92
108
|
### `ExtractPropDefaultTypes`
|
|
93
109
|
|
|
94
110
|
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.
|
|
@@ -107,8 +123,3 @@ Extracts types of a runtime emits declaration.
|
|
|
107
123
|
|
|
108
124
|
Allows you to extend slots of a given slot interface.
|
|
109
125
|
|
|
110
|
-
### `UseComposable`
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
Extracts and unwraps (de-Refs) the real types of Vue 3 composable definition to make it compatible with `ivue`.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
## Dos and Don'ts
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
type UseMouse =
|
|
10
|
+
type UseMouse = Use<typeof useMouse>;
|
|
11
11
|
/**
|
|
12
12
|
* Example of a properly defined ivue class.
|
|
13
13
|
*/
|
|
@@ -23,7 +23,7 @@ class Counter {
|
|
|
23
23
|
|
|
24
24
|
constructor(public props: CounterProps, public emit: CounterEmit) {
|
|
25
25
|
/** ✓ Properly declared auto-unwrapped composable. */
|
|
26
|
-
this.mouse = iuse(useMouse
|
|
26
|
+
this.mouse = iuse(useMouse);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/** ✓ Properly declared init function. */
|
|
@@ -97,22 +97,22 @@ Next, we convert the types back to their normal types as if they have no reactiv
|
|
|
97
97
|
Arrow functions break full extensibility of classes because they carry their own context at the point of declaration, so avoid using them inside of `ivue` classes.
|
|
98
98
|
:::
|
|
99
99
|
|
|
100
|
-
## constructor() vs
|
|
100
|
+
## `.constructor()` vs `.init()`
|
|
101
101
|
|
|
102
|
-
#### Use
|
|
102
|
+
#### Use `.constructor()` to assign properties of the class and cast Refs to Unwrapped bare types. <br />
|
|
103
103
|
|
|
104
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 />
|
|
105
105
|
|
|
106
106
|
<hr />
|
|
107
107
|
|
|
108
|
-
Inside the
|
|
108
|
+
Inside the `.constructor()` method you still have access to non-reactive state, because when `.constructor()` is initialized, it does NOT yet have access to the reactive properties of the class, since it was not yet converted to `reactive()` by `ivue`, so if you use the properties like Refs or ComputedRefs inside `.constructor()` you would have to use them with the `.value`.
|
|
109
109
|
|
|
110
|
-
As a general rule, there is no need to manipulate the values in the
|
|
110
|
+
As a general rule, there is no need to manipulate the values in the `.constructor()`, 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 `reactive()` object.
|
|
111
111
|
|
|
112
|
-
**Let's look at a
|
|
112
|
+
**Let's look at a `.constructor()` vs `.init()` example:**
|
|
113
113
|
|
|
114
114
|
::: code-group
|
|
115
|
-
<<< @/components/guidelines/CounterExternalRefsDetailed.vue{
|
|
115
|
+
<<< @/components/guidelines/CounterExternalRefsDetailed.vue{vue:line-numbers}
|
|
116
116
|
:::
|
|
117
117
|
:::details For this example we initialize the component like this:
|
|
118
118
|
|
|
@@ -132,7 +132,7 @@ As a general rule, there is no need to manipulate the values in the `constructor
|
|
|
132
132
|
|
|
133
133
|
The key to working with `ivue` is understanding correctly the way Vue 3 does automatic Unwrapping of Refs when they are passed into the `reactive()` object. In that regard we are not relying on some magic `ivue` behavior but rather the default behavior of `reactive()` Vue 3 function.
|
|
134
134
|
|
|
135
|
-
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 `ivue` environment, where there is no need to worry about `.value`. This unwrapping should be mainly done inside the
|
|
135
|
+
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 `ivue` environment, where there is no need to worry about `.value`. This unwrapping should be mainly done inside the `.constructor()` method.
|
|
136
136
|
|
|
137
137
|
## Naming Conventions
|
|
138
138
|
|
|
@@ -4,26 +4,6 @@ import CounterBasic from '../components/usage/CounterBasic.vue'
|
|
|
4
4
|
|
|
5
5
|
# How it works?
|
|
6
6
|
|
|
7
|
-
## What ivue is NOT?
|
|
8
|
-
|
|
9
|
-
To understand how ivue works and how it does it, it is important to understand what it does not do.
|
|
10
|
-
|
|
11
|
-
::: info `ivue` is different from other class based libraries
|
|
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!
|
|
23
|
-
:::
|
|
24
|
-
|
|
25
|
-
## How it works?
|
|
26
|
-
|
|
27
7
|
```ts
|
|
28
8
|
export function ivue<T extends AnyClass>(
|
|
29
9
|
className: T,
|
|
@@ -35,22 +35,36 @@ See: [VueJs.org – Reactivity Transform](https://vuejs.org/guide/extras/rea
|
|
|
35
35
|
|
|
36
36
|
`ivue` is fully interoperable with Composition API and does not work against, but rather with it, so you can use all of ecosystems composables seamlessly.
|
|
37
37
|
|
|
38
|
-
`ivue` also offers a set of functions and utility types to make extensible & exportable props defaults, extensible emits
|
|
38
|
+
`ivue` also offers a set of functions and utility types to make extensible & exportable props defaults, extensible emits, extensible slots, etc. and much more possible.
|
|
39
39
|
|
|
40
|
+
`ivue` aims to be opaque, by giving the developer the Class API reactivity system.
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
`ivue` omits custom implementations of IOC Container, Decorators, Mixins, etc. by design.
|
|
43
|
+
|
|
44
|
+
`ivue` enforces a sane default standard of operation to contain the ever flexible Class API.
|
|
45
|
+
|
|
46
|
+
`ivue` uses Powerful Cutting Edge TypeScript to transform Vue 3 Refs to their base types, infer Class constructor arguments, infer Composable return types and function arguments and much more, making Object Oriented DX Experience with Vue 3 a breeze.
|
|
47
|
+
|
|
48
|
+
## OOP and TypeScript Class API in the Ecosystem
|
|
42
49
|
|
|
43
50
|
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.
|
|
44
51
|
|
|
45
52
|
While procedural programming has its strength, it also comes with its own weaknesses, like lack of inheritance, lack of `this` context, and thus lack of true composition.
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
&
|
|
50
|
-
&
|
|
51
|
-
&
|
|
54
|
+
## `ivue` is different
|
|
55
|
+
|
|
56
|
+
— `ivue` does NOT inherit from a base Class.<br />
|
|
57
|
+
— `ivue` does NOT use Decorators to achieve its objectives.<br />
|
|
58
|
+
— `ivue` does NOT alter Vue 3 underlying behavior, but rather relies on it.<br />
|
|
59
|
+
— `ivue` is NOT Class Components (though you can build components with it).<br />
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
::: tip IVUE IMPLEMENTS MINIMAL API ARCHITECTURE
|
|
63
|
+
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!
|
|
52
64
|
:::
|
|
53
65
|
|
|
66
|
+
|
|
67
|
+
|
|
54
68
|
## Infinite Vue Class Achitecture
|
|
55
69
|
|
|
56
70
|
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype ancestors chain thus supporting classical inheritance.
|
package/docs/docs/pages/usage.md
CHANGED
|
@@ -46,7 +46,7 @@ Using ivue is very simple, but you need to understand a few principles. See the
|
|
|
46
46
|
|
|
47
47
|
Classic Counter example built with `ivue`
|
|
48
48
|
::: code-group
|
|
49
|
-
<<< @/components/usage/CounterBasic.vue{
|
|
49
|
+
<<< @/components/usage/CounterBasic.vue{vue:line-numbers}
|
|
50
50
|
:::
|
|
51
51
|
|
|
52
52
|
:::details For this example we initialize the component like this:
|
|
@@ -206,7 +206,7 @@ function decrement() {
|
|
|
206
206
|
|
|
207
207
|
## Using Composables
|
|
208
208
|
|
|
209
|
-
### Assign
|
|
209
|
+
### Assign Vue 3 Composable to a class property
|
|
210
210
|
|
|
211
211
|
See the highlighted sections related to composable usage.
|
|
212
212
|
::: code-group
|
|
@@ -227,7 +227,7 @@ See the highlighted sections related to composable usage.
|
|
|
227
227
|
|
|
228
228
|
<CounterComposables />
|
|
229
229
|
|
|
230
|
-
###
|
|
230
|
+
### Destructure Vue 3 Composable into the class
|
|
231
231
|
|
|
232
232
|
See the highlighted sections related to destructuring composable usage.
|
|
233
233
|
|
|
@@ -251,7 +251,7 @@ See the highlighted sections related to destructuring composable usage.
|
|
|
251
251
|
<CounterComposablesDestructuring />
|
|
252
252
|
|
|
253
253
|
|
|
254
|
-
###
|
|
254
|
+
### Assign `ivue` Composables to a class property
|
|
255
255
|
|
|
256
256
|
Using `ivue` based composables assigned to a class property:
|
|
257
257
|
|
|
@@ -274,7 +274,7 @@ Using `ivue` based composables assigned to a class property:
|
|
|
274
274
|
|
|
275
275
|
<CounterComposablesIvue />
|
|
276
276
|
|
|
277
|
-
###
|
|
277
|
+
### Destructure `ivue` Composables Into Class Scope
|
|
278
278
|
|
|
279
279
|
See the sections related to using `ivue` based composables initialized through class destructuring assignment.
|
|
280
280
|
|
|
@@ -357,7 +357,7 @@ To use `watch`, `watchEffect`, and other reactive functions, declare `.init()` m
|
|
|
357
357
|
See the highlighted sections related to using `init()` below:
|
|
358
358
|
|
|
359
359
|
::: code-group
|
|
360
|
-
<<< @/components/usage/CounterWatch.vue{
|
|
360
|
+
<<< @/components/usage/CounterWatch.vue{vue:line-numbers}
|
|
361
361
|
:::
|
|
362
362
|
|
|
363
363
|
:::details For this example we initialize the component like this:
|
|
@@ -386,7 +386,7 @@ See the highlighted sections related to using `init()` below:
|
|
|
386
386
|
:::
|
|
387
387
|
|
|
388
388
|
::: code-group
|
|
389
|
-
<<< @/components/usage/CounterLifecycleHooks.vue{
|
|
389
|
+
<<< @/components/usage/CounterLifecycleHooks.vue{vue:line-numbers}
|
|
390
390
|
:::
|
|
391
391
|
|
|
392
392
|
:::details For this example we initialize the component like this:
|
package/docs/package.json
CHANGED
package/package.json
CHANGED
package/src/ivue.ts
CHANGED
|
@@ -53,9 +53,9 @@ export type UnwrapRefRecursively<T = any> = T extends Ref | DemiRef
|
|
|
53
53
|
: T;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Helper type for
|
|
56
|
+
* Helper type for Use type, unwraps any type of Vue 3 composable down to its bare types.
|
|
57
57
|
*/
|
|
58
|
-
export type
|
|
58
|
+
export type Unwrap<T> = T extends Ref | DemiRef
|
|
59
59
|
? UnwrapRefRecursively<T>
|
|
60
60
|
: {
|
|
61
61
|
[K in keyof T]: T[K] extends Ref | DemiRef
|
|
@@ -66,8 +66,8 @@ export type UnwrapComposableReturn<T> = T extends Ref | DemiRef
|
|
|
66
66
|
/**
|
|
67
67
|
* Fully unwraps to bare value types any Vue 3 composable return definition type.
|
|
68
68
|
*/
|
|
69
|
-
export type
|
|
70
|
-
ReturnType<T>
|
|
69
|
+
export type Use<T = any> = Unwrap<
|
|
70
|
+
T extends AnyFn ? ReturnType<T> : T
|
|
71
71
|
>;
|
|
72
72
|
|
|
73
73
|
/**
|
|
@@ -356,18 +356,18 @@ export function iuse<T extends AnyClass | AnyFn | Object | any>(
|
|
|
356
356
|
): T extends AnyClass
|
|
357
357
|
? InstanceType<T>
|
|
358
358
|
: T extends AnyFn
|
|
359
|
-
?
|
|
360
|
-
:
|
|
359
|
+
? Use<T>
|
|
360
|
+
: Unwrap<T> {
|
|
361
361
|
return typeof classFunctionObject === 'function'
|
|
362
362
|
? isClass(classFunctionObject)
|
|
363
363
|
? ivue(
|
|
364
364
|
classFunctionObject as T extends AnyClass ? T : any,
|
|
365
365
|
...(args as InferredArgs<T extends AnyClass ? T : any>)
|
|
366
|
-
).toRefs()
|
|
366
|
+
).toRefs(true)
|
|
367
367
|
: (classFunctionObject as AnyFn)(
|
|
368
368
|
...(args as Parameters<T extends AnyFn ? AnyFn : any>)
|
|
369
369
|
)
|
|
370
|
-
: (classFunctionObject as unknown as
|
|
370
|
+
: (classFunctionObject as unknown as Unwrap<T>);
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
/**
|