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.
Files changed (40) hide show
  1. package/dist/index.es.js +74 -78
  2. package/dist/index.umd.js +1 -1
  3. package/dist/src/ivue.d.ts +21 -23
  4. package/docs/docs/.vitepress/dist/404.html +2 -2
  5. package/docs/docs/.vitepress/dist/api/ivue.html +3 -3
  6. package/docs/docs/.vitepress/dist/api/propsWithDefaults.html +3 -3
  7. package/docs/docs/.vitepress/dist/assets/{app.CQ7kL6_f.js → app.Cnbc-twM.js} +1 -1
  8. package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.DVtkHDuS.js +1 -0
  9. package/docs/docs/.vitepress/dist/assets/chunks/{VPLocalSearchBox.hM-bvSJA.js → VPLocalSearchBox.BrRdnkds.js} +1 -1
  10. package/docs/docs/.vitepress/dist/assets/chunks/{theme.BQo6cm_A.js → theme.qh_SBkj1.js} +2 -2
  11. package/docs/docs/.vitepress/dist/assets/{pages_browse-code.md.DhMpWRNv.js → pages_browse-code.md.BXwbCBZ0.js} +26 -19
  12. package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.CRguJKe8.js → pages_getting-started.md.BqHPrEWq.js} +26 -19
  13. package/docs/docs/.vitepress/dist/assets/{pages_getting-started.md.CRguJKe8.lean.js → pages_getting-started.md.BqHPrEWq.lean.js} +1 -1
  14. package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.yUFCB7mz.js → pages_guidelines.md.Dkyp5V72.js} +1 -1
  15. package/docs/docs/.vitepress/dist/assets/{pages_guidelines.md.yUFCB7mz.lean.js → pages_guidelines.md.Dkyp5V72.lean.js} +1 -1
  16. package/docs/docs/.vitepress/dist/assets/{pages_how-it-works.md.DDKhyGlo.js → pages_how-it-works.md.Bf_7UZG9.js} +26 -19
  17. 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
  18. package/docs/docs/.vitepress/dist/assets/{pages_usage.md.EDa7wXde.js → pages_usage.md.C-dTtOlJ.js} +101 -71
  19. package/docs/docs/.vitepress/dist/assets/{pages_usage.md.EDa7wXde.lean.js → pages_usage.md.C-dTtOlJ.lean.js} +101 -71
  20. package/docs/docs/.vitepress/dist/hashmap.json +1 -1
  21. package/docs/docs/.vitepress/dist/index.html +3 -3
  22. package/docs/docs/.vitepress/dist/pages/advanced-usage.html +3 -3
  23. package/docs/docs/.vitepress/dist/pages/api.html +3 -3
  24. package/docs/docs/.vitepress/dist/pages/browse-code.html +30 -23
  25. package/docs/docs/.vitepress/dist/pages/getting-started.html +30 -23
  26. package/docs/docs/.vitepress/dist/pages/guidelines.html +5 -5
  27. package/docs/docs/.vitepress/dist/pages/how-it-works.html +30 -23
  28. package/docs/docs/.vitepress/dist/pages/how-its-made.html +3 -3
  29. package/docs/docs/.vitepress/dist/pages/introduction.html +3 -3
  30. package/docs/docs/.vitepress/dist/pages/usage.html +104 -74
  31. package/docs/docs/components/usage/CounterComposablesDestructuring.vue +12 -7
  32. package/docs/docs/components/usage/CounterComposablesIvueDestructuring.vue +11 -2
  33. package/docs/docs/components/usage/classes/CustomMouse.ts +13 -8
  34. package/docs/docs/components/usage/functions/useCustomMouse.ts +3 -9
  35. package/docs/docs/pages/usage.md +12 -10
  36. package/docs/package.json +1 -1
  37. package/package.json +1 -1
  38. package/src/ivue.ts +51 -34
  39. package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.DPHmCl-3.js +0 -1
  40. /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 UseMouse = UseComposable<typeof useCustomMouse>;
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
- // x, y are Refs that will be unwrapped and destructured into this class
20
- x: UseMouse['x']; // Unwrapped Ref<number> becomes -> number
21
- y: UseMouse['y']; // Unwrapped Ref<number> becomes -> number
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: UseMouse['sum']; // 'sum' method that will be destructured into this class on construct()
24
- total: UseMouse['total']; // 'total' computed Ref that will also be destructured into this class on construct()
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
- // x, y are Refs that will be unwrapped and destructured into this class
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 Ref<number> becomes -> number
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, type UseComposable } from 'ivue';
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
- constructor(public test: number) {
12
- ({ x: this.x, y: this.y } = iuse(useMouse()))
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.x + this.y;
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 _total;
16
+ return _sum;
23
17
  });
24
18
 
25
19
  return {
@@ -249,19 +249,20 @@ See the highlighted sections related to destructuring composable usage.
249
249
 
250
250
  <CounterComposablesDestructuring />
251
251
 
252
- ## Using Inside Composables
252
+ ### Using `ivue` Composables With Destructuring
253
253
 
254
- See the highlighted sections related to using `ivue` inside a composable.
254
+ See the highlighted sections related to using `ivue` based composables.
255
255
 
256
256
  ::: code-group
257
- <<< @/components/usage/CounterInsideComposables.vue{14 vue:line-numbers}
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
- <CounterInsideComposables />
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
- <CounterInsideComposables />
273
+ <CounterComposablesIvueDestructuring />
273
274
 
274
- ## Using `ivue` Composables
275
275
 
276
- See the highlighted sections related to using `ivue` based composables.
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/CounterComposablesIvueDestructuring.vue{14 vue:line-numbers}
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
- <CounterComposablesIvueDestructuring />
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
- <CounterComposablesIvueDestructuring />
296
+ <CounterInsideComposables />
295
297
 
296
298
  ## Using Computeds
297
299
 
package/docs/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "eslint-plugin-import": "^2.29.1",
19
19
  "eslint-plugin-vue": "^9.14.1",
20
20
  "execa": "^8.0.0",
21
- "ivue": "^1.1.20",
21
+ "ivue": "^1.2.0",
22
22
  "typescript": "^4.5.4",
23
23
  "vite-plugin-dynamic-import": "^1.5.0",
24
24
  "vite-tsconfig-paths": "^4.3.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ivue",
3
- "version": "1.1.21",
3
+ "version": "1.2.1",
4
4
  "description": "Infinite Vue – Class Based Architecture for Vue 3",
5
5
  "type": "module",
6
6
  "exports": {
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 { UnwrapRef, computed, reactive, ref, toRef } from 'vue';
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 (...args: any[]) => any> =
61
- UnwrapComposableReturn<ReturnType<T>>;
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 function iref<T>(val?: T): UnwrapRef<T> {
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
- * 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.
334
- */
335
- export function iuse<T extends AnyClass | Object>(
336
- val?: T,
337
- ...args: InferredArgs<T>
338
- ): T extends AnyClass ? InstanceType<T> : UnwrapComposableReturn<T> {
339
- return isClass(val)
340
- ? ivue(
341
- val as T extends AnyClass ? T : any,
342
- ...(args as InferredArgs<T>)
343
- ).toRefs()
344
- : (val as unknown as UnwrapComposableReturn<T>);
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
- export function ivueToRefs<T extends AnyClass>(
372
+ function ivueToRefs<T extends AnyClass>(
356
373
  vue: IVue<T>,
357
374
  descriptors: Descriptors,
358
375
  computeds: Computeds