vue-computed-with-control 1.0.4 → 1.0.6
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.github.md +87 -0
- package/README.md +0 -2
- package/README.npm.md +87 -0
- package/banner.svg +8 -12
- package/logo.svg +0 -3
- package/package.json +4 -3
package/README.github.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="banner.svg" alt="vue-computed-with-control" width="100%" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">vue-computed-with-control</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">A Vue 3 composition API utility that lets you explicitly control computed property updates with manual trigger functions and dependency tracking. Provides fine-grained control over when computations re-run.</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/vue-computed-with-control"><img src="https://img.shields.io/npm/v/vue-computed-with-control.svg" alt="npm version" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/vue-computed-with-control"><img src="https://img.shields.io/npm/dm/vue-computed-with-control.svg" alt="npm downloads" /></a>
|
|
12
|
+
<a href="https://github.com/vuefrag/vue-computed-with-control/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/vue-computed-with-control.svg" alt="license" /></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install vue-computed-with-control
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { computedWithControl } from 'vue-computed-with-control';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Explicitly define the dependencies of computed.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { computedWithControl } from 'vue-computed-with-control'
|
|
31
|
+
|
|
32
|
+
const source = ref('foo')
|
|
33
|
+
const counter = ref(0)
|
|
34
|
+
|
|
35
|
+
const computedRef = computedWithControl(
|
|
36
|
+
() => source.value, // watch source, same as `watch`
|
|
37
|
+
() => counter.value, // computed getter, same as `computed`
|
|
38
|
+
)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With this, the changes of `counter` won't trigger `computedRef` to update but the `source` ref does.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
console.log(computedRef.value) // 0
|
|
45
|
+
|
|
46
|
+
counter.value += 1
|
|
47
|
+
|
|
48
|
+
console.log(computedRef.value) // 0
|
|
49
|
+
|
|
50
|
+
source.value = 'bar'
|
|
51
|
+
|
|
52
|
+
console.log(computedRef.value) // 1
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Manual Triggering
|
|
56
|
+
|
|
57
|
+
You can also manually trigger the update of the computed by:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const computedRef = computedWithControl(
|
|
61
|
+
() => source.value,
|
|
62
|
+
() => counter.value,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
computedRef.trigger()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Deep Watch
|
|
69
|
+
|
|
70
|
+
Unlike `computed`, `computedWithControl` is shallow by default.
|
|
71
|
+
You can specify the same options as `watch` to control the behavior:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const source = ref({ name: 'foo' })
|
|
75
|
+
|
|
76
|
+
const computedRef = computedWithControl(
|
|
77
|
+
source,
|
|
78
|
+
() => counter.value,
|
|
79
|
+
{ deep: true },
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> Extracted from [VueUse](https://vueuse.org/) for standalone use.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/README.md
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
<a href="https://github.com/vuefrag/vue-computed-with-control/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/vue-computed-with-control.svg" alt="license" /></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
## Installation
|
|
17
16
|
|
|
18
17
|
```bash
|
|
@@ -83,7 +82,6 @@ const computedRef = computedWithControl(
|
|
|
83
82
|
|
|
84
83
|
> Extracted from [VueUse](https://vueuse.org/) for standalone use.
|
|
85
84
|
|
|
86
|
-
|
|
87
85
|
## License
|
|
88
86
|
|
|
89
87
|
MIT
|
package/README.npm.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="logo.svg" alt="vue-computed-with-control" width="180" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">vue-computed-with-control</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">A Vue 3 composition API utility that lets you explicitly control computed property updates with manual trigger functions and dependency tracking. Provides fine-grained control over when computations re-run.</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/vue-computed-with-control"><img src="https://img.shields.io/npm/v/vue-computed-with-control.svg" alt="npm version" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/vue-computed-with-control"><img src="https://img.shields.io/npm/dm/vue-computed-with-control.svg" alt="npm downloads" /></a>
|
|
12
|
+
<a href="https://github.com/vuefrag/vue-computed-with-control/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/vue-computed-with-control.svg" alt="license" /></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install vue-computed-with-control
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { computedWithControl } from 'vue-computed-with-control';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Explicitly define the dependencies of computed.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { computedWithControl } from 'vue-computed-with-control'
|
|
31
|
+
|
|
32
|
+
const source = ref('foo')
|
|
33
|
+
const counter = ref(0)
|
|
34
|
+
|
|
35
|
+
const computedRef = computedWithControl(
|
|
36
|
+
() => source.value, // watch source, same as `watch`
|
|
37
|
+
() => counter.value, // computed getter, same as `computed`
|
|
38
|
+
)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With this, the changes of `counter` won't trigger `computedRef` to update but the `source` ref does.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
console.log(computedRef.value) // 0
|
|
45
|
+
|
|
46
|
+
counter.value += 1
|
|
47
|
+
|
|
48
|
+
console.log(computedRef.value) // 0
|
|
49
|
+
|
|
50
|
+
source.value = 'bar'
|
|
51
|
+
|
|
52
|
+
console.log(computedRef.value) // 1
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Manual Triggering
|
|
56
|
+
|
|
57
|
+
You can also manually trigger the update of the computed by:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const computedRef = computedWithControl(
|
|
61
|
+
() => source.value,
|
|
62
|
+
() => counter.value,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
computedRef.trigger()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Deep Watch
|
|
69
|
+
|
|
70
|
+
Unlike `computed`, `computedWithControl` is shallow by default.
|
|
71
|
+
You can specify the same options as `watch` to control the behavior:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const source = ref({ name: 'foo' })
|
|
75
|
+
|
|
76
|
+
const computedRef = computedWithControl(
|
|
77
|
+
source,
|
|
78
|
+
() => counter.value,
|
|
79
|
+
{ deep: true },
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> Extracted from [VueUse](https://vueuse.org/) for standalone use.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/banner.svg
CHANGED
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
<rect width="1280" height="640" fill="url(#banner-bg)"/>
|
|
11
11
|
|
|
12
12
|
<!-- Decorative elements -->
|
|
13
|
-
<circle cx="
|
|
14
|
-
<circle cx="
|
|
13
|
+
<circle cx="200" cy="150" r="120" fill="#42b883" opacity="0.06"/>
|
|
14
|
+
<circle cx="1150" cy="500" r="100" fill="#42b883" opacity="0.06"/>
|
|
15
15
|
|
|
16
16
|
<!-- Top accent bar -->
|
|
17
17
|
<rect x="0" y="0" width="1280" height="8" fill="#42b883"/>
|
|
18
18
|
|
|
19
|
-
<!--
|
|
19
|
+
<!-- Vuefrag badge -->
|
|
20
20
|
<g transform="translate(80, 80)">
|
|
21
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">
|
|
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
23
|
</g>
|
|
24
24
|
|
|
25
25
|
<!-- Package name -->
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
<!-- Install command -->
|
|
32
32
|
<g transform="translate(80, 420)">
|
|
33
|
-
<rect width="
|
|
33
|
+
<rect width="600" height="60" rx="8" fill="#0f172a"/>
|
|
34
34
|
<text x="20" y="40" font-family="ui-monospace, monospace" font-size="24" fill="#94a3b8">npm install</text>
|
|
35
35
|
<text x="200" y="40" font-family="ui-monospace, monospace" font-size="24" fill="#42b883">vue-computed-with-control</text>
|
|
36
36
|
</g>
|
|
@@ -41,12 +41,8 @@
|
|
|
41
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
42
|
</g>
|
|
43
43
|
|
|
44
|
-
<!--
|
|
45
|
-
<g
|
|
46
|
-
<
|
|
47
|
-
<polygon points="100,40 125,90 75,90" fill="#42b883" opacity="0.5"/>
|
|
44
|
+
<!-- Category icon (top right corner) -->
|
|
45
|
+
<g>
|
|
46
|
+
<circle cx="1080" cy="150" r="60" fill="none" stroke="#42b883" stroke-width="15"/><circle cx="1080" cy="150" r="25" fill="#42b883"/><path d="M1000 150h-20M1160 150h20M1080 70v-20M1080 230v20" stroke="#42b883" stroke-width="10" stroke-linecap="round"/>
|
|
48
47
|
</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
48
|
</svg>
|
package/logo.svg
CHANGED
|
@@ -9,9 +9,6 @@
|
|
|
9
9
|
<!-- Background -->
|
|
10
10
|
<rect width="96" height="96" rx="16" fill="url(#bg-grad)"/>
|
|
11
11
|
|
|
12
|
-
<!-- Decorative corner accent -->
|
|
13
|
-
<path d="M96 0v20c0-11.046-8.954-20-20-20H96z" fill="#42b883" opacity="0.12"/>
|
|
14
|
-
|
|
15
12
|
<!-- Vue badge -->
|
|
16
13
|
<g transform="translate(8, 8)">
|
|
17
14
|
<rect width="18" height="9" rx="2" fill="#42b883"/>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-computed-with-control",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Vue 3 computed with manual trigger and dependency control",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "unbuild",
|
|
22
|
-
"prepublishOnly": "npm run build"
|
|
22
|
+
"prepublishOnly": "cp README.npm.md README.md && npm run build",
|
|
23
|
+
"postpublish": "cp README.github.md README.md"
|
|
23
24
|
},
|
|
24
25
|
"keywords": [
|
|
25
26
|
"vue",
|
|
@@ -59,4 +60,4 @@
|
|
|
59
60
|
"typescript": "^5.0.0",
|
|
60
61
|
"vue": "^3.4.0"
|
|
61
62
|
}
|
|
62
|
-
}
|
|
63
|
+
}
|