Skip to content

Commit ffd60d5

Browse files
authored
Merge pull request #12 from srav001/1.0.0
1.0.0
2 parents 46a82a8 + 4e803a2 commit ffd60d5

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

demo/App.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<script setup lang="ts">
22
import { ref } from 'vue';
33
import ChildComp from './childComp.vue';
4-
import { useEventBus } from './composables/eventBus';
4+
import { useNotifier } from './composables/notifier';
55
66
const testValue = ref(0);
7-
const eventBus = useEventBus();
8-
eventBus.$on((value) => {
7+
const notifier = useNotifier();
8+
notifier.$on(value => {
99
testValue.value = value;
10-
// ^?
1110
});
1211
</script>
1312

@@ -16,7 +15,7 @@ eventBus.$on((value) => {
1615
<h1>{{ testValue }}</h1>
1716

1817
<hr style="margin-top: 5rem; margin-bottom: 5rem" />
19-
<h1>{{ eventBus.$state.value }}</h1>
18+
<h1>{{ notifier.$state.value }}</h1>
2019
<ChildComp />
2120
</div>
2221
</template>

demo/ChildComp.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
2-
import { useEventBus } from './composables/eventBus';
2+
import { useNotifier } from './composables/notifier';
33
4-
const eventBus = useEventBus();
4+
const notifier = useNotifier();
55
function incrementer() {
6-
eventBus.$emit(eventBus.$state.value + 1);
6+
notifier.$emit(val => val + 1);
7+
// or notifier.$emit(notifier.$state.value + 1);
78
}
89
</script>
910

demo/composables/eventBus.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

demo/composables/notifier.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useSubscription } from '../../src/subscription';
2+
3+
const notifier = useSubscription(0);
4+
5+
export function useNotifier() {
6+
return {
7+
$on: notifier.$addSub,
8+
$off: notifier.$deleteSub,
9+
$emit: notifier.$set,
10+
$state: notifier.$read
11+
};
12+
}

package.json

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

scripts/release/releaseData.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"onGoing": false,
3-
"version": "0.0.9"
3+
"version": "1.0.0"
44
}

src/subscription.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { dynamicallyExecuteFunction } from './functions/helpers';
22
import { ref, shallowRef, readonly } from 'vue';
33

44
/**
5-
* It takes a value and returns an object with a value property that is a shallowRef/ref of the value.
6-
* passed in, and Subscribers(function) are added to a list to be executed when the value is changed.
5+
* It takes a value and returns an object with a value property that is a shallowRef/ref of the value
6+
* passed in and Subscribers(function) are added to a list to be executed when the value is changed.
7+
* @example useSubscription<T>(value: T, deep = false)
78
* @param {T} value - T - The initial value of the subscription.
89
* @param {boolean} deep - T - If it should be deep reactivity. By default it is Shallow.
910
* @returns A function that returns an object with a shallow/deep reactive value, a subscriber and a
@@ -78,7 +79,7 @@ export function useSubscription<T>(value: T, deep = false) {
7879
else setValue(val);
7980
},
8081

81-
/** ReadOnly version of value. Wraps the shallow ref in readonly */
82+
/** ReadOnly version of value. Wraps the ref in readonly */
8283
$read: readonly(_subRef),
8384

8485
/**
@@ -108,7 +109,7 @@ export function useSubscription<T>(value: T, deep = false) {
108109
*/
109110
$mutate(mutator: ValueMutator) {
110111
if (typeof _subRef.value !== 'object') {
111-
throw new Error('Value passed is not an typeof object! Patch only accepts typeof object');
112+
throw new Error('Value passed is not an typeof object! $mutate only accepts `typeof object`');
112113
}
113114
mutateSubscriber(mutator);
114115
}

0 commit comments

Comments
 (0)