Skip to content

Commit 754fb62

Browse files
authored
Merge pull request #13 from srav001/1.0.1
1.0.1
2 parents ffd60d5 + eddf4d9 commit 754fb62

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

README.md

+24-24
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Find it on `npm` - https://www.npmjs.com/package/vue-subscription.
1515

1616
## Introduction
1717

18-
Only 1.26 kB or gzip: 0.63 kB in size, the [useSubscription](#tldr) composable takes an initial value and returns an object with a reactive value that is by default shallow and only deep when explicitly enabled. The value property, `$value is not automatically unwrapped in template`. Additionally, it also provides `explicit getter and setter` if you like more control over the state.
18+
Only 1.26 kB or gzip: 0.63 kB in size, the [useSubscription](#tldr) composable takes an initial value and returns an object with a reactive value that is by default shallow and only deep when explicitly enabled. The value property, `$value is not automatically unwrapped in template`. Additionally, it also provides `explicit getter and setter` if you like more control over the state.
1919

2020
The package also 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 for complex objects and trigger subscribers manually if and when needed rarely. Check out the [usage](#usage) examples.
2121

@@ -31,7 +31,7 @@ npm install vue-subscription
3131
```typescript
3232
// In your file
3333
import { useSubscription } from 'vue-subscription';
34-
const $mySubscription = useSubscription('hello'); // Type will be string
34+
const mySubscription = useSubscription('hello'); // Type will be string
3535
```
3636

3737
## API
@@ -42,10 +42,10 @@ To display the state in template, you can either use the `$read` or `$get`. If y
4242

4343
```vue
4444
<template>
45-
<div>{{ $mySubscription.$value }}</div>
45+
<div>{{ mySubscription.$value }}</div>
4646
<!-- Readonly version of the state -->
47-
<div>{{ $mySubscription.$get() }}</div>
48-
<div>{{ $mySubscription.$read.value }}</div>
47+
<div>{{ mySubscription.$get() }}</div>
48+
<div>{{ mySubscription.$read.value }}</div>
4949
</template>
5050
```
5151

@@ -54,31 +54,31 @@ To display the state in template, you can either use the `$read` or `$get`. If y
5454
This property/method returns the current value of the subscription.
5555

5656
```typescript
57-
const value = $mySubscription.$value;
58-
const value = $mySubscription.$get();
57+
const value = mySubscription.$value;
58+
const value = mySubscription.$get();
5959
```
6060

6161
### $value = val / $set(val)
6262

6363
This property/method sets the current value of the subscription. Also the $set can be passed down a child component to update the state in parent.
6464

6565
```typescript
66-
$mySubscription.$value = 42;
67-
$mySubscription.$set(42);
66+
mySubscription.$value = 42;
67+
mySubscription.$set(42);
6868
```
6969

7070
The $set method can also accept a mutator function that takes the current value as an argument and returns the new value:
7171

7272
```typescript
73-
$mySubscription.$set(value => value + 1);
73+
mySubscription.$set(value => value + 1);
7474
```
7575

7676
### $read
7777

7878
This is a read-only version of the subscription value. It wraps the subscription in a readonly ref.
7979

8080
```typescript
81-
const readonlySubscription = $mySubscription.$read;
81+
const readonlySubscription = mySubscription.$read;
8282
console.log(readonlySubscription.value);
8383
```
8484

@@ -91,7 +91,7 @@ function logValue(value) {
9191
console.log(`New value: ${value}`);
9292
}
9393

94-
$mySubscription.$addSub(logValue);
94+
mySubscription.$addSub(logValue);
9595
```
9696

9797
### $deleteSub
@@ -128,10 +128,10 @@ All examples given below can be copy pasted into a file and tried out if needed.
128128
### Basic Example
129129

130130
```typescript
131-
const $mySubscription = useSubscription('hello'); // Type will be string
131+
const mySubscription = useSubscription('hello'); // Type will be string
132132

133133
// Get the current value
134-
console.log($mySubscription.$value); // 'hello'
134+
console.log(mySubscription.$value); // 'hello'
135135

136136
// Subscribers can `async`
137137
async function mySubscriber(value: string) {
@@ -143,20 +143,20 @@ async function mySubscriber(value: string) {
143143
}
144144

145145
// Add a subscriber
146-
$mySubscription.$addSub(mySubscriber);
146+
mySubscription.$addSub(mySubscriber);
147147
// Manually trigger the subscribers if needed(rarely)
148-
$mySubscription.$triggerSubs(); // 'The value is now: hello'
148+
mySubscription.$triggerSubs(); // 'The value is now: hello'
149149

150150
// Set the value
151-
$mySubscription.$value = 'world';
151+
mySubscription.$value = 'world';
152152

153153
// Subscriber runs here - 'The value is now: world'
154154

155155
// Remove a subscriber (can be used in onBeforeUnmount or beforeRouteLeave etc)
156-
$mySubscription.$deleteSub(mySubscriber);
156+
mySubscription.$deleteSub(mySubscriber);
157157

158158
// Use the readonly version of the value
159-
const myReadonlyValue = $mySubscription.$read;
159+
const myReadonlyValue = mySubscription.$read;
160160
console.log(myReadonlyValue.value); // 'world'
161161
```
162162

@@ -165,7 +165,7 @@ console.log(myReadonlyValue.value); // 'world'
165165
Example uses a complex objects which won't be tracked deeply by default. Unless the subscription is used in template, watch, watchEffect or computed you don't need to add the deep flag.
166166

167167
```typescript
168-
const $mySubscription = useSubscription(
168+
const mySubscription = useSubscription(
169169
{
170170
user: {
171171
name: 'John',
@@ -176,21 +176,21 @@ const $mySubscription = useSubscription(
176176
true
177177
);
178178
// Add a subscriber
179-
$mySubscription.$addSub(data => {
179+
mySubscription.$addSub(data => {
180180
console.log(`The data is now: ${JSON.stringify(data)}`);
181181
});
182182

183-
function myMutator(data: typeof $mySubscription.$value) {
183+
function myMutator(data: typeof mySubscription.$value) {
184184
data.user.isActive = true;
185185
return data;
186186
}
187187

188188
// Trigger the subscribers
189-
$mySubscription.$triggerSubs(); // 'The data is now: { user: { name: 'John', isActive: false }}'
189+
mySubscription.$triggerSubs(); // 'The data is now: { user: { name: 'John', isActive: false }}'
190190

191191
function tester() {
192192
// Mutate the value (only works if the value is an object)
193-
$mySubscription.$mutate(myMutator);
193+
mySubscription.$mutate(myMutator);
194194
// Subscriber runs here - 'The data is now: { user: { name: 'John', isActive: true }}'
195195
}
196196
tester();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-subscription",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A type-safe 🔥 & tiny ⭐️ super-charged ref ⚡️ / eventBus replacement in Vue 💚.",
55
"keywords": [
66
"web",

scripts/release/releaseData.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"onGoing": false,
3-
"version": "1.0.0"
3+
"version": "1.0.1"
44
}

0 commit comments

Comments
 (0)