vue-computed-eager 1.0.1 → 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 +25 -25
- package/banner.svg +52 -0
- package/logo.svg +34 -0
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="logo.svg" alt="vue-computed-eager" width="180" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">vue-computed-eager</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">A Vue 3 composition API utility that creates computed properties which evaluate immediately when dependencies change, rather than lazily on access. Ideal for simple boolean checks with rarely-changing values. Note: Vue 3.4+ has built-in optimization making this less necessary.</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/vue-computed-eager"><img src="https://img.shields.io/npm/v/vue-computed-eager.svg" alt="npm version" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/vue-computed-eager"><img src="https://img.shields.io/npm/dm/vue-computed-eager.svg" alt="npm downloads" /></a>
|
|
12
|
+
<a href="https://github.com/vuefrag/vue-computed-eager/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/vue-computed-eager.svg" alt="license" /></a>
|
|
13
|
+
</p>
|
|
4
14
|
|
|
5
15
|
> Extracted from [VueUse](https://vueuse.org/) for standalone use.
|
|
6
16
|
|
|
@@ -13,35 +23,25 @@ npm install vue-computed-eager
|
|
|
13
23
|
## Usage
|
|
14
24
|
|
|
15
25
|
```ts
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Eager computed without lazy evaluation.
|
|
20
|
-
|
|
21
|
-
> **Info:** This function will be removed in future version.
|
|
26
|
+
import { ref } from 'vue'
|
|
27
|
+
import { computedEager } from 'vue-computed-eager'
|
|
22
28
|
|
|
29
|
+
const todos = ref([])
|
|
30
|
+
const hasOpenTodos = computedEager(() => !!todos.length)
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
console.log(hasOpenTodos.value) // false
|
|
33
|
+
todos.value.push({ title: 'Learn Vue' })
|
|
34
|
+
console.log(hasOpenTodos.value) // true
|
|
35
|
+
```
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
## When to use
|
|
30
38
|
|
|
31
|
-
- Use `computed()` when you have a complex calculation
|
|
32
|
-
- Use `computedEager()` when you have a simple operation
|
|
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).
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
import { ref } from 'vue';
|
|
36
|
-
import { computedEager } from 'vue-computed-eager';
|
|
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)
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
const hasOpenTodos = computedEager(() => !!todos.value.length);
|
|
40
|
-
|
|
41
|
-
console.log(hasOpenTodos.value); // false
|
|
42
|
-
todos.value.push({ title: 'Learn Vue' });
|
|
43
|
-
console.log(hasOpenTodos.value); // true
|
|
44
|
-
```
|
|
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
45
|
|
|
46
46
|
## License
|
|
47
47
|
|
package/banner.svg
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 640" width="1280" height="640">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="banner-bg" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="0%" style="stop-color:#35495e;stop-opacity:1" />
|
|
5
|
+
<stop offset="100%" style="stop-color:#1a252f;stop-opacity:1" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
|
|
9
|
+
<!-- Background -->
|
|
10
|
+
<rect width="1280" height="640" fill="url(#banner-bg)"/>
|
|
11
|
+
|
|
12
|
+
<!-- Decorative elements -->
|
|
13
|
+
<circle cx="1200" cy="100" r="300" fill="#42b883" opacity="0.05"/>
|
|
14
|
+
<circle cx="80" cy="540" r="200" fill="#42b883" opacity="0.05"/>
|
|
15
|
+
|
|
16
|
+
<!-- Top accent bar -->
|
|
17
|
+
<rect x="0" y="0" width="1280" height="8" fill="#42b883"/>
|
|
18
|
+
|
|
19
|
+
<!-- VueFrag badge -->
|
|
20
|
+
<g transform="translate(80, 80)">
|
|
21
|
+
<rect width="140" height="50" rx="8" fill="#42b883"/>
|
|
22
|
+
<text x="70" y="33" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="22" font-weight="700" fill="white">VueFrag</text>
|
|
23
|
+
</g>
|
|
24
|
+
|
|
25
|
+
<!-- Package name -->
|
|
26
|
+
<text x="80" y="280" font-family="system-ui, -apple-system, sans-serif" font-size="72" font-weight="700" fill="white">vue-computed-eager</text>
|
|
27
|
+
|
|
28
|
+
<!-- Description -->
|
|
29
|
+
<text x="80" y="360" font-family="system-ui, -apple-system, sans-serif" font-size="32" fill="#94a3b8">Vue 3 eager computed that evaluates immediately on depend...</text>
|
|
30
|
+
|
|
31
|
+
<!-- Install command -->
|
|
32
|
+
<g transform="translate(80, 420)">
|
|
33
|
+
<rect width="500" height="60" rx="8" fill="#0f172a"/>
|
|
34
|
+
<text x="20" y="40" font-family="ui-monospace, monospace" font-size="24" fill="#94a3b8">npm install</text>
|
|
35
|
+
<text x="200" y="40" font-family="ui-monospace, monospace" font-size="24" fill="#42b883">vue-computed-eager</text>
|
|
36
|
+
</g>
|
|
37
|
+
|
|
38
|
+
<!-- Category badge -->
|
|
39
|
+
<g transform="translate(80, 520)">
|
|
40
|
+
<rect width="172" height="40" rx="20" fill="#42b883" opacity="0.2"/>
|
|
41
|
+
<text x="86" y="27" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="18" fill="#42b883">Reactivity</text>
|
|
42
|
+
</g>
|
|
43
|
+
|
|
44
|
+
<!-- Vue logo hint -->
|
|
45
|
+
<g transform="translate(1080, 480)">
|
|
46
|
+
<polygon points="100,20 140,100 60,100" fill="#42b883" opacity="0.3"/>
|
|
47
|
+
<polygon points="100,40 125,90 75,90" fill="#42b883" opacity="0.5"/>
|
|
48
|
+
</g>
|
|
49
|
+
|
|
50
|
+
<!-- Bottom text -->
|
|
51
|
+
<text x="1200" y="600" text-anchor="end" font-family="system-ui, -apple-system, sans-serif" font-size="18" fill="#64748b">Standalone VueUse function</text>
|
|
52
|
+
</svg>
|
package/logo.svg
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" width="256" height="256">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg-grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="0%" style="stop-color:#35495e;stop-opacity:1" />
|
|
5
|
+
<stop offset="100%" style="stop-color:#1a252f;stop-opacity:1" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
|
|
9
|
+
<!-- Background -->
|
|
10
|
+
<rect width="96" height="96" rx="16" fill="url(#bg-grad)"/>
|
|
11
|
+
|
|
12
|
+
<!-- Decorative corner accent -->
|
|
13
|
+
<path d="M96 0v20c0-11.046-8.954-20-20-20H96z" fill="#42b883" opacity="0.12"/>
|
|
14
|
+
|
|
15
|
+
<!-- Vue badge -->
|
|
16
|
+
<g transform="translate(8, 8)">
|
|
17
|
+
<rect width="18" height="9" rx="2" fill="#42b883"/>
|
|
18
|
+
<text x="9" y="6.8" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="4.5" font-weight="700" fill="white">VUE</text>
|
|
19
|
+
</g>
|
|
20
|
+
|
|
21
|
+
<!-- Category icon -->
|
|
22
|
+
<g>
|
|
23
|
+
<circle cx="48" cy="28" r="12" fill="none" stroke="#42b883" stroke-width="3"/><circle cx="48" cy="28" r="5" fill="#42b883"/><path d="M36 28h-4M60 28h4M48 16v-4M48 40v4" stroke="#42b883" stroke-width="2" stroke-linecap="round"/>
|
|
24
|
+
</g>
|
|
25
|
+
|
|
26
|
+
<!-- Function name - textLength ensures it fits within bounds -->
|
|
27
|
+
<text x="48" y="58" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="9" font-weight="600" fill="white" textLength="75.6" lengthAdjust="spacingAndGlyphs">Computed Eager</text>
|
|
28
|
+
|
|
29
|
+
<!-- Category label -->
|
|
30
|
+
<text x="48" y="72" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="7" fill="#42b883" opacity="0.85">Reactivity</text>
|
|
31
|
+
|
|
32
|
+
<!-- Bottom accent line -->
|
|
33
|
+
<rect x="28" y="82" width="40" height="2" rx="1" fill="#42b883" opacity="0.5"/>
|
|
34
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-computed-eager",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Vue 3 eager computed that evaluates immediately on dependency change",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"logo.svg",
|
|
18
|
+
"banner.svg"
|
|
17
19
|
],
|
|
18
20
|
"scripts": {
|
|
19
21
|
"build": "unbuild",
|
|
@@ -22,8 +24,20 @@
|
|
|
22
24
|
"keywords": [
|
|
23
25
|
"vue",
|
|
24
26
|
"vue3",
|
|
27
|
+
"vue-3",
|
|
25
28
|
"composable",
|
|
29
|
+
"composition-api",
|
|
26
30
|
"vueuse",
|
|
31
|
+
"reactive",
|
|
32
|
+
"reactivity",
|
|
33
|
+
"computed",
|
|
34
|
+
"ref",
|
|
35
|
+
"state",
|
|
36
|
+
"eager",
|
|
37
|
+
"immediate",
|
|
38
|
+
"non-lazy",
|
|
39
|
+
"sync",
|
|
40
|
+
"performance",
|
|
27
41
|
"computedEager"
|
|
28
42
|
],
|
|
29
43
|
"author": "VueFrag",
|
|
@@ -44,4 +58,4 @@
|
|
|
44
58
|
"typescript": "^5.0.0",
|
|
45
59
|
"vue": "^3.4.0"
|
|
46
60
|
}
|
|
47
|
-
}
|
|
61
|
+
}
|