Skip to content

Commit 7d6309a

Browse files
authored
Merge pull request #16 from srav001/1.0.3
1.0.3
2 parents 422ceca + 84af28c commit 7d6309a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ This method removes a subscriber from the subscription.
102102
subscription.$deleteSub(logValue);
103103
```
104104

105+
### $clearSubs
106+
107+
Clears all subscribers. Easy for cleanup in beforeUnmount.
108+
109+
```typescript
110+
subscription.$clearSubs();
111+
```
112+
105113
### $triggerSubs
106114

107115
This method manually triggers all subscribers to the subscription. Should only be needed rarely.
@@ -154,6 +162,8 @@ mySubscription.$value = 'world';
154162

155163
// Remove a subscriber (can be used in onBeforeUnmount or beforeRouteLeave etc)
156164
mySubscription.$deleteSub(mySubscriber);
165+
// OR to remove all subs at once.
166+
mySubscription.$clearSubs();
157167

158168
// Use the readonly version of the value
159169
const myReadonlyValue = mySubscription.$read;
@@ -240,6 +250,7 @@ function useSubscription<T>(
240250
$read: Readonly<Ref<T>>;
241251
$addSub: (subscriber: (value: T) => Promise<void> | void) => void;
242252
$deleteSub: (subscriber: (value: T) => Promise<void> | void) => void;
253+
$clearSubs: () => void;
243254
$triggerSubs: () => void;
244255
$mutate: (mutator: (value: T) => T) => void;
245256
};
@@ -263,6 +274,7 @@ An object with the following properties (Type def above):
263274
- $read - A readonly reactive reference to the current value of the subscription.
264275
- $addSub - A method for adding a subscriber to the subscription. It can be `async`. The subscriber is a function that will be executed whenever the value of the subscription changes. It can take the new value of the subscription as its argument.
265276
- $deleteSub - A method for removing a subscriber from the subscription.
277+
- $clearSubs - A method for clearing all subscribers.
266278
- $triggerSubs - A method for manually triggering all subscribers. Should only be needed rarely.
267279
- $mutate - 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.
268280

0 commit comments

Comments
 (0)