ivue 1.0.2 → 1.0.4
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/.idea/codeStyles/Project.xml +65 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/ivue.iml +8 -0
- package/.idea/modules.xml +8 -0
- package/.idea/php.xml +19 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +23 -7
- package/coverage/clover.xml +159 -159
- package/coverage/coverage-final.json +1 -1
- package/coverage/index.html +17 -17
- package/coverage/index.ts.html +86 -107
- package/dist/index.es.js +74 -90
- package/dist/index.umd.js +1 -1
- package/dist/src/index.d.ts +1 -196
- package/dist/src/ivue.d.ts +218 -0
- package/docs/docs/.vitepress/config.ts +110 -22
- package/docs/docs/.vitepress/dist/404.html +4 -4
- package/docs/docs/.vitepress/dist/api/ivue.html +8 -8
- package/docs/docs/.vitepress/dist/api/propsWithDefaults.html +8 -8
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.BCZ4q_0D.js → api_ivue.md.MRwb9Lcb.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_ivue.md.BCZ4q_0D.lean.js → api_ivue.md.MRwb9Lcb.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.Cr5FwI9o.lean.js → api_propsWithDefaults.md.CeE4IC-K.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{api_propsWithDefaults.md.Cr5FwI9o.js → api_propsWithDefaults.md.CeE4IC-K.lean.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/{app.DRiljpSE.js → app.ConZRsN0.js} +1 -1
- package/docs/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.CGLWArGd.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/Button.vue_vue_type_script_setup_true_lang.P7niV-n8.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/VPLocalSearchBox.C7VDyivS.js +7 -0
- package/docs/docs/.vitepress/dist/assets/chunks/framework.CNtPHGsN.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/index.es.DnWLDAUc.js +1 -0
- package/docs/docs/.vitepress/dist/assets/chunks/theme.B7n-r1TY.js +2 -0
- package/docs/docs/.vitepress/dist/assets/index.md.wPLoTLBY.js +1 -0
- package/docs/docs/.vitepress/dist/assets/index.md.wPLoTLBY.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_advanced-usage.md.BZgX-VP7.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_advanced-usage.md.BZgX-VP7.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_api.md.C_PvCZns.js +7 -0
- package/docs/docs/.vitepress/dist/assets/pages_api.md.C_PvCZns.lean.js +7 -0
- package/docs/docs/.vitepress/dist/assets/pages_browse-code.md.CPluoaap.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_browse-code.md.CPluoaap.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.knQcOZyP.js +8 -0
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.knQcOZyP.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_guidelines.md.DddPdPom.js +101 -0
- package/docs/docs/.vitepress/dist/assets/pages_guidelines.md.DddPdPom.lean.js +101 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.OJGcGEXF.js +4 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.OJGcGEXF.lean.js +4 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-its-made.md.Vv9Z9TEi.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_how-its-made.md.Vv9Z9TEi.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.DrDm-R8F.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.DrDm-R8F.lean.js +1 -0
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.zSOVjtFF.js +430 -0
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.zSOVjtFF.lean.js +430 -0
- package/docs/docs/.vitepress/dist/assets/style.Fgx7OB_D.css +1 -0
- package/docs/docs/.vitepress/dist/hashmap.json +1 -1
- package/docs/docs/.vitepress/dist/index.html +9 -8
- package/docs/docs/.vitepress/dist/pages/advanced-usage.html +24 -0
- package/docs/docs/.vitepress/dist/pages/api.html +30 -0
- package/docs/docs/.vitepress/dist/pages/browse-code.html +24 -0
- package/docs/docs/.vitepress/dist/pages/getting-started.html +11 -11
- package/docs/docs/.vitepress/dist/pages/guidelines.html +125 -0
- package/docs/docs/.vitepress/dist/pages/how-it-works.html +11 -8
- package/docs/docs/.vitepress/dist/pages/how-its-made.html +24 -0
- package/docs/docs/.vitepress/dist/pages/introduction.html +9 -8
- package/docs/docs/.vitepress/dist/pages/usage.html +428 -14
- package/docs/docs/.vitepress/theme/index.js +5 -0
- package/docs/docs/.vitepress/theme/main.css +29 -0
- package/docs/docs/components/Button.vue +1 -1
- package/docs/docs/components/guidelines/CounterExternalRefsDetailed.vue +41 -0
- package/docs/docs/components/usage/CounterBasic.vue +17 -0
- package/docs/docs/components/usage/CounterComposables.vue +19 -0
- package/docs/docs/components/usage/CounterComposablesDestructuring.vue +46 -0
- package/docs/docs/components/usage/CounterComputeds.vue +25 -0
- package/docs/docs/components/usage/CounterComputedsDisabled.vue +32 -0
- package/docs/docs/components/usage/CounterDefineExpose.vue +12 -0
- package/docs/docs/components/usage/CounterDefineExposeAdvanced.vue +25 -0
- package/docs/docs/components/usage/CounterDefineExposeClass.ts +11 -0
- package/docs/docs/components/usage/CounterExternalRefs.vue +25 -0
- package/docs/docs/components/usage/CounterInsideComposables.vue +27 -0
- package/docs/docs/components/usage/CounterInternalRefs.vue +26 -0
- package/docs/docs/components/usage/CounterLifecycleHooks.vue +22 -0
- package/docs/docs/components/usage/CounterWatch.vue +25 -0
- package/docs/docs/components/usage/CounterWithProps.vue +29 -0
- package/docs/docs/components/usage/CounterWithPropsAndEmits.vue +36 -0
- package/docs/docs/components/usage/functions/useMouse.ts +22 -0
- package/docs/docs/index.md +10 -9
- package/docs/docs/pages/advanced-usage.md +11 -0
- package/docs/docs/pages/api.md +106 -0
- package/docs/docs/pages/browse-code.md +18 -0
- package/docs/docs/pages/getting-started.md +23 -5
- package/docs/docs/pages/guidelines.md +128 -0
- package/docs/docs/pages/how-it-works.md +71 -0
- package/docs/docs/pages/how-its-made.md +32 -0
- package/docs/docs/pages/introduction.md +37 -20
- package/docs/docs/pages/usage.md +347 -10
- package/docs/package.json +4 -3
- package/package.json +4 -2
- package/src/__tests__/ivue.vitest.spec.ts +228 -132
- package/src/index.ts +1 -463
- package/src/ivue.ts +495 -0
- package/vite.config.ts +4 -0
- package/docs/.env +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/framework.CEhE-9HF.js +0 -1
- package/docs/docs/.vitepress/dist/assets/chunks/theme.CldUEgAJ.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.B1vDz5mb.js +0 -1
- package/docs/docs/.vitepress/dist/assets/index.md.B1vDz5mb.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.C7qtPEWU.js +0 -8
- package/docs/docs/.vitepress/dist/assets/pages_getting-started.md.C7qtPEWU.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.DKizt6Ny.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_how-it-works.md.DKizt6Ny.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.Dkqu-XCz.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_introduction.md.Dkqu-XCz.lean.js +0 -1
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.qo7ICfLC.js +0 -17
- package/docs/docs/.vitepress/dist/assets/pages_usage.md.qo7ICfLC.lean.js +0 -17
- package/docs/docs/.vitepress/dist/assets/style.BSZVsGuP.css +0 -1
- package/docs/docs/components/examples/Counter.vue +0 -17
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Getting Started
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
The only dependency for `ivue` is Vue 3, so it is easy to get started.
|
|
6
|
+
|
|
7
|
+
In your terminal install `ivue` using:
|
|
4
8
|
```bash
|
|
5
|
-
#
|
|
9
|
+
# yarn
|
|
6
10
|
yarn add ivue
|
|
7
11
|
|
|
8
|
-
#
|
|
12
|
+
# npm
|
|
9
13
|
npm i ivue
|
|
10
14
|
|
|
11
|
-
#
|
|
15
|
+
# pnpm
|
|
12
16
|
pnpm i ivue
|
|
13
17
|
```
|
|
14
18
|
|
|
19
|
+
## Install by Copying
|
|
20
|
+
|
|
21
|
+
`ivue` is designed to be easily shareable and installable so if you are running TypeScript, you can just copy the
|
|
22
|
+
`ivue.ts` into your repo and you are done:
|
|
23
|
+
:::details Click to expand the latest `ivue` source code to copy
|
|
24
|
+
|
|
25
|
+
:::code-group
|
|
26
|
+
<<< ../../../src/index.ts{ts:line-numbers} [ivue.ts]
|
|
27
|
+
:::
|
|
28
|
+
Or [Copy from GitHub](https://github.com/infinite-system/ivue/blob/main/src/index.ts)
|
|
29
|
+
|
|
30
|
+
::: tip NOTE
|
|
31
|
+
This installation path is recommended only if you quickly want to tinker with the internals of ivue, as you won't be getting the latest updates. Also note that this code comes from github `main` branch latest which might also be in beta and not fully published to `npm`.
|
|
32
|
+
:::
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import CounterExternalRefsDetailed from '../components/guidelines/CounterExternalRefsDetailed.vue';
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
# Guidelines
|
|
6
|
+
|
|
7
|
+
## Dos and Don'ts
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
type UseMouse = UseComposable<typeof useMouse>;
|
|
11
|
+
/**
|
|
12
|
+
* Example of a properly defined ivue class.
|
|
13
|
+
*/
|
|
14
|
+
class Counter {
|
|
15
|
+
/** ✅ Properly declared unwrapped composable. */
|
|
16
|
+
mouse: UseMouse;
|
|
17
|
+
|
|
18
|
+
constructor(public props: CounterProps, public emit: CounterEmit) {
|
|
19
|
+
this.mouse = useMouse() as unknown as UseMouse // ✅ Properly declared unwrapped composable.
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** ✅ Properly declared init function. */
|
|
23
|
+
init() {
|
|
24
|
+
/** ✅ Properly set lifecycle hook. */
|
|
25
|
+
onMounted(() => {
|
|
26
|
+
this.count = 4;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/** ✅ Properly set watch function */
|
|
30
|
+
watch(() => this.count, (newCount) => {
|
|
31
|
+
if (newCount === 5) {
|
|
32
|
+
alert('You reached the count of ' + newCount + '!');
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Use ref() for the property and cast it to number
|
|
38
|
+
* because refs auto-unwrap inside reactive().
|
|
39
|
+
*/
|
|
40
|
+
count = ref(0) as unknown as number; // ✅
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Use ref() for the property and cast it to number
|
|
44
|
+
* because refs auto-unwrap inside reactive().
|
|
45
|
+
*/
|
|
46
|
+
timesClicked = ref(0) as unknown as number; // ✅
|
|
47
|
+
|
|
48
|
+
/** ✅ Properly declared function (not arrow function). */
|
|
49
|
+
increment() {
|
|
50
|
+
this.count++;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** ✅ Properly declared function (not arrow function). */
|
|
54
|
+
click() {
|
|
55
|
+
this.increment();
|
|
56
|
+
this.timesClicked++;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Do NOT use arrow functions, arrow functions are not extensible.
|
|
61
|
+
*/
|
|
62
|
+
increment = () => this.count++ ❌
|
|
63
|
+
|
|
64
|
+
/** ✅ Properly declared computed getter. */
|
|
65
|
+
get doubleCount() {
|
|
66
|
+
return this.count * 2;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Use ref() for properties
|
|
72
|
+
|
|
73
|
+
`ivue` recommends all class properties to be defined as `ref()` to be able to interoperate with `defineExpose()`, if you simply pass reactive props which are not Refs through `defineExpose()`, they will lose reactivity. `ref()` refs just like computed refs get flattened into the `reactive()` object, so there is no need to worry about using `.value`. The `ref()` refs are necessary just internally for Vue 3 to know which refs to keep reactive.
|
|
74
|
+
|
|
75
|
+
### Unwrap (de-Ref) the types
|
|
76
|
+
|
|
77
|
+
Next, we convert the types back to their normal types as if they have no reactivity at all, so `Ref<number>` is `number` in `ivue`, so rather than going in the direction of complexifying the types, we are going in the opposite direction towards simplification.
|
|
78
|
+
|
|
79
|
+
### Use standard declaration syntax for functions
|
|
80
|
+
|
|
81
|
+
`ivue` recommends all class functions to be defined in plain full function style (not arrow functions), this allows all `ivue` classes to be extensible at any point. By using plain standard functions, it allows the developer to be able to override them at any time by simply extending the class.
|
|
82
|
+
|
|
83
|
+
### Do not use arrow functions in class declarations
|
|
84
|
+
|
|
85
|
+
:::warning
|
|
86
|
+
Arrow functions break full extensibility of classes because they carry their own context at the point of declaration, so avoid using them inside of `ivue` classes.
|
|
87
|
+
:::
|
|
88
|
+
|
|
89
|
+
## constructor() vs .init()
|
|
90
|
+
|
|
91
|
+
#### Use `constructor()` to assign properties of the class and cast Refs to Unwrapped bare types. <br />
|
|
92
|
+
|
|
93
|
+
#### Use `.init()` to declare reactive state functions like `watch`, `watchEffect`, and lifecycle hooks like `onMounted`, `onBeforeMount` etc, do assignments of reactive properties, since `init()` already has access to `reactive()` state through `this`.<br />
|
|
94
|
+
|
|
95
|
+
<hr />
|
|
96
|
+
|
|
97
|
+
Inside the `constructor()` method you still have access to non-reactive state, because when `constructor()` is initialized, it does NOT yet have access to the reactive properties of the class, since it was not yet converted to `reactive()` by `ivue`, so if you use the properties like Refs or ComputedRefs inside `constructor()` you would have to use them with the `.value`.
|
|
98
|
+
|
|
99
|
+
As a general rule, there is no need to manipulate the values in the `constructor()`, use constructor only for assigning the properties and casting the types of those assigned properties to the unwrapped (de-Refed) final state of the resulting `reactive()` object.
|
|
100
|
+
|
|
101
|
+
**Let's look at a `constructor()` vs `.init()` example:**
|
|
102
|
+
|
|
103
|
+
::: code-group
|
|
104
|
+
<<< @/components/guidelines/CounterExternalRefsDetailed.vue{5,9-13,16-20,29,32,40 vue:line-numbers}
|
|
105
|
+
:::
|
|
106
|
+
:::details For this example we initialize the component like this:
|
|
107
|
+
|
|
108
|
+
```vue
|
|
109
|
+
<template>
|
|
110
|
+
<CounterExternalRefsDetailed />
|
|
111
|
+
</template>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
:::
|
|
115
|
+
|
|
116
|
+
<div style="font-size: 18px; font-weight: 500;">Result</div>
|
|
117
|
+
|
|
118
|
+
<CounterExternalRefsDetailed />
|
|
119
|
+
|
|
120
|
+
## Unwrapping Refs
|
|
121
|
+
|
|
122
|
+
The key to working with `ivue` is understanding correctly the way Vue 3 does automatic Unwrapping of Refs when they are passed into the `reactive()` object. In that regard we are not relying on some magic `ivue` behavior but rather the default behavior of `reactive()` Vue 3 function.
|
|
123
|
+
|
|
124
|
+
To match that unwrapping behavior, our class needs to Unwrap (or de-Ref) the types of Composables, Refs, ComputedRefs, if they are being passed into the constructor, to get their raw basic types those Refs are pointing to, so that you can start operating in the `ivue` environment, where there is no need to worry about `.value`. This unwrapping should be mainly done inside the `constructor()` method.
|
|
125
|
+
|
|
126
|
+
## Naming Conventions
|
|
127
|
+
|
|
128
|
+
To benefit from the full power of `ivue`, it is recommended to extract the classes into separate files. What has been an effective pattern is to name the classes and put them right beside components in the same folder that these classes are being used with. So if you have `CounterComponent.vue` component, it can have a class inside `CounterComponentClass.ts`, and you can store props, emits, and other runtime definitions inside `CounterComponentProps.ts`.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import CounterBasic from '../components/usage/CounterBasic.vue'
|
|
3
|
+
</script>
|
|
4
|
+
# How it works?
|
|
5
|
+
|
|
6
|
+
## What ivue is NOT?
|
|
7
|
+
|
|
8
|
+
To understand how ivue works and how it does it, it is important to understand what it does not do.
|
|
9
|
+
|
|
10
|
+
::: info `ivue` is different from other class based libraries
|
|
11
|
+
— `ivue` does NOT inherit from a base class<br />
|
|
12
|
+
— `ivue` does NOT use decorators to achieve its objectives<br />
|
|
13
|
+
— `ivue` does NOT alter Vue 3 underlying behavior, but rather relies on it<br />
|
|
14
|
+
— `ivue` is NOT the same as class components (though you can build components with it)
|
|
15
|
+
:::
|
|
16
|
+
|
|
17
|
+
## How it works?
|
|
18
|
+
```ts
|
|
19
|
+
export function ivue<T extends AnyClass>(
|
|
20
|
+
className: T,
|
|
21
|
+
...args: InferredArgs<T>
|
|
22
|
+
): IVue<T>
|
|
23
|
+
```
|
|
24
|
+
The main `ivue()` initializer function uses TypeScript to be able to infer and validate the constrcutor argument types of `AnyClass` and passes those arguments to the constructor of `AnyClass`.
|
|
25
|
+
|
|
26
|
+
`ivue` allows you to pass any number of arguments into the class `constructor(arg1, arg2, arg3, ...etc)`
|
|
27
|
+
|
|
28
|
+
`ivue()` initializer function returns an extended Vue 3 `reactive()` object in which getters and setters are internally converted to computeds and adds `.toRefs()` method to the created object. Computeds auto-unwrap themselves when they are accessed as a reactive object property, so the `.value` properties and computeds get flattened in the resulting object and do not require `.value` to be accessed.
|
|
29
|
+
|
|
30
|
+
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.
|
|
31
|
+
|
|
32
|
+
`ivue` aims to be opaque and minimal, just doing the minimum to convert a class to a reactive object, leaving the rest to be implemented using Vue 3 Composition API inside an initializer function called `.init()`
|
|
33
|
+
|
|
34
|
+
## Usage Recommendation
|
|
35
|
+
`ivue` recommends all class properties to be defined as `ref()` to be able to interoperate with `defineExpose()`, if you simply pass reactive props which are not Refs through `defineExpose()`, they will lose reactivity. `ref()` refs just like computed refs get flattened into the `reactive()` object, so there is no need to worry about using `.value`. The `ref()` refs are necessary just internally for Vue 3 to know which refs to keep reactive, and we just convert the types back to their normal types as if they have no reactivity at all, so `Ref<number>` is `number` in `ivue`, so rather than going in the direction of complexifying the types, we are going in the opposite direction towards simplification.
|
|
36
|
+
|
|
37
|
+
`ivue` recommends all class functions, getters and setters to be defined in plain full function style (not arrow functions), this allows all `ivue` classes to be extensible at any point. By using plain standard functions, getters and setters allows for any getter, setter, function or property to be overriden by extending this class. Arrow functions break full extensibility of classes, so avoid using them inside of classes.
|
|
38
|
+
|
|
39
|
+
See: [More Guidelines](/pages/guidelines.html)
|
|
40
|
+
|
|
41
|
+
## Minimal API Surface Area
|
|
42
|
+
|
|
43
|
+
`ivue()` initializer function is the main API<br />
|
|
44
|
+
`.init()` method helps initialize the reactive state like `watch`, `onMount`, etc.<br />
|
|
45
|
+
`.toRefs()` method allows to interoperate with Vue 3 Composables<br />
|
|
46
|
+
Utility Types help to achieve the rest of `ivue` capabilities
|
|
47
|
+
|
|
48
|
+
:::details Click to see the whole latest `ivue` source code from github main branch below:
|
|
49
|
+
:::code-group
|
|
50
|
+
<<< ../../../src/index.ts{ts:line-numbers} [ivue.ts]
|
|
51
|
+
:::
|
|
52
|
+
Or [See on GitHub](https://github.com/infinite-system/ivue/blob/main/src/index.ts)
|
|
53
|
+
|
|
54
|
+
## 100% Vue 3 Compatible
|
|
55
|
+
`.toRefs()` allows the object to be converted to Vue 3 native composable structure with full `.value`s, so it can interoperate with native composables if needed. `.toRefs()` is also often used to get refs for `v-bind()` in css styles.
|
|
56
|
+
|
|
57
|
+
## 100% TypeScript Support
|
|
58
|
+
|
|
59
|
+
`ivue` is on the cutting edge of TypeScript and owes its capabilities to the latest developments in TypeScript.
|
|
60
|
+
|
|
61
|
+
`ivue` provides a set of utility types to make working with `Vue 3` even easier and more scalable.
|
|
62
|
+
|
|
63
|
+
## 100% Unit Tested Architecture
|
|
64
|
+
|
|
65
|
+
At the current stage all of the code that is used to build `ivue` is 100% tested with 100% coverage, and aims to keep being at 100% always.
|
|
66
|
+
|
|
67
|
+
You can clone the project and run `yarn test` yourself and examine the tests.
|
|
68
|
+
|
|
69
|
+
## Zero Dependencies
|
|
70
|
+
|
|
71
|
+
`ivue` has zero dependencies except Vue 3.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
# How it's made
|
|
3
|
+
|
|
4
|
+
## Original Inspiration
|
|
5
|
+
|
|
6
|
+
The original inspiration for `ivue` comes from `MobX` React state management library, where something similar is attempted to create a class based reactive observable architecture.
|
|
7
|
+
|
|
8
|
+
## Epiphany
|
|
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 perfomance 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
|
+
|
|
12
|
+
And one lucky and sunny day driving back from work in an eureka moment of light it occured 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
|
+
|
|
14
|
+
`ivue` relies on this very simple discovery of how to elegantly convert getters into Vue 3 computeds.
|
|
15
|
+
|
|
16
|
+
## Simplicity
|
|
17
|
+
|
|
18
|
+
After many iterations where I created a whole inversion of control library for `ivue`, using lots of different decorators and event Traits, I realized that simplicity is paramount to good architecture.
|
|
19
|
+
|
|
20
|
+
In that sweep of clarity, I got rid of 95% of the code that was just extra stuff and not the essence and left only `3` core functions: `ivue()`, `.init()`, `.toRefs()` only which are necessary to do everything `ivue` is set out to do.
|
|
21
|
+
|
|
22
|
+
Use Composition API composables inside `init()` function.
|
|
23
|
+
|
|
24
|
+
## Minimalism
|
|
25
|
+
|
|
26
|
+
Thus `ivue` has minimal surface area of the API making it very robust and easy to test.
|
|
27
|
+
By default `ivue` does not rely on decorators, though you can use decorators if you wish to.
|
|
28
|
+
|
|
29
|
+
## The Rest is Up To You
|
|
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 upto the community of enthusiatic open source contributors, please share with us your vision of how you and all of can use `ivue` better.
|
|
32
|
+
|
|
@@ -1,45 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import Button from '../components/Button.vue'
|
|
3
|
+
</script>
|
|
4
|
+
# What is Infinite Vue?
|
|
2
5
|
|
|
3
|
-
## The
|
|
6
|
+
## The Problem
|
|
4
7
|
|
|
5
8
|
With the development of React hooks and Vue following in its footsteps with introduction of Vue 3 Composition API, the ecosystem has moved away from Options API.
|
|
6
9
|
|
|
7
10
|
While providing greater flexibility and composability the Composition API has its own downsides, one of them is having to use `.value` to refer to the reactive variables which makes the development process more clunky when the App reaches a certain size.
|
|
8
11
|
|
|
9
|
-
As
|
|
12
|
+
As you may know, `reactvity-transform` macros were an attempt to mitigate those issues, which turned out to create even more issues, and was discontinued.
|
|
10
13
|
|
|
11
|
-
See: https://vuejs.org/guide/extras/reactivity-transform.html
|
|
14
|
+
See: [VueJs.org – Reactivity Transform](https://vuejs.org/guide/extras/reactivity-transform.html)
|
|
12
15
|
|
|
16
|
+
## `ivue` is
|
|
17
|
+
<div style="padding-left:20px; font-size: 1.2rem; line-height: 2rem;">
|
|
18
|
+
– Simple like Options API<br />
|
|
19
|
+
– Flexible like Composition API<br />
|
|
20
|
+
– Extensible like TypeScript Classes API<br />
|
|
21
|
+
</div>
|
|
13
22
|
|
|
14
|
-
|
|
15
|
-
— ivue mitigates the downsides of both Composition API and Options API, uses only their strengths and brings back Object Oriented Programming to allow the development of complex and scallable apps.
|
|
23
|
+
`ivue` is a powerful tool because it fully aligns itself with JavaScript / TypeScript Class API.
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
`ivue` gives you a class based Composable capabilities with Inheritance and all the power of TypeScript Classes.
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
`ivue` mitigates the downsides of both Composition API and Options API, uses only their strengths and brings back Object Oriented Programming to allow the development of complex and scalable apps.
|
|
28
|
+
|
|
29
|
+
`ivue` is fully interoperable with Composition API and does not work against, but rather with it, so you can use all of ecosystems composables seamlessly.
|
|
30
|
+
|
|
31
|
+
`ivue` also offers a set of functions and utility types to make extensible & exportable props defaults, extensible emits and extensible slots possible.
|
|
21
32
|
|
|
22
|
-
## Classes are Back with Full Vue 3 Compatibility & Beyond
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
## Classes in the Ecosystem
|
|
35
|
+
|
|
36
|
+
With failed implementations of classes in React and also failed implementations using class components in Vue 2 / 3, the ecosystem decided that classes are bad and moved to pure procedural designs.
|
|
37
|
+
|
|
38
|
+
While procedural programming has its strength, it also comes with its own weaknesses, like lack of inheritance, lack of `this` context, and thus lack of true composition.
|
|
25
39
|
|
|
26
40
|
::: info IVUE IS DIFFERENT
|
|
27
|
-
&
|
|
28
|
-
&
|
|
29
|
-
&
|
|
30
|
-
&
|
|
41
|
+
– `ivue` does NOT inherit from a base class<br />
|
|
42
|
+
– `ivue` does NOT use decorators to achieve its objectives<br />
|
|
43
|
+
– `ivue` does NOT alter Vue 3 underlying behavior<br />
|
|
44
|
+
– `ivue` is NOT the same as class components (though you can build components with it)<br />
|
|
31
45
|
:::
|
|
32
46
|
|
|
33
|
-
## Infinite Vue Achitecture
|
|
47
|
+
## Infinite Vue Class Achitecture
|
|
48
|
+
|
|
49
|
+
`ivue` replicates native JavaScript / TypeScript class implementation by extending descriptors (getters and setters) up the whole prototype chain thus supporting classical inheritance.
|
|
34
50
|
|
|
35
|
-
|
|
51
|
+
By using TypeScript we are able to infer the arguments of the main `ivue()` initializer function and pass the arguments to the constructor.
|
|
36
52
|
|
|
37
|
-
|
|
53
|
+
`ivue()` initializer function returns a reactive object with getters converted to computeds and adds `.toRefs()` method to the object, `.toRefs()` allows the object to be converted to native composable structure, so it can interoperate as a composable if needed.
|
|
38
54
|
|
|
39
|
-
`ivue`
|
|
55
|
+
`ivue` aims to be opaque and minimal, just doing the minimum to convert a class to a reactive object, leaving the rest to be implemented using Vue 3 Composition API inside an initializer function called `.init()`
|
|
40
56
|
|
|
57
|
+
You can read more about `ivue` internal architecture in <Button href="/pages/how-it-works" label="How it works?" /> page.
|
|
41
58
|
|
|
42
59
|
## When to use Infinite Vue?
|
|
43
60
|
|
|
44
|
-
When complexity of your app or components becomes very high using
|
|
61
|
+
When the complexity of your app or components becomes very high using `ivue` can become a natural choice to deal with that complexity. Because `.value` is abstracted away in `ivue`, everything is simply a reactive object of Refs.
|
|
45
62
|
|