ivue 1.5.6 → 1.5.8
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/dist/index.es.js +11 -12
- package/dist/index.umd.js +1 -1
- package/dist/ivue.d.ts +10 -23
- package/lib/ivue.ts +19 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## About
|
|
4
4
|
|
|
5
|
-
`ivue` is a TypeScript class based composable architecture for Vue 3, that unlocks infinite scalability for Vue 3 based apps. It allows you to extend
|
|
5
|
+
`ivue` is a TypeScript class based composable architecture for Vue 3, that unlocks infinite scalability for Vue 3 based apps. It allows you to extend regular Vue 3 in a simple and elegant way.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
– Simple & Elegant Architecture<br />
|
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
– Flexible like Composition API<br />
|
|
23
23
|
– Extensible like TypeScript Class API<br />
|
|
24
24
|
– Robust, Minimal, Opaque & Unobtrusive<br />
|
|
25
|
+
– Pure Object Oriented Reactivity System based on Vue 3 Composition API<br />
|
|
25
26
|
– 100% Vue 3 Compatible<br />
|
|
26
27
|
– 100% Test Covered<br />
|
|
27
28
|
– 100% Type Safe<br />
|
|
28
29
|
– Production Ready<br />
|
|
29
30
|
– Just <code>1.1kb</code> gzipped!<br />
|
|
30
|
-
– 100% VSCode / Intellij IDE Auto-complete
|
|
31
|
+
– 100% VSCode / Intellij IDE Auto-complete Intellisense<br />
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { reactive as
|
|
1
|
+
import { reactive as v, computed as b, ref as A, shallowRef as D, toRef as m } from "vue";
|
|
2
2
|
const d = /* @__PURE__ */ new Map();
|
|
3
|
-
function
|
|
3
|
+
function E(e) {
|
|
4
4
|
if (d.has(e))
|
|
5
5
|
return d.get(e);
|
|
6
6
|
const o = /* @__PURE__ */ new Map();
|
|
@@ -12,9 +12,9 @@ function D(e) {
|
|
|
12
12
|
}), t = Object.getPrototypeOf(t);
|
|
13
13
|
return d.set(e, o), o;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function M(e, ...o) {
|
|
16
16
|
var i, O;
|
|
17
|
-
const t =
|
|
17
|
+
const t = E(e), f = t != null && t.size ? {} : null, r = v(new e(...o));
|
|
18
18
|
for (const [n, l] of t)
|
|
19
19
|
((i = e == null ? void 0 : e.ivue) == null ? void 0 : i[n]) !== !1 && Object.defineProperty(r, n, { get: l.get ? () => {
|
|
20
20
|
var a, g;
|
|
@@ -62,28 +62,27 @@ function C(e) {
|
|
|
62
62
|
while (e.constructor !== Object);
|
|
63
63
|
return y.set(o, t), t;
|
|
64
64
|
}
|
|
65
|
-
const z =
|
|
65
|
+
const z = A, N = D;
|
|
66
66
|
function W(e, ...o) {
|
|
67
|
-
return typeof e == "function" ?
|
|
67
|
+
return typeof e == "function" ? R(e) ? M(e, ...o).toRefs(!0) : e(...o) : e;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function R(e) {
|
|
70
70
|
var o;
|
|
71
71
|
return typeof e == "function" && !!e.prototype && !((o = Object.getOwnPropertyDescriptor(e, "prototype")) != null && o.writable);
|
|
72
72
|
}
|
|
73
73
|
function k(e, o) {
|
|
74
74
|
for (const t in o)
|
|
75
|
-
typeof (e == null ? void 0 : e[t]) == "object" && (e == null ? void 0 : e[t]) !== null ||
|
|
75
|
+
typeof (e == null ? void 0 : e[t]) == "object" && (e == null ? void 0 : e[t]) !== null || R(e == null ? void 0 : e[t]) ? o[t].default = () => e == null ? void 0 : e[t] : o[t].default = e == null ? void 0 : e[t];
|
|
76
76
|
return o;
|
|
77
77
|
}
|
|
78
78
|
export {
|
|
79
79
|
d as descriptorsMap,
|
|
80
|
-
|
|
80
|
+
E as getAllClassDescriptors,
|
|
81
81
|
C as getAllClassProperties,
|
|
82
82
|
z as iref,
|
|
83
|
-
|
|
83
|
+
R as isClass,
|
|
84
84
|
N as ishallowRef,
|
|
85
85
|
W as iuse,
|
|
86
|
-
|
|
87
|
-
y as propsMap,
|
|
86
|
+
M as ivue,
|
|
88
87
|
k as propsWithDefaults
|
|
89
88
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):f((c=typeof globalThis<"u"?globalThis:c||self).ivue={},c.Vue)})(this,function(c,f){"use strict";const y=new Map;function j(t){if(y.has(t))return y.get(t);const r=new Map;let e=t.prototype;for(;e.constructor!==Object;)Object.entries(Object.getOwnPropertyDescriptors(e)).forEach(([l,n])=>{const i=r.get(l);i!==n&&(n!=null&&n.get||n!=null&&n.set)&&(i!=null&&i.get&&(n.get=i==null?void 0:i.get),i!=null&&i.set&&(n.set=i==null?void 0:i.set),r.set(l,n))}),e=Object.getPrototypeOf(e);return y.set(t,r),r}function w(t,...r){var i,P;const e=j(t),l=e!=null&&e.size?{}:null,n=f.reactive(new t(...r));for(const[s,d]of e)((i=t==null?void 0:t.ivue)==null?void 0:i[s])!==!1&&Object.defineProperty(n,s,{get:d.get?()=>{var p,b;return s in l?l[s]:l[s]=f.computed({get:(p=d.get)==null?void 0:p.bind(n),set:(b=d.set)==null?void 0:b.bind(n)})}:void 0,set:(P=d.set)==null?void 0:P.bind(n),enumerable:!1});return Object.defineProperty(n,"toRefs",{get:()=>function(s,d,p){return function(b,S){var v,
|
|
1
|
+
(function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):f((c=typeof globalThis<"u"?globalThis:c||self).ivue={},c.Vue)})(this,function(c,f){"use strict";const y=new Map;function j(t){if(y.has(t))return y.get(t);const r=new Map;let e=t.prototype;for(;e.constructor!==Object;)Object.entries(Object.getOwnPropertyDescriptors(e)).forEach(([l,n])=>{const i=r.get(l);i!==n&&(n!=null&&n.get||n!=null&&n.set)&&(i!=null&&i.get&&(n.get=i==null?void 0:i.get),i!=null&&i.set&&(n.set=i==null?void 0:i.set),r.set(l,n))}),e=Object.getPrototypeOf(e);return y.set(t,r),r}function w(t,...r){var i,P;const e=j(t),l=e!=null&&e.size?{}:null,n=f.reactive(new t(...r));for(const[s,d]of e)((i=t==null?void 0:t.ivue)==null?void 0:i[s])!==!1&&Object.defineProperty(n,s,{get:d.get?()=>{var p,b;return s in l?l[s]:l[s]=f.computed({get:(p=d.get)==null?void 0:p.bind(n),set:(b=d.set)==null?void 0:b.bind(n)})}:void 0,set:(P=d.set)==null?void 0:P.bind(n),enumerable:!1});return Object.defineProperty(n,"toRefs",{get:()=>function(s,d,p){return function(b,S){var v,R;const g={};if(Array.isArray(b))for(let a=0;a<b.length;a++){const o=b[a];if(d.has(o))if(o in p)g[o]=p[o];else{const u=d.get(o);g[o]=p[o]=f.computed({get:(v=u==null?void 0:u.get)==null?void 0:v.bind(s),set:(R=u==null?void 0:u.set)==null?void 0:R.bind(s)})}else typeof s[o]=="function"?g[o]=s[o].bind(s):g[o]=f.toRef(s,o)}else{let a=new Set(m(s));d.forEach((o,u)=>{var M,A;g[u]=u in p?p[u]:p[u]=f.computed({get:(M=o.get)==null?void 0:M.bind(s),set:(A=o.set)==null?void 0:A.bind(s)}),a==null||a.delete(u)}),a.forEach(o=>{typeof s[o]=="function"?g[o]=s[o].bind(s):g[o]=f.toRef(s,o)}),a=null}return g}}(n,e,l),enumerable:!1}),"init"in n&&n.init(),n}const O=new Map;function m(t){if(O.has(t.constructor))return O.get(t.constructor);const r=t.constructor,e=new Set;do Object.getOwnPropertyNames(t).forEach(l=>{["caller","callee","arguments","constructor"].includes(l)||e.add(l)}),t=Object.getPrototypeOf(t);while(t.constructor!==Object);return O.set(r,e),e}const D=f.ref,E=f.shallowRef;function h(t){var r;return typeof t=="function"&&!!t.prototype&&!((r=Object.getOwnPropertyDescriptor(t,"prototype"))!=null&&r.writable)}c.descriptorsMap=y,c.getAllClassDescriptors=j,c.getAllClassProperties=m,c.iref=D,c.isClass=h,c.ishallowRef=E,c.iuse=function(t,...r){return typeof t=="function"?h(t)?w(t,...r).toRefs(!0):t(...r):t},c.ivue=w,c.propsWithDefaults=function(t,r){for(const e in r)typeof(t==null?void 0:t[e])=="object"&&(t==null?void 0:t[e])!==null||h(t==null?void 0:t[e])?r[e].default=()=>t==null?void 0:t[e]:r[e].default=t==null?void 0:t[e];return r},Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/dist/ivue.d.ts
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExtractPropTypes, Ref, ToRef } from 'vue';
|
|
2
2
|
import type { Ref as DemiRef } from 'vue-demi';
|
|
3
3
|
/** Types */
|
|
4
4
|
/**
|
|
5
5
|
* IVue core reactive instance type with an extended .toRefs() method added.
|
|
6
6
|
*/
|
|
7
|
-
export declare type IVue<T extends AnyClass> = InstanceType<T> &
|
|
8
|
-
/**
|
|
9
|
-
* Extend with .toRefs() method, so that a reactive class can be converted to a composable definition.
|
|
10
|
-
*/
|
|
11
|
-
export interface ExtendWithToRefs<T extends AnyClass> {
|
|
7
|
+
export declare type IVue<T extends AnyClass> = InstanceType<T> & {
|
|
12
8
|
toRefs: IVueToRefsFn<T>;
|
|
13
|
-
}
|
|
9
|
+
};
|
|
14
10
|
/**
|
|
15
11
|
* Type definition for `.toRefs()` method converts reactive class properties to composable .value properties.
|
|
16
12
|
* 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.
|
|
17
13
|
*/
|
|
18
|
-
|
|
14
|
+
interface IVueToRefsFn<T extends AnyClass> {
|
|
19
15
|
<P extends keyof InstanceType<T>>(props: P[]): Pick<IVueRefs<InstanceType<T>>, P>;
|
|
20
16
|
<P extends keyof InstanceType<T>>(props: P[], unwrap: false): Pick<IVueRefs<InstanceType<T>>, P>;
|
|
21
17
|
<P extends keyof InstanceType<T>>(props: P[], unwrap: true): Pick<InstanceType<T>, P>;
|
|
@@ -27,7 +23,7 @@ export interface IVueToRefsFn<T extends AnyClass> {
|
|
|
27
23
|
* Converts a class properties to a composable .value Refs using ToRef vue type,
|
|
28
24
|
* also knows NOT to convert functions to .value Refs but to leave them as is.
|
|
29
25
|
*/
|
|
30
|
-
export declare type IVueRefs<T
|
|
26
|
+
export declare type IVueRefs<T> = {
|
|
31
27
|
[K in keyof T]: T[K] extends Function ? T[K] : ToRef<T[K]>;
|
|
32
28
|
};
|
|
33
29
|
/**
|
|
@@ -37,17 +33,17 @@ export declare type IVueRefs<T = any> = {
|
|
|
37
33
|
* are difficult to fully resolve to bare values without this utility.
|
|
38
34
|
* Also support Vue 3 Demi for vue-use library support.
|
|
39
35
|
*/
|
|
40
|
-
|
|
36
|
+
declare type UnwrapRefRecursively<T = any> = T extends Ref | DemiRef ? UnwrapRefRecursively<T['value']> : T;
|
|
41
37
|
/**
|
|
42
|
-
* Helper type for Use type, unwraps any type of Vue 3 composable down to its bare types.
|
|
38
|
+
* Helper type for Use type, unwraps any type of Vue 3 composable return object down to its bare types.
|
|
43
39
|
*/
|
|
44
|
-
|
|
40
|
+
declare type UnwrapComposableRefs<T> = T extends Ref | DemiRef ? UnwrapRefRecursively<T> : {
|
|
45
41
|
[K in keyof T]: T[K] extends Ref | DemiRef ? UnwrapRefRecursively<T[K]> : T[K];
|
|
46
42
|
};
|
|
47
43
|
/**
|
|
48
44
|
* Fully unwraps to bare value types any Vue 3 composable return definition type.
|
|
49
45
|
*/
|
|
50
|
-
export declare type Use<T = any> =
|
|
46
|
+
export declare type Use<T = any> = T extends Ref | DemiRef ? UnwrapRefRecursively<T> : UnwrapComposableRefs<T extends AnyFn ? ReturnType<T> : T>;
|
|
51
47
|
/**
|
|
52
48
|
* Extracts object defined emit types by converting them to a plain interface
|
|
53
49
|
*/
|
|
@@ -76,11 +72,7 @@ export declare type AnyClass = abstract new (...args: any[]) => any;
|
|
|
76
72
|
/**
|
|
77
73
|
* Descriptors map type.
|
|
78
74
|
*/
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Computeds hash map type.
|
|
82
|
-
*/
|
|
83
|
-
export declare type Computeds = Record<string, ComputedRef>;
|
|
75
|
+
declare type Descriptors = Map<string, PropertyDescriptor>;
|
|
84
76
|
/**
|
|
85
77
|
* Infer paramaters of a constructor function of a Class.
|
|
86
78
|
*/
|
|
@@ -152,11 +144,6 @@ export declare function getAllClassDescriptors(className: AnyClass): Descriptors
|
|
|
152
144
|
* @returns {IVue<T>}
|
|
153
145
|
*/
|
|
154
146
|
export declare function ivue<T extends AnyClass>(className: T, ...args: InferredArgs<T>): IVue<T>;
|
|
155
|
-
/**
|
|
156
|
-
* Store all props for each class prototype processed by:
|
|
157
|
-
* @see {getAllClassProperties}
|
|
158
|
-
*/
|
|
159
|
-
export declare const propsMap: Map<object, Set<string> | any>;
|
|
160
147
|
/**
|
|
161
148
|
* Get properties of an entire class prototype ancestors chain as a Map.
|
|
162
149
|
*/
|
package/lib/ivue.ts
CHANGED
|
@@ -8,20 +8,15 @@ import type { Ref as DemiRef } from 'vue-demi';
|
|
|
8
8
|
/**
|
|
9
9
|
* IVue core reactive instance type with an extended .toRefs() method added.
|
|
10
10
|
*/
|
|
11
|
-
export type IVue<T extends AnyClass> = InstanceType<T> &
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Extend with .toRefs() method, so that a reactive class can be converted to a composable definition.
|
|
15
|
-
*/
|
|
16
|
-
export interface ExtendWithToRefs<T extends AnyClass> {
|
|
11
|
+
export type IVue<T extends AnyClass> = InstanceType<T> & {
|
|
17
12
|
toRefs: IVueToRefsFn<T>;
|
|
18
|
-
}
|
|
13
|
+
};
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* Type definition for `.toRefs()` method converts reactive class properties to composable .value properties.
|
|
22
17
|
* 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
18
|
*/
|
|
24
|
-
|
|
19
|
+
interface IVueToRefsFn<T extends AnyClass> {
|
|
25
20
|
<P extends keyof InstanceType<T>>(props: P[]): Pick<
|
|
26
21
|
IVueRefs<InstanceType<T>>,
|
|
27
22
|
P
|
|
@@ -30,10 +25,10 @@ export interface IVueToRefsFn<T extends AnyClass> {
|
|
|
30
25
|
IVueRefs<InstanceType<T>>,
|
|
31
26
|
P
|
|
32
27
|
>;
|
|
33
|
-
<P extends keyof InstanceType<T>>(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
<P extends keyof InstanceType<T>>(props: P[], unwrap: true): Pick<
|
|
29
|
+
InstanceType<T>,
|
|
30
|
+
P
|
|
31
|
+
>;
|
|
37
32
|
(props: true): InstanceType<T>;
|
|
38
33
|
(props: false): IVueRefs<InstanceType<T>>;
|
|
39
34
|
(): IVueRefs<InstanceType<T>>;
|
|
@@ -43,7 +38,7 @@ export interface IVueToRefsFn<T extends AnyClass> {
|
|
|
43
38
|
* Converts a class properties to a composable .value Refs using ToRef vue type,
|
|
44
39
|
* also knows NOT to convert functions to .value Refs but to leave them as is.
|
|
45
40
|
*/
|
|
46
|
-
export type IVueRefs<T
|
|
41
|
+
export type IVueRefs<T> = {
|
|
47
42
|
[K in keyof T]: T[K] extends Function ? T[K] : ToRef<T[K]>;
|
|
48
43
|
};
|
|
49
44
|
|
|
@@ -54,14 +49,14 @@ export type IVueRefs<T = any> = {
|
|
|
54
49
|
* are difficult to fully resolve to bare values without this utility.
|
|
55
50
|
* Also support Vue 3 Demi for vue-use library support.
|
|
56
51
|
*/
|
|
57
|
-
|
|
52
|
+
type UnwrapRefRecursively<T = any> = T extends Ref | DemiRef
|
|
58
53
|
? UnwrapRefRecursively<T['value']>
|
|
59
54
|
: T;
|
|
60
55
|
|
|
61
56
|
/**
|
|
62
|
-
* Helper type for Use type, unwraps any type of Vue 3 composable down to its bare types.
|
|
57
|
+
* Helper type for Use type, unwraps any type of Vue 3 composable return object down to its bare types.
|
|
63
58
|
*/
|
|
64
|
-
|
|
59
|
+
type UnwrapComposableRefs<T> = T extends Ref | DemiRef
|
|
65
60
|
? UnwrapRefRecursively<T>
|
|
66
61
|
: {
|
|
67
62
|
[K in keyof T]: T[K] extends Ref | DemiRef
|
|
@@ -72,7 +67,9 @@ export type Unwrap<T> = T extends Ref | DemiRef
|
|
|
72
67
|
/**
|
|
73
68
|
* Fully unwraps to bare value types any Vue 3 composable return definition type.
|
|
74
69
|
*/
|
|
75
|
-
export type Use<T = any> =
|
|
70
|
+
export type Use<T = any> = T extends Ref | DemiRef
|
|
71
|
+
? UnwrapRefRecursively<T>
|
|
72
|
+
: UnwrapComposableRefs<T extends AnyFn ? ReturnType<T> : T>;
|
|
76
73
|
|
|
77
74
|
/**
|
|
78
75
|
* Extracts object defined emit types by converting them to a plain interface
|
|
@@ -112,12 +109,12 @@ export type AnyClass = abstract new (...args: any[]) => any;
|
|
|
112
109
|
/**
|
|
113
110
|
* Descriptors map type.
|
|
114
111
|
*/
|
|
115
|
-
|
|
112
|
+
type Descriptors = Map<string, PropertyDescriptor>;
|
|
116
113
|
|
|
117
114
|
/**
|
|
118
115
|
* Computeds hash map type.
|
|
119
116
|
*/
|
|
120
|
-
|
|
117
|
+
type Computeds = Record<string, ComputedRef>;
|
|
121
118
|
|
|
122
119
|
/**
|
|
123
120
|
* Infer paramaters of a constructor function of a Class.
|
|
@@ -296,7 +293,7 @@ export function ivue<T extends AnyClass>(
|
|
|
296
293
|
* Store all props for each class prototype processed by:
|
|
297
294
|
* @see {getAllClassProperties}
|
|
298
295
|
*/
|
|
299
|
-
|
|
296
|
+
const propsMap: Map<object, Set<string> | any> = new Map();
|
|
300
297
|
|
|
301
298
|
/**
|
|
302
299
|
* Get properties of an entire class prototype ancestors chain as a Map.
|
|
@@ -377,7 +374,7 @@ export function iuse<T extends AnyClass | AnyFn | Object | any>(
|
|
|
377
374
|
(classFunctionObject as AnyFn)(
|
|
378
375
|
...(args as Parameters<T extends AnyFn ? AnyFn : any>)
|
|
379
376
|
)
|
|
380
|
-
: (classFunctionObject as unknown as
|
|
377
|
+
: (classFunctionObject as unknown as Use<T>) /** Unwrap any other Object or any type down to its bare types. */;
|
|
381
378
|
}
|
|
382
379
|
|
|
383
380
|
/**
|
|
@@ -392,7 +389,7 @@ function ivueToRefs<T extends AnyClass>(
|
|
|
392
389
|
vue: IVue<T>,
|
|
393
390
|
descriptors: Descriptors,
|
|
394
391
|
computeds: Computeds
|
|
395
|
-
):
|
|
392
|
+
): IVueToRefsFn<T> {
|
|
396
393
|
return function (
|
|
397
394
|
props?: (keyof InstanceType<T>)[] | boolean,
|
|
398
395
|
unwrap?: boolean /** This property helps with TypeScript function definition overloading of return types and is not being used inside the function itself. */
|