Skip to content

Commit

Permalink
Merge pull request #12 from srav001/1.0.0
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
srav001 authored May 25, 2023
2 parents 46a82a8 + 4e803a2 commit ffd60d5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
9 changes: 4 additions & 5 deletions demo/App.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<script setup lang="ts">
import { ref } from 'vue';
import ChildComp from './childComp.vue';
import { useEventBus } from './composables/eventBus';
import { useNotifier } from './composables/notifier';
const testValue = ref(0);
const eventBus = useEventBus();
eventBus.$on((value) => {
const notifier = useNotifier();
notifier.$on(value => {
testValue.value = value;
// ^?
});
</script>

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

<hr style="margin-top: 5rem; margin-bottom: 5rem" />
<h1>{{ eventBus.$state.value }}</h1>
<h1>{{ notifier.$state.value }}</h1>
<ChildComp />
</div>
</template>
7 changes: 4 additions & 3 deletions demo/ChildComp.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script setup lang="ts">
import { useEventBus } from './composables/eventBus';
import { useNotifier } from './composables/notifier';
const eventBus = useEventBus();
const notifier = useNotifier();
function incrementer() {
eventBus.$emit(eventBus.$state.value + 1);
notifier.$emit(val => val + 1);
// or notifier.$emit(notifier.$state.value + 1);
}
</script>

Expand Down
12 changes: 0 additions & 12 deletions demo/composables/eventBus.ts

This file was deleted.

12 changes: 12 additions & 0 deletions demo/composables/notifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useSubscription } from '../../src/subscription';

const notifier = useSubscription(0);

export function useNotifier() {
return {
$on: notifier.$addSub,
$off: notifier.$deleteSub,
$emit: notifier.$set,
$state: notifier.$read
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-subscription",
"version": "0.0.9",
"version": "1.0.0",
"description": "A type-safe 🔥 & tiny ⭐️ super-charged ref ⚡️ / eventBus replacement in Vue 💚.",
"keywords": [
"web",
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.9"
"version": "1.0.0"
}
9 changes: 5 additions & 4 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { dynamicallyExecuteFunction } from './functions/helpers';
import { ref, shallowRef, readonly } from 'vue';

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

/** ReadOnly version of value. Wraps the shallow ref in readonly */
/** ReadOnly version of value. Wraps the ref in readonly */
$read: readonly(_subRef),

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

0 comments on commit ffd60d5

Please sign in to comment.