Skip to content

Commit

Permalink
Apply changes from artemsky#85
Browse files Browse the repository at this point in the history
  • Loading branch information
theace0296 committed Dec 31, 2022
1 parent a6125e5 commit dedcc53
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theace0296/vue-snotify",
"version": "4.0.3",
"version": "4.0.4",
"description": "A Vue.js toast notifications",
"scripts": {
"dev": "vite -c vite.config.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Snotify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
</div>
</template>
&

<script lang="ts">
import { defineComponent } from 'vue';
import { SnotifyToast } from './toast.model';
Expand Down
29 changes: 17 additions & 12 deletions src/components/SnotifyToast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,8 @@ export default defineComponent({
};
},
created() {
this.$snotify.emitter.on('toastChanged', (toast) => {
if (this.toast.id === toast?.id) {
this.$forceUpdate();
this.initToast();
}
});
this.$snotify.emitter.on('remove', (id) => {
if (this.toast.id === id) {
this.onRemove();
}
});
this.$snotify.emitter.on('toastChanged', this.onChanged);
this.$snotify.emitter.on('remove', this.onRemove);
},
mounted() {
this.$nextTick(() => {
Expand All @@ -153,6 +144,8 @@ export default defineComponent({
});
},
unmounted() {
this.$snotify.emitter.off('toastChanged', this.onChanged);
this.$snotify.emitter.off('remove', this.onRemove);
cancelAnimationFrame(this.animationFrame ?? -1);
this.toast.eventEmitter.emit('destroyed');
},
Expand Down Expand Up @@ -223,10 +216,22 @@ export default defineComponent({
};
calculate();
},
/**
* Trigger onChanged, updates toast
*/
onChanged(toast: SnotifyToast) {
if (this.toast.id === toast?.id) {
this.$forceUpdate();
this.initToast();
}
},
/**
* Trigger beforeDestroy lifecycle. Removes toast
*/
onRemove() {
onRemove(id: string | number) {
if (this.toast.id !== id) {
return;
}
this.state.isDestroying = true;
this.$emit('state-changed', 'beforeHide');
this.toast.eventEmitter.emit('beforeHide');
Expand Down

0 comments on commit dedcc53

Please sign in to comment.