forked from caroso1222/notyf
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat( default behaviour ): pause notification kill-duration on mouseo…
…ver and resume on mouseleave - add "should pause on mouseover" test - add "EventListener", "Timer" utilities' classes - public "NotyfNotification.triggerEvent" | to make "NotyfView" trigger "mouseover" event on "NotyfNotification" - add "NotyfEvent.MouseOver" - add "NotyfEvent.MouseLeave" - update "Notyf._pushNotification" = pause "NotyfNotification" timer and resume timer on "mouseleave" = remove "NotyfNotification" on timer "finished" event - trigger "mouseover" event on "NotyfNotification" by "NotyfView" - trigger "mouseleave" event on "NotyfNotification" by "NotyfView" close caroso1222#110
- Loading branch information
1 parent
d19f0ab
commit 1189430
Showing
7 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type EventCallback = (event: any) => void; | ||
|
||
export default class EventeListener { | ||
protected listeners: Partial<Record<string, EventCallback[]>> = {}; | ||
|
||
constructor() {} | ||
|
||
public on(eventType: string, cb: EventCallback) { | ||
const callbacks = this.listeners[eventType] || []; | ||
this.listeners[eventType] = callbacks.concat([cb]); | ||
} | ||
|
||
protected triggerEvent(eventType: string, event?: any) { | ||
const callbacks = this.listeners[eventType] || []; | ||
callbacks.forEach((callback: EventCallback) => callback(event)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import EventListener from './eventListener'; | ||
|
||
export default class Timer extends EventListener { | ||
|
||
private startTime: number = Date.now(); | ||
|
||
private timer: ReturnType<typeof setTimeout>; | ||
|
||
private lastTime: number = Date.now(); | ||
|
||
get leftTime() { | ||
return this.duration - (this.lastTime - this.startTime); | ||
} | ||
|
||
constructor(public duration: number) { | ||
super(); | ||
|
||
this.timer = setTimeout(() => { | ||
this.triggerEvent('finished'); | ||
|
||
this.lastTime = Date.now(); | ||
}, duration); | ||
} | ||
|
||
pause() { | ||
this.triggerEvent('pause'); | ||
|
||
clearTimeout(this.timer); | ||
|
||
this.lastTime = Date.now(); | ||
} | ||
|
||
resume() { | ||
this.triggerEvent('resume'); | ||
|
||
clearTimeout(this.timer); | ||
|
||
this.timer = setTimeout(() => { | ||
this.triggerEvent('finished'); | ||
|
||
this.lastTime = Date.now(); | ||
}, this.leftTime); | ||
} | ||
|
||
} |