Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# vue-subscription

A type-safe 🔥, tiny ⭐️ & fast ⚡️ replacement for EventBus in Vue 💚. Compatible with Vue 2 ( 2.7.0 and above ) and Vue 3. Provides ESM and Common JS exports.
A type-safe 🔥, tiny ⭐️ & fast ⚡️ replacement for EventBus / a super-charged ref in Vue 💚. Compatible with Vue 2 ( 2.7.0 and above ) and Vue 3. Provides ESM and Common JS exports.

Find it on `npm` - https://www.npmjs.com/package/vue-subscription.

Expand All @@ -17,7 +17,7 @@ Find it on `npm` - https://www.npmjs.com/package/vue-subscription.

This [package](#https://www.npmjs.com/package/vue-subscription) 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. You can use it as a super charged ref since `$value is not automatically unwrapped in template`.

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. In addition to the value property, also provides `explicit getter and setter` if you like more control over the state.
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. In addition to the value property, also provides `explicit getter and setter` if you like more control over the state. Check out the [usage](#usage) examples to learn more.

## Installation

Expand All @@ -41,14 +41,12 @@ const $mySubscription = useSubscription('hello'); // Type will be string
To display the state in template, you can either use the $value or $get.

```vue

<template>

<div>{{ $mySubscription.$value }}</div>
<div>{{ $mySubscription.$get() }}</div>

<div>{{ $mySubscription.$value }}</div>
<div>{{ $mySubscription.$get() }}</div>
<!-- Readonly version of the state -->
<div>{{ $mySubscription.$read.value }}</div>
</template>

```

### $value / $get()
Expand All @@ -62,7 +60,7 @@ const value = $mySubscription.$get();

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

This property/method sets the current value of the subscription.
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.

```typescript
$mySubscription.$value = 42;
Expand Down Expand Up @@ -259,7 +257,7 @@ deep (optional) - Whether to create a shallow or deep reactive subscription. Def

An object with the following properties (Type def above):

- $value - The current value of the subscription.
- $value - The current value of the subscription. Doesn't unwrap in template.
- $get - A function that returns the current value of the subscription.
- $set - A function that sets the value of the subscription. If a function is passed, it will receive the current value of the subscription as its argument and should return the new value.
- $read - A readonly reactive reference to the current value of the subscription.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-subscription",
"version": "0.0.6",
"description": "A simple ⭐️ & type-safe 🔥 replacement for EventBus in Vue 💚.",
"version": "0.0.8",
"description": "A type-safe 🔥, tiny ⭐️ & fast ⚡️ replacement for EventBus / a super-charged ref in Vue 💚.",
"keywords": [
"web",
"vue",
Expand Down Expand Up @@ -77,4 +77,4 @@
"node": ">=16.0.0",
"pnpm": ">=6.0.0"
}
}
}
2 changes: 1 addition & 1 deletion scripts/release/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function gitUpdate() {
execWithSync(`git add .`);
execWithSync(`git commit --allow-empty -m "chore: releasing version ${version}"`);
execWithSync(`git tag ${version}`);
execWithSync(`git push origin ${version}`);
execWithSync(`ggpush`);

return true;
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/releaseData.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"onGoing": false,
"version": "0.0.5"
"version": "0.0.8"
}
3 changes: 1 addition & 2 deletions src/functions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export async function dynamicallyExecuteFunction<T>(func: Function, arg: T) {
return result;
}
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
throw new Error('Function failed to run', { cause: err });
}
}