|
1 | 1 | import { HTMLAttributes, PropType, SlotsType, TransitionGroup, TransitionGroupProps, computed, defineComponent, onMounted, ref } from 'vue'; |
2 | 2 | import { params } from '@/params'; |
3 | | -import { Id, listToDirection, Timer, NotificationItemWithTimer, emitter, parse } from '@/utils'; |
| 3 | +import { Id, listToDirection, emitter, parse } from '@/utils'; |
4 | 4 | import defaults from '@/defaults'; |
5 | 5 | import { NotificationItem, NotificationsOptions } from '@/types'; |
| 6 | +import { createTimer, NotificationItemWithTimer } from '@/utils/timer'; |
6 | 7 | import './Notifications.css'; |
7 | 8 |
|
8 | 9 | const STATE = { |
@@ -119,7 +120,6 @@ export default defineComponent({ |
119 | 120 | }>, |
120 | 121 | setup: (props, { emit, slots, expose }) => { |
121 | 122 | const list = ref<NotificationItemExtended[]>([]); |
122 | | - const timerControl = ref<Timer | null>(null); |
123 | 123 | const velocity = params.get('velocity'); |
124 | 124 |
|
125 | 125 | const isVA = computed(() => { |
@@ -179,14 +179,14 @@ export default defineComponent({ |
179 | 179 | } |
180 | 180 | }; |
181 | 181 |
|
182 | | - const pauseTimeout = () => { |
| 182 | + const pauseTimeout = (item: NotificationItemExtended): undefined => { |
183 | 183 | if (props.pauseOnHover) { |
184 | | - timerControl.value?.pause(); |
| 184 | + item.timer?.stop(); |
185 | 185 | } |
186 | 186 | }; |
187 | | - const resumeTimeout = () => { |
| 187 | + const resumeTimeout = (item: NotificationItemExtended): undefined => { |
188 | 188 | if (props.pauseOnHover) { |
189 | | - timerControl.value?.resume(); |
| 189 | + item.timer?.start(); |
190 | 190 | } |
191 | 191 | }; |
192 | 192 | const addItem = (event: NotificationsOptions = {}): void => { |
@@ -229,7 +229,7 @@ export default defineComponent({ |
229 | 229 | }; |
230 | 230 |
|
231 | 231 | if (duration >= 0) { |
232 | | - timerControl.value = new Timer(() => destroy(item), item.length, item); |
| 232 | + item.timer = createTimer(() => destroy(item), item.length); |
233 | 233 | } |
234 | 234 |
|
235 | 235 | const botToTop = 'bottom' in styles.value; |
@@ -289,7 +289,7 @@ export default defineComponent({ |
289 | 289 | }; |
290 | 290 |
|
291 | 291 | const destroy = (item: NotificationItemExtended): void => { |
292 | | - clearTimeout(item.timer); |
| 292 | + item.timer?.stop(); |
293 | 293 | item.state = STATE.DESTROYED; |
294 | 294 |
|
295 | 295 | clean(); |
@@ -372,8 +372,8 @@ export default defineComponent({ |
372 | 372 | class='vue-notification-wrapper' |
373 | 373 | style={notifyWrapperStyle(item)} |
374 | 374 | data-id={item.id} |
375 | | - onMouseenter={pauseTimeout} |
376 | | - onMouseleave={resumeTimeout} |
| 375 | + onMouseenter={() => pauseTimeout(item)} |
| 376 | + onMouseleave={() => resumeTimeout(item)} |
377 | 377 | > |
378 | 378 | { |
379 | 379 | slots.body ? slots.body({ |
|
0 commit comments