Skip to content

Commit dedcc53

Browse files
committed
Apply changes from artemsky#85
1 parent a6125e5 commit dedcc53

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@theace0296/vue-snotify",
3-
"version": "4.0.3",
3+
"version": "4.0.4",
44
"description": "A Vue.js toast notifications",
55
"scripts": {
66
"dev": "vite -c vite.config.ts",

src/components/Snotify.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
</div>
2323
</template>
24-
&
24+
2525
<script lang="ts">
2626
import { defineComponent } from 'vue';
2727
import { SnotifyToast } from './toast.model';

src/components/SnotifyToast.vue

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,8 @@ export default defineComponent({
127127
};
128128
},
129129
created() {
130-
this.$snotify.emitter.on('toastChanged', (toast) => {
131-
if (this.toast.id === toast?.id) {
132-
this.$forceUpdate();
133-
this.initToast();
134-
}
135-
});
136-
this.$snotify.emitter.on('remove', (id) => {
137-
if (this.toast.id === id) {
138-
this.onRemove();
139-
}
140-
});
130+
this.$snotify.emitter.on('toastChanged', this.onChanged);
131+
this.$snotify.emitter.on('remove', this.onRemove);
141132
},
142133
mounted() {
143134
this.$nextTick(() => {
@@ -153,6 +144,8 @@ export default defineComponent({
153144
});
154145
},
155146
unmounted() {
147+
this.$snotify.emitter.off('toastChanged', this.onChanged);
148+
this.$snotify.emitter.off('remove', this.onRemove);
156149
cancelAnimationFrame(this.animationFrame ?? -1);
157150
this.toast.eventEmitter.emit('destroyed');
158151
},
@@ -223,10 +216,22 @@ export default defineComponent({
223216
};
224217
calculate();
225218
},
219+
/**
220+
* Trigger onChanged, updates toast
221+
*/
222+
onChanged(toast: SnotifyToast) {
223+
if (this.toast.id === toast?.id) {
224+
this.$forceUpdate();
225+
this.initToast();
226+
}
227+
},
226228
/**
227229
* Trigger beforeDestroy lifecycle. Removes toast
228230
*/
229-
onRemove() {
231+
onRemove(id: string | number) {
232+
if (this.toast.id !== id) {
233+
return;
234+
}
230235
this.state.isDestroying = true;
231236
this.$emit('state-changed', 'beforeHide');
232237
this.toast.eventEmitter.emit('beforeHide');

0 commit comments

Comments
 (0)