mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-18 12:09:29 -07:00
refactor(stage.ts): rename class 'watchable' to 'Watchable' for consistency and clarity
feat(utils.ts): add Watchable class to provide a generic watchable object with getter, setter, and watcher functionality
This commit is contained in:
@@ -13,3 +13,21 @@ export function expand(num: number): string {
|
||||
export function isMobile(): boolean {
|
||||
return window.matchMedia('(hover: none)').matches
|
||||
}
|
||||
|
||||
export class Watchable<T> {
|
||||
constructor(private obj: T) {}
|
||||
private watchers: (() => void)[] = []
|
||||
|
||||
get(): T {
|
||||
return this.obj
|
||||
}
|
||||
|
||||
set(e: T): void {
|
||||
this.obj = e
|
||||
this.watchers.forEach((watcher) => watcher())
|
||||
}
|
||||
|
||||
addWatcher(watcher: () => void): void {
|
||||
this.watchers.push(watcher)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user