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.
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 +15 -22
  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 +21 -19
  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 '../../../../../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
- 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.1.21",
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.0",
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,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 (...args: any[]) => any> =
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 (...args: any[]) => any,
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 function iref<T>(val?: T): UnwrapRef<T> {
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. 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.
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
- export function ivueToRefs<T extends AnyClass>(
357
+ function ivueToRefs<T extends AnyClass>(
356
358
  vue: IVue<T>,
357
359
  descriptors: Descriptors,
358
360
  computeds: Computeds