You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,26 @@
1
1
# vue-subscription
2
2
3
+
A type-safe 🔥, tiny ⭐️ & fast ⚡️ replacement for EventBus in Vue 💚. Provides ESM and Common JS exports. Compatible with Vue versions `>=2.7.0` or `3.0.0`.
4
+
3
5
This Vue package provides a simple way to create reactive subscriptions that can be used to observe changes to a value and execute a list of subscribers when the value changes. It also includes methods to mutate the value and trigger subscribers manually.
4
6
5
7
The `useSubscription` function takes an initial value and returns an object with a reactive value of the initial value passed in, and a subscriber can be added to be executed when the value is changed.
const $mySubscription =useSubscription('hello'); // Type will be string
22
22
```
23
23
24
-
---
25
-
26
24
## API
27
25
28
26
### $value / $get()
@@ -98,8 +96,6 @@ subscription.$mutate(value => {
98
96
});
99
97
```
100
98
101
-
---
102
-
103
99
## Usage
104
100
105
101
### Basic Example
@@ -202,8 +198,6 @@ $set(val => `Hello ${val}`);
202
198
console.log($read.value); // 'Hello world'
203
199
```
204
200
205
-
---
206
-
207
201
## Type definition
208
202
209
203
### Function Signature
@@ -239,3 +233,8 @@ An object with the following properties:
239
233
- $deleteSub(subscriber: (value: T) => Promise<void> | void)) - A method for removing a subscriber from the subscription.
240
234
- $triggerSubs() - A method for manually triggering all subscribers. This should rarely be necessary.
241
235
- $mutate(mutator: (value: T) => T) - A method for updating the value of the subscription with a function that takes the current value as its argument and returns the new value. This should only be used for updating complex objects.
236
+
237
+
## DEMO
238
+
239
+
You can checkout the demo to test locally or on StackBlitz
0 commit comments