ivue 1.1.21 → 1.2.0
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 +74 -78
- package/dist/index.umd.js +1 -1
- package/dist/src/ivue.d.ts +15 -22
- package/docs/docs/.vitepress/dist/404.html +2 -2
- package/docs/docs/.vitepress/dist/api/ivue.html +3 -3
- package/docs/docs/.vitepress/dist/api/propsWithDefaults.html +3 -3
- package/docs/docs/.vitepress/dist/assets/{app.CQ7kL6_f.js → app.Cnbc-twM.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.DVtkHDuS.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/{VPLocalSearchBox.hM-bvSJA.js → VPLocalSearchBox.BrRdnkds.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/{theme.BQo6cm_A.js → theme.qh_SBkj1.js} +2 -2
- package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.DhMpWRNv.js → pages_browse-code.md.BXwbCBZ0.js} +26 -19
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.CRguJKe8.js → pages_getting-started.md.BqHPrEWq.js} +26 -19
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.CRguJKe8.lean.js → pages_getting-started.md.BqHPrEWq.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.yUFCB7mz.js → pages_guidelines.md.Dkyp5V72.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.yUFCB7mz.lean.js → pages_guidelines.md.Dkyp5V72.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.DDKhyGlo.js → pages_how-it-works.md.Bf_7UZG9.js} +26 -19
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.DDKhyGlo.lean.js → pages_how-it-works.md.Bf_7UZG9.lean.js} +26 -19
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.EDa7wXde.js → pages_usage.md.C-dTtOlJ.js} +101 -71
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.EDa7wXde.lean.js → pages_usage.md.C-dTtOlJ.lean.js} +101 -71
- package/docs/docs/.vitepress/dist/hashmap.json +1 -1
- package/docs/docs/.vitepress/dist/index.html +3 -3
- package/docs/docs/.vitepress/dist/pages/advanced-usage.html +3 -3
- package/docs/docs/.vitepress/dist/pages/api.html +3 -3
- package/docs/docs/.vitepress/dist/pages/browse-code.html +30 -23
- package/docs/docs/.vitepress/dist/pages/getting-started.html +30 -23
- package/docs/docs/.vitepress/dist/pages/guidelines.html +5 -5
- package/docs/docs/.vitepress/dist/pages/how-it-works.html +30 -23
- package/docs/docs/.vitepress/dist/pages/how-its-made.html +3 -3
- package/docs/docs/.vitepress/dist/pages/introduction.html +3 -3
- package/docs/docs/.vitepress/dist/pages/usage.html +104 -74
- package/docs/docs/components/usage/CounterComposablesDestructuring.vue +12 -7
- package/docs/docs/components/usage/CounterComposablesIvueDestructuring.vue +11 -2
- package/docs/docs/components/usage/classes/CustomMouse.ts +13 -8
- package/docs/docs/components/usage/functions/useCustomMouse.ts +3 -9
- package/docs/docs/pages/usage.md +12 -10
- package/docs/package.json +1 -1
- package/package.json +1 -1
- package/src/ivue.ts +21 -19
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.DPHmCl-3.js +0 -1
- /package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.DhMpWRNv.lean.js → pages_browse-code.md.BXwbCBZ0.lean.js} +0 -0
|
@@ -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
|
|
10
|
+
type UseCustomMouse = UseComposable<typeof useCustomMouse>;
|
|
11
11
|
|
|
12
12
|
class Counter {
|
|
13
13
|
count = iref(0);
|
|
@@ -16,12 +16,17 @@ class Counter {
|
|
|
16
16
|
this.count++;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
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
|
|
23
|
+
* Vue 3's `reactive()` Proxy will be able to resolve those Refs internally.
|
|
24
|
+
*/
|
|
25
|
+
x: UseCustomMouse['x']; // Unwrapped Ref<number> becomes -> number
|
|
26
|
+
y: UseCustomMouse['y']; // Unwrapped Ref<number> becomes -> number
|
|
22
27
|
|
|
23
|
-
sum:
|
|
24
|
-
total:
|
|
28
|
+
sum: UseCustomMouse['sum']; // 'sum' method that will be destructured into this class on construct()
|
|
29
|
+
total: UseCustomMouse['total']; // 'total' computed Ref that will also be destructured into this class on construct()
|
|
25
30
|
|
|
26
31
|
constructor() {
|
|
27
32
|
({
|
|
@@ -29,7 +34,7 @@ class Counter {
|
|
|
29
34
|
y: this.y,
|
|
30
35
|
sum: this.sum,
|
|
31
36
|
total: this.total
|
|
32
|
-
} = iuse(useCustomMouse()));
|
|
37
|
+
} = iuse(useCustomMouse(5)));
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -10,15 +10,23 @@ class Counter {
|
|
|
10
10
|
this.count++;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 'x', 'y', 'total' are Refs that will be unwrapped to their bare raw types and destructured into the class.
|
|
16
|
+
* Even though unwrapped (de-Refed), they will maintain their behavior as Refs and thus will maintain reactivity
|
|
17
|
+
* and at the same time get destructured into this class root level scope because
|
|
18
|
+
* Vue 3's `reactive()` Proxy will be able to resolve those Refs internally.
|
|
19
|
+
*/
|
|
14
20
|
x: CustomMouse['x']; // Unwrapped Ref<number> becomes -> number
|
|
15
21
|
y: CustomMouse['y']; // Unwrapped Ref<number> becomes -> number
|
|
16
|
-
total: CustomMouse['total']; // Unwrapped
|
|
22
|
+
total: CustomMouse['total']; // Unwrapped ComputedRef<number> becomes -> number
|
|
23
|
+
sum: CustomMouse['sum']; // Function remains a function
|
|
17
24
|
|
|
18
25
|
constructor() {
|
|
19
26
|
({
|
|
20
27
|
x: this.x,
|
|
21
28
|
y: this.y,
|
|
29
|
+
sum: this.sum,
|
|
22
30
|
total: this.total,
|
|
23
31
|
} = iuse(CustomMouse, 5));
|
|
24
32
|
}
|
|
@@ -33,4 +41,5 @@ const counter = ivue(Counter);
|
|
|
33
41
|
<br />
|
|
34
42
|
Total (computed): {{ counter.total }}
|
|
35
43
|
<br />
|
|
44
|
+
<button class="button" @click="() => counter.sum()">Click This Big Sum Button To Total X + Y</button>
|
|
36
45
|
</template>
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { useMouse } from '@vueuse/core';
|
|
2
|
-
import { iuse,
|
|
2
|
+
import { iref, iuse, type UseComposable } from '../../../../../src/ivue';
|
|
3
3
|
|
|
4
|
-
type UseMouse = UseComposable<typeof useMouse
|
|
4
|
+
type UseMouse = UseComposable<typeof useMouse>;
|
|
5
5
|
|
|
6
6
|
export class CustomMouse {
|
|
7
|
-
|
|
8
7
|
x: UseMouse['x'];
|
|
9
8
|
y: UseMouse['y'];
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
_sum = iref(0);
|
|
11
|
+
|
|
12
|
+
constructor(public requiredProp: number) {
|
|
13
|
+
({ x: this.x, y: this.y } = iuse(useMouse()));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
sum() {
|
|
17
|
+
this._sum = this.x + this.y + this.requiredProp;
|
|
13
18
|
}
|
|
14
|
-
|
|
19
|
+
|
|
15
20
|
get total() {
|
|
16
|
-
return this.
|
|
21
|
+
return this._sum;
|
|
17
22
|
}
|
|
18
|
-
}
|
|
23
|
+
}
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { computed, ref } from 'vue';
|
|
2
2
|
import { useMouse } from '@vueuse/core';
|
|
3
3
|
|
|
4
|
-
export function useCustomMouse() {
|
|
4
|
+
export function useCustomMouse(requiredProp: number) {
|
|
5
5
|
const { x, y } = useMouse();
|
|
6
6
|
|
|
7
7
|
const _sum = ref(0);
|
|
8
8
|
|
|
9
9
|
function sum() {
|
|
10
|
-
_sum.value = x.value + y.value;
|
|
10
|
+
_sum.value = x.value + y.value + requiredProp;
|
|
11
11
|
}
|
|
12
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
13
|
const total = computed(() => {
|
|
20
14
|
// Returning without .value, not entirely correctly, but will still work in Vue template.
|
|
21
15
|
// This is to test the impressive IVue unwrapping capabilities of deeply nested and confusing Refs
|
|
22
|
-
return
|
|
16
|
+
return _sum;
|
|
23
17
|
});
|
|
24
18
|
|
|
25
19
|
return {
|
package/docs/docs/pages/usage.md
CHANGED
|
@@ -249,19 +249,20 @@ See the highlighted sections related to destructuring composable usage.
|
|
|
249
249
|
|
|
250
250
|
<CounterComposablesDestructuring />
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
### Using `ivue` Composables With Destructuring
|
|
253
253
|
|
|
254
|
-
See the highlighted sections related to using `ivue`
|
|
254
|
+
See the highlighted sections related to using `ivue` based composables.
|
|
255
255
|
|
|
256
256
|
::: code-group
|
|
257
|
-
<<< @/components/usage/
|
|
257
|
+
<<< @/components/usage/CounterComposablesIvueDestructuring.vue{14 vue:line-numbers}
|
|
258
|
+
<<< @/components/usage/classes/CustomMouse.ts{ts:line-numbers} [classes/CustomMouse.ts]
|
|
258
259
|
:::
|
|
259
260
|
|
|
260
261
|
:::details For this example we initialize the component like this:
|
|
261
262
|
|
|
262
263
|
```vue
|
|
263
264
|
<template>
|
|
264
|
-
<
|
|
265
|
+
<CounterComposablesIvueDestructuring />
|
|
265
266
|
</template>
|
|
266
267
|
```
|
|
267
268
|
|
|
@@ -269,21 +270,22 @@ See the highlighted sections related to using `ivue` inside a composable.
|
|
|
269
270
|
|
|
270
271
|
<div style="font-size: 18px; font-weight: 500;">Result</div>
|
|
271
272
|
|
|
272
|
-
<
|
|
273
|
+
<CounterComposablesIvueDestructuring />
|
|
273
274
|
|
|
274
|
-
## Using `ivue` Composables
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
## Using Inside Composables
|
|
277
|
+
|
|
278
|
+
See the highlighted sections related to using `ivue` inside a composable.
|
|
277
279
|
|
|
278
280
|
::: code-group
|
|
279
|
-
<<< @/components/usage/
|
|
281
|
+
<<< @/components/usage/CounterInsideComposables.vue{14 vue:line-numbers}
|
|
280
282
|
:::
|
|
281
283
|
|
|
282
284
|
:::details For this example we initialize the component like this:
|
|
283
285
|
|
|
284
286
|
```vue
|
|
285
287
|
<template>
|
|
286
|
-
<
|
|
288
|
+
<CounterInsideComposables />
|
|
287
289
|
</template>
|
|
288
290
|
```
|
|
289
291
|
|
|
@@ -291,7 +293,7 @@ See the highlighted sections related to using `ivue` based composables.
|
|
|
291
293
|
|
|
292
294
|
<div style="font-size: 18px; font-weight: 500;">Result</div>
|
|
293
295
|
|
|
294
|
-
<
|
|
296
|
+
<CounterInsideComposables />
|
|
295
297
|
|
|
296
298
|
## Using Computeds
|
|
297
299
|
|
package/docs/package.json
CHANGED
package/package.json
CHANGED
package/src/ivue.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
import type { ComputedRef, ExtractPropTypes, Ref, ToRef } from 'vue';
|
|
4
|
-
import {
|
|
4
|
+
import { computed, reactive, ref, toRef } from 'vue';
|
|
5
5
|
import type { Ref as DemiRef } from 'vue-demi';
|
|
6
6
|
|
|
7
7
|
/** Types */
|
|
@@ -44,7 +44,7 @@ export type UnwrapRefRecursively<T = any> = T extends Ref | DemiRef
|
|
|
44
44
|
: T;
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* Helper type for UseComposable.
|
|
47
|
+
* Helper type for UseComposable, unwraps any type of Vue 3 composable down to its bare types.
|
|
48
48
|
*/
|
|
49
49
|
export type UnwrapComposableReturn<T> = T extends Ref | DemiRef
|
|
50
50
|
? UnwrapRefRecursively<T>
|
|
@@ -57,7 +57,7 @@ export type UnwrapComposableReturn<T> = T extends Ref | DemiRef
|
|
|
57
57
|
/**
|
|
58
58
|
* Fully unwraps to bare value types any Vue 3 composable return definition type.
|
|
59
59
|
*/
|
|
60
|
-
export type UseComposable<T extends
|
|
60
|
+
export type UseComposable<T extends AnyFn> =
|
|
61
61
|
UnwrapComposableReturn<ReturnType<T>>;
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -85,18 +85,23 @@ export type ExtendSlots<T> = PrefixKeys<T, 'before--'> &
|
|
|
85
85
|
PrefixKeys<T, 'after--'>;
|
|
86
86
|
|
|
87
87
|
/** Helper Types. */
|
|
88
|
+
/**
|
|
89
|
+
* Any JavaScript function of any type.
|
|
90
|
+
*/
|
|
91
|
+
export type AnyFn = (...args: any[]) => any;
|
|
92
|
+
|
|
88
93
|
/**
|
|
89
94
|
* Any JavaScript class of any type.
|
|
90
95
|
*/
|
|
91
96
|
export type AnyClass = abstract new (...args: any[]) => any;
|
|
92
97
|
|
|
93
98
|
/**
|
|
94
|
-
* Descriptors map.
|
|
99
|
+
* Descriptors map type.
|
|
95
100
|
*/
|
|
96
101
|
export type Descriptors = Map<string, PropertyDescriptor>;
|
|
97
102
|
|
|
98
103
|
/**
|
|
99
|
-
* Computeds hash map.
|
|
104
|
+
* Computeds hash map type.
|
|
100
105
|
*/
|
|
101
106
|
export type Computeds = Record<string, ComputedRef>;
|
|
102
107
|
|
|
@@ -135,7 +140,7 @@ export type IFnParameter<
|
|
|
135
140
|
* Get function arguments Parmeters<F> parameter by key K
|
|
136
141
|
*/
|
|
137
142
|
export type FnParameter<
|
|
138
|
-
F extends
|
|
143
|
+
F extends AnyFn,
|
|
139
144
|
K extends number
|
|
140
145
|
> = Parameters<F>[K];
|
|
141
146
|
|
|
@@ -317,20 +322,17 @@ export function getAllClassProperties(obj: object): Set<string> {
|
|
|
317
322
|
* @param val T
|
|
318
323
|
* @returns {UnwrapRef<T>}
|
|
319
324
|
*/
|
|
320
|
-
export
|
|
321
|
-
return ref(val) as unknown as UnwrapRef<T>;
|
|
322
|
-
}
|
|
325
|
+
export const iref = ref as <T = any>(value: T) => T;
|
|
323
326
|
|
|
324
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.
|
|
331
|
-
* it returns
|
|
332
|
-
* their types as raw (
|
|
333
|
-
* ivue wrapper class context.
|
|
328
|
+
* Two modes of operation:
|
|
329
|
+
* 1. `iuse(useComposable(arg, arg2, arg3, ...))` converts the return types of a Composable / Ref to pure raw type definition.
|
|
330
|
+
* Returns for all properties of an object an unwrapped raw type definition,
|
|
331
|
+
* unwraps direct Refs & ComputedRefs as well down to their raw types.
|
|
332
|
+
*
|
|
333
|
+
* 2. `iuse(AnyClass, ...args)` If AnyClass is supplied and that class's arguments like so `iuse(AnyClass, ...args)`,
|
|
334
|
+
* it returns an 'ivue(AnyClass, ...args).toRefs()` ivue object in Vee 3 Composable standard form for all properties but casts
|
|
335
|
+
* their types as raw (non-Ref) types to fit with reactive() structure of the ivue class context.
|
|
334
336
|
*/
|
|
335
337
|
export function iuse<T extends AnyClass | Object>(
|
|
336
338
|
val?: T,
|
|
@@ -352,7 +354,7 @@ export function iuse<T extends AnyClass | Object>(
|
|
|
352
354
|
* @param computeds @see Computeds
|
|
353
355
|
* @returns {ExtendWithToRefs<T>['toRefs']}
|
|
354
356
|
*/
|
|
355
|
-
|
|
357
|
+
function ivueToRefs<T extends AnyClass>(
|
|
356
358
|
vue: IVue<T>,
|
|
357
359
|
descriptors: Descriptors,
|
|
358
360
|
computeds: Computeds
|