vue-computed-eager 1.0.2 → 1.0.3
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 +11 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,35 +23,26 @@ npm install vue-computed-eager
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
import {
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Eager computed without lazy evaluation.
|
|
30
|
-
|
|
31
|
-
> **Info:** This function will be removed in future version.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
> **Tip:** Note💡: If you are using Vue 3.4+, you can use `computed` right away, you no longer need this function.
|
|
35
|
-
In Vue 3.4+, if the computed new value does not change, `computed`, `effect`, `watch`, `watchEffect`, `render` dependencies will not be triggered.
|
|
36
|
-
See: https://github.com/vuejs/core/pull/5912
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Learn more at [Vue: When a computed property can be the wrong tool](https://dev.to/linusborg/vue-when-a-computed-property-can-be-the-wrong-tool-195j).
|
|
40
|
-
|
|
41
|
-
- Use `computed()` when you have a complex calculation going on, which can actually profit from caching and lazy evaluation and should only be (re-)calculated if really necessary.
|
|
42
|
-
- Use `computedEager()` when you have a simple operation, with a rarely changing return value – often a boolean.
|
|
43
|
-
|
|
44
|
-
```ts
|
|
26
|
+
import { ref } from 'vue'
|
|
45
27
|
import { computedEager } from 'vue-computed-eager'
|
|
46
28
|
|
|
47
29
|
const todos = ref([])
|
|
48
30
|
const hasOpenTodos = computedEager(() => !!todos.length)
|
|
49
31
|
|
|
50
32
|
console.log(hasOpenTodos.value) // false
|
|
51
|
-
|
|
33
|
+
todos.value.push({ title: 'Learn Vue' })
|
|
52
34
|
console.log(hasOpenTodos.value) // true
|
|
53
35
|
```
|
|
54
36
|
|
|
37
|
+
## When to use
|
|
38
|
+
|
|
39
|
+
- Use `computed()` when you have a complex calculation that profits from caching and lazy evaluation.
|
|
40
|
+
- Use `computedEager()` when you have a simple operation with a rarely changing return value (often a boolean).
|
|
41
|
+
|
|
42
|
+
Learn more: [Vue: When a computed property can be the wrong tool](https://dev.to/linusborg/vue-when-a-computed-property-can-be-the-wrong-tool-195j)
|
|
43
|
+
|
|
44
|
+
**Note:** If you are using Vue 3.4+, standard `computed` has been optimized to avoid triggering effects when the value hasn't changed. See [vuejs/core#5912](https://github.com/vuejs/core/pull/5912).
|
|
45
|
+
|
|
55
46
|
## License
|
|
56
47
|
|
|
57
48
|
MIT
|