ivue 1.1.20 → 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 +3 -2
- 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/src/ivue.d.ts +17 -11
- package/docs/docs/.vitepress/config.ts +10 -4
- package/docs/docs/.vitepress/dist/404.html +2 -2
- package/docs/docs/.vitepress/dist/api/ivue.html +6 -6
- package/docs/docs/.vitepress/dist/api/propsWithDefaults.html +6 -6
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.Dcwh72Up.js → api_ivue.md.DyFbv52x.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.Dcwh72Up.lean.js → api_ivue.md.DyFbv52x.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.4_yVaZVQ.lean.js → api_propsWithDefaults.md.C6C7ZBZl.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.4_yVaZVQ.js → api_propsWithDefaults.md.C6C7ZBZl.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{app.BYfdK_hD.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.DTLsfrER.js → Button.vue_vue_type_script_setup_true_lang.Bynntqk6.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/{VPLocalSearchBox.BA9OZ_Zi.js → VPLocalSearchBox.hM-bvSJA.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/{framework.A0LWpETw.js → framework.CvEKxEoK.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.BJUrCfJB.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/{theme.CcUearAn.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.DW_gZ3PR.js → pages_advanced-usage.md.DsU0E8Oi.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_advanced-usage.md.DW_gZ3PR.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.B0SHw1kH.js → pages_browse-code.md.DhMpWRNv.js} +13 -11
- package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.B0SHw1kH.lean.js → pages_browse-code.md.DhMpWRNv.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.DNBViykD.js → pages_getting-started.md.CRguJKe8.js} +14 -12
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.DNBViykD.lean.js → pages_getting-started.md.CRguJKe8.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.CqaMa3nD.lean.js → pages_guidelines.md.yUFCB7mz.js} +3 -3
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.CqaMa3nD.js → pages_guidelines.md.yUFCB7mz.lean.js} +3 -3
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.DnT0w5vM.lean.js → pages_how-it-works.md.DDKhyGlo.js} +14 -12
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.DnT0w5vM.js → pages_how-it-works.md.DDKhyGlo.lean.js} +14 -12
- package/docs/docs/.vitepress/dist/assets/{pages_how-its-made.md.QUpGkW5C.js → pages_how-its-made.md.CCol99CD.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_how-its-made.md.QUpGkW5C.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.Csm2P67_.js → pages_usage.md.EDa7wXde.js} +27 -22
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.Csm2P67_.lean.js → pages_usage.md.EDa7wXde.lean.js} +27 -22
- package/docs/docs/.vitepress/dist/hashmap.json +1 -1
- package/docs/docs/.vitepress/dist/index.html +8 -8
- package/docs/docs/.vitepress/dist/pages/advanced-usage.html +6 -6
- package/docs/docs/.vitepress/dist/pages/api.html +7 -7
- package/docs/docs/.vitepress/dist/pages/browse-code.html +18 -16
- package/docs/docs/.vitepress/dist/pages/getting-started.html +19 -17
- package/docs/docs/.vitepress/dist/pages/guidelines.html +8 -8
- package/docs/docs/.vitepress/dist/pages/how-it-works.html +19 -17
- package/docs/docs/.vitepress/dist/pages/how-its-made.html +6 -6
- package/docs/docs/.vitepress/dist/pages/introduction.html +8 -8
- package/docs/docs/.vitepress/dist/pages/usage.html +32 -27
- package/docs/docs/components/usage/CounterComposablesIvueDestructuring.vue +1 -1
- package/docs/docs/components/usage/classes/CustomMouse.ts +3 -1
- package/docs/docs/components/usage/functions/useCustomMouse.ts +8 -3
- package/docs/docs/index.md +24 -16
- package/docs/docs/pages/api.md +1 -1
- package/docs/docs/pages/how-it-works.md +24 -10
- package/docs/docs/pages/introduction.md +4 -3
- package/docs/package.json +1 -1
- package/package.json +1 -1
- package/src/__tests__/ivue.vitest.spec.ts +22 -21
- package/src/ivue.ts +19 -14
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.MRMl6PRR.js +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.vxZiu-N0.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.DKVu1ndY.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.DKVu1ndY.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.CTVxqljG.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.CTVxqljG.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.Ce-jOv9s.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.Ce-jOv9s.lean.js +0 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useMouse } from '@vueuse/core';
|
|
2
|
-
import {
|
|
2
|
+
import { iuse, type UseComposable } from 'ivue';
|
|
3
3
|
|
|
4
4
|
type UseMouse = UseComposable<typeof useMouse>
|
|
5
5
|
|
|
6
6
|
export class CustomMouse {
|
|
7
|
+
|
|
7
8
|
x: UseMouse['x'];
|
|
8
9
|
y: UseMouse['y'];
|
|
10
|
+
|
|
9
11
|
constructor(public test: number) {
|
|
10
12
|
({ x: this.x, y: this.y } = iuse(useMouse()))
|
|
11
13
|
}
|
|
@@ -3,18 +3,23 @@ import { useMouse } from '@vueuse/core';
|
|
|
3
3
|
|
|
4
4
|
export function useCustomMouse() {
|
|
5
5
|
const { x, y } = useMouse();
|
|
6
|
+
|
|
6
7
|
const _sum = ref(0);
|
|
7
8
|
|
|
8
9
|
function sum() {
|
|
9
10
|
_sum.value = x.value + y.value;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
-
|
|
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;
|
|
14
17
|
});
|
|
15
18
|
|
|
16
19
|
const total = computed(() => {
|
|
17
|
-
|
|
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;
|
|
18
23
|
});
|
|
19
24
|
|
|
20
25
|
return {
|
package/docs/docs/index.md
CHANGED
|
@@ -2,43 +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
11
|
|
|
12
12
|
## `ivue` is
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
<div style="padding-left:20px;">
|
|
15
|
+
<div style="padding-left:20px; font-size: 20px; line-height: 32px;">
|
|
16
16
|
∞ Simple like Options API<br />
|
|
17
17
|
∞ Flexible like Composition API<br />
|
|
18
18
|
∞ Extensible like TypeScript Class API<br />
|
|
19
|
-
∞ Minimal, Opaque &
|
|
20
|
-
∞ 100%
|
|
19
|
+
∞ Robust, Minimal, Opaque & Unobtrusive<br />
|
|
20
|
+
∞ 100% VSCode / Intellij IDE Autocomplete Intellisence<br />
|
|
21
21
|
∞ 100% Vue 3 Compatible<br />
|
|
22
22
|
∞ 100% Test Covered<br />
|
|
23
|
+
∞ 100% Type Safe<br />
|
|
23
24
|
∞ Production Ready<br />
|
|
24
25
|
∞ Just <code>1.1kb</code> gzipped!<br />
|
|
25
26
|
</div>
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
## Features
|
|
29
|
-
<div style="padding-left:20px;">
|
|
30
|
-
&
|
|
31
|
-
&
|
|
32
|
-
&
|
|
33
|
-
&
|
|
34
|
-
&
|
|
35
|
-
&
|
|
36
|
-
&
|
|
37
|
-
– Provides Full TypeScript Support<br />
|
|
38
|
-
– Extends Vue 3 TypeScript Capability<br />
|
|
39
|
-
– Zero dependencies except Vue 3<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 />
|
|
40
38
|
</div>
|
|
41
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
|
+
|
|
42
50
|
## Next Step
|
|
43
51
|
|
|
44
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
|
@@ -22,7 +22,7 @@ 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
|
|
|
@@ -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.
|
|
@@ -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
|
|
|
@@ -18,12 +18,13 @@ See: [VueJs.org – Reactivity Transform](https://vuejs.org/guide/extras/rea
|
|
|
18
18
|
– Simple like Options API<br />
|
|
19
19
|
– Flexible like Composition API<br />
|
|
20
20
|
– Extensible like TypeScript Class API<br />
|
|
21
|
-
–
|
|
21
|
+
– Robust, Minimal, Opaque & Unobtrusive<br />
|
|
22
22
|
– 100% Vue 3 Compatible<br />
|
|
23
23
|
– 100% Test Covered<br />
|
|
24
24
|
– 100% Type Safe<br />
|
|
25
25
|
– Production Ready<br />
|
|
26
26
|
– Just <code>1.1kb</code> gzipped!<br />
|
|
27
|
+
– 100% VSCode / Intellij IDE Auto-complete Intellisence<br />
|
|
27
28
|
</div>
|
|
28
29
|
|
|
29
30
|
`ivue` is a powerful tool because it fully aligns itself with JavaScript / TypeScript Class API.
|
|
@@ -52,7 +53,7 @@ While procedural programming has its strength, it also comes with its own weakne
|
|
|
52
53
|
|
|
53
54
|
## Infinite Vue Class Achitecture
|
|
54
55
|
|
|
55
|
-
`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.
|
|
56
57
|
|
|
57
58
|
By using TypeScript we are able to infer the arguments of the main `ivue()` initializer function and pass the arguments to the constructor.
|
|
58
59
|
|
package/docs/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { PropType, isReactive
|
|
2
|
+
import { PropType, isReactive } from 'vue';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
ExtractPropDefaultTypes,
|
|
@@ -7,15 +7,16 @@ import {
|
|
|
7
7
|
getAllClassProperties,
|
|
8
8
|
isClass,
|
|
9
9
|
ivue,
|
|
10
|
+
iref,
|
|
10
11
|
propsWithDefaults,
|
|
11
12
|
} from '../ivue';
|
|
12
13
|
|
|
13
14
|
class Basic {
|
|
14
|
-
id =
|
|
15
|
+
id = iref('id');
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
class Bit {
|
|
18
|
-
_testProperty =
|
|
19
|
+
_testProperty = iref('test-value');
|
|
19
20
|
/** Setter without a getter. */
|
|
20
21
|
set testProperty(value: string) {
|
|
21
22
|
this._testProperty = value;
|
|
@@ -23,15 +24,15 @@ class Bit {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
class Item extends Bit {
|
|
26
|
-
_width =
|
|
27
|
-
unit =
|
|
27
|
+
_width = iref(5);
|
|
28
|
+
unit = iref('px');
|
|
28
29
|
get width(): string {
|
|
29
30
|
return this._width + this.unit;
|
|
30
31
|
}
|
|
31
32
|
set width(value: number) {
|
|
32
33
|
this._width = value;
|
|
33
34
|
}
|
|
34
|
-
_height =
|
|
35
|
+
_height = iref(5);
|
|
35
36
|
get height(): string {
|
|
36
37
|
return this._height + this.unit;
|
|
37
38
|
}
|
|
@@ -41,29 +42,29 @@ class Item extends Bit {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
class ProductItem extends Item {
|
|
44
|
-
_productType =
|
|
45
|
+
_productType = iref('generic');
|
|
45
46
|
get productType() {
|
|
46
47
|
return this._productType;
|
|
47
48
|
}
|
|
48
49
|
set productType(value) {
|
|
49
50
|
this._productType = value;
|
|
50
51
|
}
|
|
51
|
-
_productFit =
|
|
52
|
+
_productFit = iref('perfect-fit');
|
|
52
53
|
get productFit() {
|
|
53
54
|
return this._productFit;
|
|
54
55
|
}
|
|
55
|
-
_productId =
|
|
56
|
+
_productId = iref(0);
|
|
56
57
|
set productId(value: number) {
|
|
57
58
|
this._productId = 0;
|
|
58
59
|
}
|
|
59
|
-
_productFeel =
|
|
60
|
+
_productFeel = iref('sleek');
|
|
60
61
|
public get productFeel() {
|
|
61
62
|
return this._productFeel;
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
class StoreItem extends ProductItem {
|
|
66
|
-
_productType =
|
|
67
|
+
_productType = iref('store');
|
|
67
68
|
get productType() {
|
|
68
69
|
const prefix = super.productFeel ?? '';
|
|
69
70
|
return (prefix ? prefix + ':' : '') + this._productType;
|
|
@@ -74,9 +75,9 @@ class StoreItem extends ProductItem {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
class RetailStoreItem extends StoreItem {
|
|
77
|
-
_productType =
|
|
78
|
+
_productType = iref('retail');
|
|
78
79
|
/** Do not overwrite productType getter here, on purpose. */
|
|
79
|
-
productHistory =
|
|
80
|
+
productHistory = iref([]);
|
|
80
81
|
get testProperty() {
|
|
81
82
|
return this._testProperty;
|
|
82
83
|
}
|
|
@@ -89,9 +90,9 @@ let computedCalls = 0;
|
|
|
89
90
|
let notComputedCalls = 0;
|
|
90
91
|
|
|
91
92
|
class Entity {
|
|
92
|
-
_key =
|
|
93
|
-
height =
|
|
94
|
-
width =
|
|
93
|
+
_key = iref(0);
|
|
94
|
+
height = iref(0);
|
|
95
|
+
width = iref(0);
|
|
95
96
|
constructor(height: number, width = 5) {
|
|
96
97
|
this.height = height;
|
|
97
98
|
this.width = width;
|
|
@@ -240,23 +241,23 @@ describe('ivue', () => {
|
|
|
240
241
|
expect(item.width).toBe('10px');
|
|
241
242
|
});
|
|
242
243
|
|
|
243
|
-
it('parent getters from the prototype chain are working', () => {
|
|
244
|
+
it('parent getters from the prototype ancestors chain are working', () => {
|
|
244
245
|
const item = ivue(RetailStoreItem);
|
|
245
246
|
|
|
246
247
|
expect(item.productType).toBe('sleek:retail');
|
|
247
248
|
});
|
|
248
249
|
|
|
249
|
-
it('parent setters from the prototype chain are working', () => {
|
|
250
|
+
it('parent setters from the prototype ancestors chain are working', () => {
|
|
250
251
|
const item = ivue(RetailStoreItem);
|
|
251
252
|
|
|
252
253
|
expect(item.productType).toBe('sleek:retail');
|
|
253
254
|
/** SET VIA SETTER */
|
|
254
|
-
// @ts-expect-error ivue supports setting set and get separately in different levels of class prototype chain
|
|
255
|
+
// @ts-expect-error ivue supports setting set and get separately in different levels of class prototype ancestors chain
|
|
255
256
|
item.productType = 'new-retail';
|
|
256
257
|
expect(item.productType).toBe('sleek:new-retail');
|
|
257
258
|
});
|
|
258
259
|
|
|
259
|
-
it('parent setters that are set at different levels in the prototype chain work together in harmony', () => {
|
|
260
|
+
it('parent setters that are set at different levels in the prototype ancestors chain work together in harmony', () => {
|
|
260
261
|
const item = ivue(RetailStoreItem);
|
|
261
262
|
/**
|
|
262
263
|
* Setter for product feel is set on @see {StoreItem} class,
|
|
@@ -273,7 +274,7 @@ describe('ivue', () => {
|
|
|
273
274
|
|
|
274
275
|
expect(item._testProperty).toBe('test-value');
|
|
275
276
|
/** SET VIA SETTER */
|
|
276
|
-
// @ts-expect-error ivue supports setting set and get separately in different levels of class prototype chain
|
|
277
|
+
// @ts-expect-error ivue supports setting set and get separately in different levels of class prototype ancestors chain
|
|
277
278
|
item.testProperty = 'new-test-value';
|
|
278
279
|
expect(item._testProperty).toBe('new-test-value');
|
|
279
280
|
});
|
package/src/ivue.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type IVueRefs<T = any> = {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Unwraps
|
|
36
|
+
* Unwraps Ref Recursively, helps resolve fully the bare value types of any type T
|
|
37
37
|
* because sometimes the Refs are returned as they are with `.value` from computeds,
|
|
38
38
|
* thus inferring nested ComputedRef<ComputedRef<ComputedRef<Ref>>> types, which
|
|
39
39
|
* are difficult to fully resolve to bare values without this utility.
|
|
@@ -166,7 +166,7 @@ export type ValueOf<T extends Record<any, any>, K> = T[K];
|
|
|
166
166
|
export const descriptorsMap = new Map();
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
* Get descriptors of an entire class prototype chain as a Map.
|
|
169
|
+
* Get descriptors of an entire class prototype ancestors chain as a Map.
|
|
170
170
|
* Completely emulates JavaScript class inheritance chain for getters and setters.
|
|
171
171
|
*
|
|
172
172
|
* @param className
|
|
@@ -201,7 +201,7 @@ export function getAllClassDescriptors(className: AnyClass): Descriptors {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
);
|
|
204
|
-
/** Walk up the prototype chain. */
|
|
204
|
+
/** Walk up the prototype ancestors chain. */
|
|
205
205
|
prototype = Object.getPrototypeOf(prototype);
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -283,7 +283,7 @@ export function ivue<T extends AnyClass>(
|
|
|
283
283
|
export const propsMap: Map<object, Set<string> | any> = new Map();
|
|
284
284
|
|
|
285
285
|
/**
|
|
286
|
-
* Get properties of an entire class prototype chain as a Map.
|
|
286
|
+
* Get properties of an entire class prototype ancestors chain as a Map.
|
|
287
287
|
*/
|
|
288
288
|
export function getAllClassProperties(obj: object): Set<string> {
|
|
289
289
|
/* Retrieve props from cache */
|
|
@@ -312,28 +312,33 @@ export function getAllClassProperties(obj: object): Set<string> {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
/**
|
|
315
|
-
* `iref` is an
|
|
316
|
-
* `iref` does not alter the behavior of ref(), but simply
|
|
317
|
-
*
|
|
318
|
-
* @
|
|
319
|
-
* @returns
|
|
315
|
+
* `iref()` is an alias for Vue ref() function but returns an unwrapped type without the .value
|
|
316
|
+
* `iref()` does not alter the behavior of ref(), but simply transforms the type to an unwrapped raw value.
|
|
317
|
+
* @param val T
|
|
318
|
+
* @returns {UnwrapRef<T>}
|
|
320
319
|
*/
|
|
321
320
|
export function iref<T>(val?: T): UnwrapRef<T> {
|
|
322
321
|
return ref(val) as unknown as UnwrapRef<T>;
|
|
323
322
|
}
|
|
324
323
|
|
|
325
324
|
/**
|
|
326
|
-
*
|
|
327
|
-
*
|
|
325
|
+
* Two modes of operation:
|
|
326
|
+
* 1. `iuse()` converts the types of a Composable / Ref to pure raw type definition.
|
|
327
|
+
* Returns for all properties of an object an unwrapped raw type definition,
|
|
328
|
+
* unwraps direct Refs & ComputedRefs as well.
|
|
329
|
+
*
|
|
330
|
+
* 2. If AnyClass is supplied into `iuse(AnyClass, ...args)` and that class's ...args,
|
|
331
|
+
* it returns a 'ivue(AnyClass, ...args).toRefs()` object for all properties but casts
|
|
332
|
+
* their types as raw (no-Ref) types to fit with reactive() structure of the
|
|
333
|
+
* ivue wrapper class context.
|
|
328
334
|
*/
|
|
329
|
-
|
|
330
335
|
export function iuse<T extends AnyClass | Object>(
|
|
331
336
|
val?: T,
|
|
332
337
|
...args: InferredArgs<T>
|
|
333
|
-
): T extends AnyClass ?
|
|
338
|
+
): T extends AnyClass ? InstanceType<T> : UnwrapComposableReturn<T> {
|
|
334
339
|
return isClass(val)
|
|
335
340
|
? ivue(
|
|
336
|
-
val as T extends AnyClass ? T :
|
|
341
|
+
val as T extends AnyClass ? T : any,
|
|
337
342
|
...(args as InferredArgs<T>)
|
|
338
343
|
).toRefs()
|
|
339
344
|
: (val as unknown as UnwrapComposableReturn<T>);
|