ivue 1.2.4 → 1.3.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/coverage/clover.xml +177 -176
- package/coverage/coverage-final.json +1 -1
- package/coverage/index.html +18 -18
- package/coverage/index.ts.html +1 -1
- package/coverage/ivue.ts.html +176 -146
- package/dist/index.es.js +47 -46
- package/dist/index.umd.js +1 -1
- package/dist/src/ivue.d.ts +17 -8
- package/docs/docs/.vitepress/config.ts +16 -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.D_gfERxK.js → app.C_6IW306.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.Cfu1MyIk.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/{VPLocalSearchBox.BzoUb0RV.js → VPLocalSearchBox.BEJZ5WJL.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/{index.es.D191XnPH.js → index.es.B1_StH0Z.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/{theme.CzkYYfOm.js → theme.COJ5Yu8m.js} +2 -2
- package/docs/docs/.vitepress/dist/assets/{pages_advanced-usage.md.DsU0E8Oi.js → pages_advanced-usage.md.Xwq8hk_w.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_advanced-usage.md.DsU0E8Oi.lean.js → pages_advanced-usage.md.Xwq8hk_w.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.Bo9Kusmf.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_api.md.Bo9Kusmf.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.BhmYOQjE.js → pages_browse-code.md.BS0BRUx_.js} +39 -29
- package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.C8UElRkE.js → pages_getting-started.md.BbVqm1ey.js} +39 -29
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.C2kOmJCV.js → pages_guidelines.md.fL8xf0Gx.js} +3 -3
- package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.C2kOmJCV.lean.js → pages_guidelines.md.fL8xf0Gx.lean.js} +3 -3
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.D6PSCfuz.js → pages_how-it-works.md.CP31gYQw.js} +39 -29
- package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.D6PSCfuz.lean.js → pages_how-it-works.md.CP31gYQw.lean.js} +39 -29
- package/docs/docs/.vitepress/dist/assets/pages_how-its-made.md.C02KZK0J.js +1 -0
- package/docs/docs/.vitepress/dist/assets/{pages_introduction.md.MtnX0UvH.js → pages_introduction.md.B6foeVXQ.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_introduction.md.MtnX0UvH.lean.js → pages_introduction.md.B6foeVXQ.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.Dw6OzuOj.js → pages_usage.md.5C8BnzAi.js} +24 -24
- package/docs/docs/.vitepress/dist/assets/{pages_usage.md.Dw6OzuOj.lean.js → pages_usage.md.5C8BnzAi.lean.js} +24 -24
- 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 +5 -5
- package/docs/docs/.vitepress/dist/pages/api.html +6 -6
- package/docs/docs/.vitepress/dist/pages/browse-code.html +43 -33
- package/docs/docs/.vitepress/dist/pages/getting-started.html +44 -34
- package/docs/docs/.vitepress/dist/pages/guidelines.html +8 -8
- package/docs/docs/.vitepress/dist/pages/how-it-works.html +44 -34
- package/docs/docs/.vitepress/dist/pages/how-its-made.html +5 -5
- package/docs/docs/.vitepress/dist/pages/introduction.html +5 -5
- package/docs/docs/.vitepress/dist/pages/usage.html +28 -28
- package/docs/docs/components/advanced-usage/ConvertLegacy.vue +58 -0
- package/docs/docs/pages/advanced-usage.md +2 -1
- package/docs/docs/pages/api.md +7 -3
- package/docs/docs/pages/guidelines.md +1 -1
- package/docs/docs/pages/how-its-made.md +3 -3
- package/docs/docs/pages/introduction.md +1 -1
- package/docs/package.json +1 -1
- package/package.json +6 -1
- package/src/__tests__/ivue.vitest.spec.ts +61 -7
- package/src/ivue.ts +34 -24
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.ChoKIVFM.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.bOEtTo1m.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_api.md.bOEtTo1m.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_how-its-made.md.CCol99CD.js +0 -1
- /package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.BhmYOQjE.lean.js → pages_browse-code.md.BS0BRUx_.lean.js} +0 -0
- /package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.C8UElRkE.lean.js → pages_getting-started.md.BbVqm1ey.lean.js} +0 -0
- /package/docs/docs/.vitepress/dist/assets/{pages_how-its-made.md.CCol99CD.lean.js → pages_how-its-made.md.C02KZK0J.lean.js} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
class Chair {
|
|
3
|
+
// Defaults that will be common for all the instances
|
|
4
|
+
static backSupport: boolean = true;
|
|
5
|
+
static armRests: boolean = true;
|
|
6
|
+
|
|
7
|
+
// Instance properties
|
|
8
|
+
color: string;
|
|
9
|
+
seatHeight: number;
|
|
10
|
+
recliningAngle: number;
|
|
11
|
+
headSupport: boolean;
|
|
12
|
+
padding: string;
|
|
13
|
+
seatSize: string;
|
|
14
|
+
isHeightAdjustable: boolean;
|
|
15
|
+
isMovable: boolean;
|
|
16
|
+
type: string;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
color: string,
|
|
20
|
+
seatHeight: number,
|
|
21
|
+
recliningAngle: number,
|
|
22
|
+
headSupport: boolean,
|
|
23
|
+
padding: string,
|
|
24
|
+
seatSize: string,
|
|
25
|
+
isHeightAdjustable: boolean,
|
|
26
|
+
isMovable: boolean
|
|
27
|
+
) {
|
|
28
|
+
// Defaults which can be changed by the subclass class.
|
|
29
|
+
this.color = color;
|
|
30
|
+
this.seatHeight = seatHeight;
|
|
31
|
+
this.recliningAngle = recliningAngle;
|
|
32
|
+
this.headSupport = headSupport || false;
|
|
33
|
+
this.padding = padding || "3 inch";
|
|
34
|
+
this.seatSize = seatSize || "16 inch";
|
|
35
|
+
this.isHeightAdjustable = isHeightAdjustable || false;
|
|
36
|
+
this.isMovable = isMovable || false;
|
|
37
|
+
this.type = "Chair";
|
|
38
|
+
console.log(Chair.printDefaultProps()); // Usage of static method inside constructor
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static logObjectProps(): void {
|
|
42
|
+
console.dir(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Static within static usage
|
|
46
|
+
static printDefaultProps(): void {
|
|
47
|
+
console.log(`Chair Back Support = ${this.backSupport}`);
|
|
48
|
+
console.log(`Arm rests support = ${this.armRests}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
adjustableHeight(): void {};
|
|
52
|
+
adjustAngle(): void {};
|
|
53
|
+
moveChair(): void {};
|
|
54
|
+
}
|
|
55
|
+
</script>
|
|
56
|
+
<template>
|
|
57
|
+
<div>Hello</div>
|
|
58
|
+
</template>
|
package/docs/docs/pages/api.md
CHANGED
|
@@ -28,7 +28,11 @@ Core `ivue(className, ...args)` initializer is able to infer and validate the co
|
|
|
28
28
|
|
|
29
29
|
### `iref()`
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Is simply an alias to Vue 3 `ref()` function but casts the type to the internal unreactive type, because properties auto-unwrap in `reactive()` object that is being created by `ivue` upon initialization.
|
|
32
|
+
|
|
33
|
+
### `ishallowRef()`
|
|
34
|
+
|
|
35
|
+
Is simply an alias Vue 3 `shallowRef()` function but casts the type to the internal unreactive type, because properties auto-unwrap in `reactive()` object that is being created by `ivue` upon initialization.
|
|
32
36
|
|
|
33
37
|
### `iuse()`
|
|
34
38
|
|
|
@@ -77,9 +81,9 @@ This improves performance if `box` has many other properties that we do not need
|
|
|
77
81
|
|
|
78
82
|
## Core Types
|
|
79
83
|
|
|
80
|
-
### `IVue`
|
|
84
|
+
### `IVue` {#IVue}
|
|
81
85
|
|
|
82
|
-
### `Use`
|
|
86
|
+
### `Use` {#Use}
|
|
83
87
|
|
|
84
88
|
|
|
85
89
|
## Utility Functions
|
|
@@ -7,9 +7,9 @@ The original inspiration for `ivue` comes from `MobX` React state management lib
|
|
|
7
7
|
|
|
8
8
|
## Epiphany
|
|
9
9
|
|
|
10
|
-
After building several ports from `MobX` state management library to `VueJS` to reactivity system I realized that Vue itself is far superior in its design and
|
|
10
|
+
After building several ports from `MobX` state management library to `VueJS` to reactivity system I realized that Vue itself is far superior in its design and performance and can solve the same problem without relying on second hand-library, but for that my evolution of understanding of how JavaScript getters and setters work needed to happen.
|
|
11
11
|
|
|
12
|
-
And one lucky and sunny day driving back from work in an eureka moment of light it
|
|
12
|
+
And one lucky and sunny day driving back from work in an eureka moment of light it occurred to me how to use Vue 3 computeds in place of getters in classes (Yes, apparently my brain does coding while driving a car).
|
|
13
13
|
|
|
14
14
|
`ivue` relies on this very simple discovery of how to elegantly convert getters into Vue 3 computeds.
|
|
15
15
|
|
|
@@ -28,5 +28,5 @@ By default `ivue` does not rely on decorators, though you can use decorators if
|
|
|
28
28
|
|
|
29
29
|
## The Rest is Up To You
|
|
30
30
|
`ivue` is like a small mustard seed core for the big tree trunk of Class Based Reactive applications to be built around it, that's why the path of utter simplicity was chosen.
|
|
31
|
-
Everything else like an Inversion of Control (IOC) system, Traits, Mixins, Decorators can be built around the core `ivue` architecture and is
|
|
31
|
+
Everything else like an Inversion of Control (IOC) system, Traits, Mixins, Decorators can be built around the core `ivue` architecture and is up to the community of enthusiastic open source contributors, please share with us your vision of how you and all of can use `ivue` better.
|
|
32
32
|
|
|
@@ -65,7 +65,7 @@ Things like IOC Container, Decorators, Traits, Mixins, etc. were omitted by desi
|
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
## Infinite Vue Class
|
|
68
|
+
## Infinite Vue Class Architecture
|
|
69
69
|
|
|
70
70
|
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype ancestors chain thus supporting classical inheritance.
|
|
71
71
|
|
package/docs/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ivue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Infinite Vue – Class Based Architecture for Vue 3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
"vue": "^3.0.0",
|
|
27
27
|
"vue-demi": "^0.0.0"
|
|
28
28
|
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"vue-demi": {
|
|
31
|
+
"optional": true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
29
34
|
"devDependencies": {
|
|
30
35
|
"@cypress/vite-dev-server": "^5.0.2",
|
|
31
36
|
"@cypress/vue": "^5.0.3",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { PropType, isReactive } from 'vue';
|
|
2
|
+
import { PropType, isReactive, ref } from 'vue';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
ExtractPropDefaultTypes,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ivue,
|
|
10
10
|
iref,
|
|
11
11
|
propsWithDefaults,
|
|
12
|
+
iuse,
|
|
12
13
|
} from '../ivue';
|
|
13
14
|
|
|
14
15
|
class Basic {
|
|
@@ -431,6 +432,58 @@ describe('ivue', () => {
|
|
|
431
432
|
expect(notComputedCalls).toBe(3); // Always incrementing
|
|
432
433
|
});
|
|
433
434
|
});
|
|
435
|
+
describe('core functions', () => {
|
|
436
|
+
let useComposable = () => {
|
|
437
|
+
return {
|
|
438
|
+
x: ref(0),
|
|
439
|
+
y: ref(0)
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
it('iref returns standard ref with .value but unwraps type', () => {
|
|
443
|
+
const bool = iref(true);
|
|
444
|
+
const str = iref('string');
|
|
445
|
+
|
|
446
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
447
|
+
expect(bool.value).toBe(true);
|
|
448
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
449
|
+
expect(str.value).toBe('string');
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('iuse(Object) returns standard ref with .value but unwraps type', () => {
|
|
453
|
+
const iuseComposable = iuse(useComposable());
|
|
454
|
+
|
|
455
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
456
|
+
expect(iuseComposable.x.value).toBe(0)
|
|
457
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
458
|
+
expect(iuseComposable.y.value).toBe(0);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('iuse(Class, ...ClassProps) returns standard ref with .value but unwraps type', () => {
|
|
462
|
+
const iuseComposable = iuse(Item);
|
|
463
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
464
|
+
expect(iuseComposable._width.value).toBe(5)
|
|
465
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
466
|
+
expect(iuseComposable.unit.value).toBe('px');
|
|
467
|
+
|
|
468
|
+
const iuseComposable2 = iuse(Entity, 100);
|
|
469
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
470
|
+
expect(iuseComposable2.height.value).toBe(100)
|
|
471
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
472
|
+
expect(iuseComposable2.width.value).toBe(5);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('iuse(Function, ...FunctionProps) returns standard ref with .value but unwraps type', () => {
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
const iuseComposable = iuse(useComposable);
|
|
479
|
+
|
|
480
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
481
|
+
expect(iuseComposable.x.value).toBe(0)
|
|
482
|
+
// @ts-expect-error Unwraps type, only to be used within ivue Class or Vue 3 `reactive()` context
|
|
483
|
+
expect(iuseComposable.y.value).toBe(0);
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
|
|
434
487
|
|
|
435
488
|
describe('util functions', () => {
|
|
436
489
|
it('isClass correctly determines if a value is a class', () => {
|
|
@@ -474,7 +527,8 @@ describe('ivue', () => {
|
|
|
474
527
|
updatePath: '', // String
|
|
475
528
|
updateEntity: false, // Boolean
|
|
476
529
|
updateFieldsTemplate: [], // Array
|
|
477
|
-
updateFieldsParams: {
|
|
530
|
+
updateFieldsParams: {
|
|
531
|
+
// Object
|
|
478
532
|
active: true,
|
|
479
533
|
},
|
|
480
534
|
updateLabel: 'Update Item', // String
|
|
@@ -496,23 +550,23 @@ describe('ivue', () => {
|
|
|
496
550
|
expect(_propsWithDefaults.updateFieldsTemplate.default).toBeTypeOf(
|
|
497
551
|
'function'
|
|
498
552
|
);
|
|
499
|
-
expect(
|
|
553
|
+
expect(
|
|
500
554
|
Array.isArray(
|
|
501
555
|
(_propsWithDefaults.updateFieldsTemplate.default as () => any)()
|
|
502
556
|
)
|
|
503
557
|
).toBe(true);
|
|
504
|
-
|
|
558
|
+
|
|
505
559
|
// Object
|
|
506
|
-
expect(
|
|
560
|
+
expect(
|
|
507
561
|
(_propsWithDefaults.updateFieldsParams.default as () => any)().active
|
|
508
562
|
).toBe(true);
|
|
509
|
-
|
|
563
|
+
|
|
510
564
|
// Class
|
|
511
565
|
expect(_propsWithDefaults.runner.default).toBeTypeOf('function');
|
|
512
566
|
expect(isClass((_propsWithDefaults.runner.default as () => any)())).toBe(
|
|
513
567
|
true
|
|
514
568
|
);
|
|
515
|
-
|
|
569
|
+
|
|
516
570
|
// Function
|
|
517
571
|
expect(_propsWithDefaults.fn.default).toBeTypeOf('function');
|
|
518
572
|
expect(isClass((_propsWithDefaults.fn.default as () => any)())).toBe(
|
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 { computed, reactive, ref, toRef } from 'vue';
|
|
4
|
+
import { computed, reactive, ref, shallowRef, toRef } from 'vue';
|
|
5
5
|
import type { Ref as DemiRef } from 'vue-demi';
|
|
6
6
|
|
|
7
7
|
/** Types */
|
|
@@ -19,15 +19,21 @@ export interface ExtendWithToRefs<T extends AnyClass> {
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Type definition for `.toRefs()` method converts reactive class properties to composable .value properties.
|
|
22
|
-
* But if unwrap = true is specified, the refs will be unwrapped refs
|
|
22
|
+
* But if props = true OR unwrap = true is specified, the refs will be unwrapped refs to be able to be merged with the the root class properties without losing reactivity.
|
|
23
23
|
*/
|
|
24
24
|
export interface IVueToRefsFn<T extends AnyClass> {
|
|
25
|
-
<P extends keyof InstanceType<T
|
|
25
|
+
<P extends keyof InstanceType<T>>(props: P[]): Pick<
|
|
26
|
+
IVueRefs<InstanceType<T>>,
|
|
27
|
+
P
|
|
28
|
+
>;
|
|
29
|
+
<P extends keyof InstanceType<T>>(props: P[], unwrap: false): Pick<
|
|
30
|
+
IVueRefs<InstanceType<T>>,
|
|
31
|
+
P
|
|
32
|
+
>;
|
|
33
|
+
<P extends keyof InstanceType<T>>(
|
|
26
34
|
props: P[],
|
|
27
|
-
unwrap
|
|
28
|
-
):
|
|
29
|
-
? Pick<InstanceType<T>, P>
|
|
30
|
-
: Pick<IVueRefs<InstanceType<T>>, P>;
|
|
35
|
+
unwrap: true
|
|
36
|
+
): Pick<InstanceType<T>, P>;
|
|
31
37
|
(props: true): InstanceType<T>;
|
|
32
38
|
(props: false): IVueRefs<InstanceType<T>>;
|
|
33
39
|
(): IVueRefs<InstanceType<T>>;
|
|
@@ -66,9 +72,7 @@ export type Unwrap<T> = T extends Ref | DemiRef
|
|
|
66
72
|
/**
|
|
67
73
|
* Fully unwraps to bare value types any Vue 3 composable return definition type.
|
|
68
74
|
*/
|
|
69
|
-
export type Use<T = any> = Unwrap<
|
|
70
|
-
T extends AnyFn ? ReturnType<T> : T
|
|
71
|
-
>;
|
|
75
|
+
export type Use<T = any> = Unwrap<T extends AnyFn ? ReturnType<T> : T>;
|
|
72
76
|
|
|
73
77
|
/**
|
|
74
78
|
* Extracts object defined emit types by converting them to a plain interface
|
|
@@ -324,17 +328,25 @@ export function getAllClassProperties(obj: object): Set<string> {
|
|
|
324
328
|
}
|
|
325
329
|
|
|
326
330
|
/**
|
|
327
|
-
* `iref()` is an alias for Vue ref() function but returns an
|
|
328
|
-
* `iref()` does not alter the behavior of ref(), but simply transforms the type to an
|
|
331
|
+
* `iref()` is an alias for Vue ref() function but returns an unwrapped type without the .value
|
|
332
|
+
* `iref()` does not alter the behavior of ref(), but simply transforms the type to an unwrapped raw value.
|
|
329
333
|
* @param val T
|
|
330
|
-
* @returns {
|
|
334
|
+
* @returns {T}
|
|
331
335
|
*/
|
|
332
336
|
export const iref = ref as <T = any>(value?: T) => T;
|
|
333
337
|
|
|
338
|
+
/**
|
|
339
|
+
* `ishallowRef()` is an alias for Vue shallowRef() function but returns an unwrapped type without the .value
|
|
340
|
+
* `ishallowRef()` does not alter the behavior of shallowRef(), but simply transforms the type to an unwrapped raw value.
|
|
341
|
+
* @param val T
|
|
342
|
+
* @returns {T}
|
|
343
|
+
*/
|
|
344
|
+
export const ishallowRef = shallowRef as <T = any>(value?: T) => T;
|
|
345
|
+
|
|
334
346
|
/**
|
|
335
347
|
* Three modes of operation:
|
|
336
|
-
* 1. `iuse(useComposable(arg, arg2, arg3, ...))` converts the return types of a Composable / Ref to pure raw type definition.
|
|
337
|
-
* Returns for all properties of an object an
|
|
348
|
+
* 1. `iuse(useComposable(arg, arg2, arg3, ...))` converts the return types of a Composable / Ref to pure raw unwrapped type definition.
|
|
349
|
+
* Returns for all properties of an object an unwrapped raw type definition,
|
|
338
350
|
* unwraps direct Refs & ComputedRefs as well down to their raw types.
|
|
339
351
|
*
|
|
340
352
|
* 2. `iuse(useComposable, arg, arg2, arg3, ...)` for cleaner syntax for #1, it does exactly the same thing but
|
|
@@ -353,21 +365,19 @@ export function iuse<T extends AnyClass | AnyFn | Object | any>(
|
|
|
353
365
|
: T extends AnyFn
|
|
354
366
|
? Parameters<T extends (...args: any[]) => any ? T : any>
|
|
355
367
|
: any
|
|
356
|
-
): T extends AnyClass
|
|
357
|
-
? InstanceType<T>
|
|
358
|
-
: T extends AnyFn
|
|
359
|
-
? Use<T>
|
|
360
|
-
: Unwrap<T> {
|
|
368
|
+
): T extends AnyClass ? InstanceType<T> : Use<T> {
|
|
361
369
|
return typeof classFunctionObject === 'function'
|
|
362
370
|
? isClass(classFunctionObject)
|
|
363
|
-
?
|
|
371
|
+
? /** Run IVUE but return full Refs, yet property 'true' makes `.toRefs(true)` cast the type to the unwrapped raw type definition instead of a `.value` Ref. */
|
|
372
|
+
ivue(
|
|
364
373
|
classFunctionObject as T extends AnyClass ? T : any,
|
|
365
374
|
...(args as InferredArgs<T extends AnyClass ? T : any>)
|
|
366
375
|
).toRefs(true)
|
|
367
|
-
:
|
|
376
|
+
: /** Run Vue 3 Standard Composable but also unwrap it to bare raw types. */
|
|
377
|
+
(classFunctionObject as AnyFn)(
|
|
368
378
|
...(args as Parameters<T extends AnyFn ? AnyFn : any>)
|
|
369
379
|
)
|
|
370
|
-
: (classFunctionObject as unknown as Unwrap<T>)
|
|
380
|
+
: (classFunctionObject as unknown as Unwrap<T>) /** Unwrap any other Object or any type down to its bare types. */;
|
|
371
381
|
}
|
|
372
382
|
|
|
373
383
|
/**
|
|
@@ -385,7 +395,7 @@ function ivueToRefs<T extends AnyClass>(
|
|
|
385
395
|
): ExtendWithToRefs<T>['toRefs'] {
|
|
386
396
|
return function (
|
|
387
397
|
props?: (keyof InstanceType<T>)[] | boolean,
|
|
388
|
-
unwrap?: boolean
|
|
398
|
+
unwrap?: boolean /** This property helps with TypeScript function definition overloading of return types and is not being used inside the function itself. */
|
|
389
399
|
): any /** @see {ReturnType<IVueToRefsFn<T>>} */ {
|
|
390
400
|
/** Resulting refs store. */
|
|
391
401
|
const result: Record<string | number | symbol, any> = {};
|