ivue 1.1.21 → 1.2.1
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 +21 -23
- 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 +51 -34
- 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 '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,8 +57,9 @@ 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
|
|
61
|
-
|
|
60
|
+
export type UseComposable<T extends AnyFn> = UnwrapComposableReturn<
|
|
61
|
+
ReturnType<T>
|
|
62
|
+
>;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Extracts object defined emit types by converting them to a plain interface
|
|
@@ -85,18 +86,23 @@ export type ExtendSlots<T> = PrefixKeys<T, 'before--'> &
|
|
|
85
86
|
PrefixKeys<T, 'after--'>;
|
|
86
87
|
|
|
87
88
|
/** Helper Types. */
|
|
89
|
+
/**
|
|
90
|
+
* Any JavaScript function of any type.
|
|
91
|
+
*/
|
|
92
|
+
export type AnyFn = (...args: any[]) => any;
|
|
93
|
+
|
|
88
94
|
/**
|
|
89
95
|
* Any JavaScript class of any type.
|
|
90
96
|
*/
|
|
91
97
|
export type AnyClass = abstract new (...args: any[]) => any;
|
|
92
98
|
|
|
93
99
|
/**
|
|
94
|
-
* Descriptors map.
|
|
100
|
+
* Descriptors map type.
|
|
95
101
|
*/
|
|
96
102
|
export type Descriptors = Map<string, PropertyDescriptor>;
|
|
97
103
|
|
|
98
104
|
/**
|
|
99
|
-
* Computeds hash map.
|
|
105
|
+
* Computeds hash map type.
|
|
100
106
|
*/
|
|
101
107
|
export type Computeds = Record<string, ComputedRef>;
|
|
102
108
|
|
|
@@ -134,10 +140,7 @@ export type IFnParameter<
|
|
|
134
140
|
/**
|
|
135
141
|
* Get function arguments Parmeters<F> parameter by key K
|
|
136
142
|
*/
|
|
137
|
-
export type FnParameter<
|
|
138
|
-
F extends (...args: any[]) => any,
|
|
139
|
-
K extends number
|
|
140
|
-
> = Parameters<F>[K];
|
|
143
|
+
export type FnParameter<F extends AnyFn, K extends number> = Parameters<F>[K];
|
|
141
144
|
|
|
142
145
|
/**
|
|
143
146
|
* Convert Union Type to Intersection Type.
|
|
@@ -317,31 +320,45 @@ export function getAllClassProperties(obj: object): Set<string> {
|
|
|
317
320
|
* @param val T
|
|
318
321
|
* @returns {UnwrapRef<T>}
|
|
319
322
|
*/
|
|
320
|
-
export
|
|
321
|
-
return ref(val) as unknown as UnwrapRef<T>;
|
|
322
|
-
}
|
|
323
|
+
export const iref = ref as <T = any>(value?: T) => T;
|
|
323
324
|
|
|
324
325
|
/**
|
|
325
|
-
*
|
|
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
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
326
|
+
* Three modes of operation:
|
|
327
|
+
* 1. `iuse(useComposable(arg, arg2, arg3, ...))` converts the return types of a Composable / Ref to pure raw type definition.
|
|
328
|
+
* Returns for all properties of an object an unwrapped raw type definition,
|
|
329
|
+
* unwraps direct Refs & ComputedRefs as well down to their raw types.
|
|
330
|
+
*
|
|
331
|
+
* 2. `iuse(useComposable, arg, arg2, arg3, ...)` for cleaner syntax for #1, it does exactly the same thing but
|
|
332
|
+
* here the TypeScript inference works for composable function arguments to assist you with intellisence,
|
|
333
|
+
* like they work for constructor arguments in the cause of `ivue()` core function,
|
|
334
|
+
* making the API cleaner to look at and make it compatible with how this function operates with classes, see #3.
|
|
335
|
+
*
|
|
336
|
+
* 3. `iuse(AnyClass, ...args)` If AnyClass is supplied and that class's arguments into `iuse(AnyClass, ...args)`,
|
|
337
|
+
* it returns an 'ivue(AnyClass, ...args).toRefs()` object for all properties but casts
|
|
338
|
+
* their types as raw (no-Ref) types to fit with reactive() structure of the ivue class context.
|
|
339
|
+
*/
|
|
340
|
+
export function iuse<T extends AnyClass | AnyFn | Object>(
|
|
341
|
+
classFunctionObject?: T,
|
|
342
|
+
...args: T extends AnyClass
|
|
343
|
+
? InferredArgs<T>
|
|
344
|
+
: T extends AnyFn
|
|
345
|
+
? Parameters<T extends (...args: any[]) => any ? T : any>
|
|
346
|
+
: any
|
|
347
|
+
): T extends AnyClass
|
|
348
|
+
? InstanceType<T>
|
|
349
|
+
: T extends AnyFn
|
|
350
|
+
? UseComposable<T>
|
|
351
|
+
: UnwrapComposableReturn<T> {
|
|
352
|
+
return typeof classFunctionObject === 'function'
|
|
353
|
+
? isClass(classFunctionObject)
|
|
354
|
+
? ivue(
|
|
355
|
+
classFunctionObject as T extends AnyClass ? T : any,
|
|
356
|
+
...(args as InferredArgs<T extends AnyClass ? T : any>)
|
|
357
|
+
).toRefs()
|
|
358
|
+
: (classFunctionObject as AnyFn)(
|
|
359
|
+
...(args as Parameters<T extends AnyFn ? AnyFn : any>)
|
|
360
|
+
)
|
|
361
|
+
: (classFunctionObject as unknown as UnwrapComposableReturn<T>);
|
|
345
362
|
}
|
|
346
363
|
|
|
347
364
|
/**
|
|
@@ -352,7 +369,7 @@ export function iuse<T extends AnyClass | Object>(
|
|
|
352
369
|
* @param computeds @see Computeds
|
|
353
370
|
* @returns {ExtendWithToRefs<T>['toRefs']}
|
|
354
371
|
*/
|
|
355
|
-
|
|
372
|
+
function ivueToRefs<T extends AnyClass>(
|
|
356
373
|
vue: IVue<T>,
|
|
357
374
|
descriptors: Descriptors,
|
|
358
375
|
computeds: Computeds
|