-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf48f4d
commit 16ae211
Showing
55 changed files
with
11,731 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
29 changes: 29 additions & 0 deletions
29
zoompinch-vue/src/controllers/wheel-gestures/events/EventBus.ts
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,29 @@ | ||
import { deepFreeze } from '../utils' | ||
|
||
export type EventMapEmpty = Record<string, unknown> | ||
export type EventListener<D = unknown> = (data: D) => void | ||
export type Off = () => void | ||
|
||
export default function EventBus<EventMap = EventMapEmpty>() { | ||
const listeners = {} as Record<keyof EventMap, EventListener<never>[]> | ||
|
||
function on<EK extends keyof EventMap>(type: EK, listener: EventListener<EventMap[EK]>): Off { | ||
listeners[type] = (listeners[type] || []).concat(listener) | ||
return () => off(type, listener) | ||
} | ||
|
||
function off<EK extends keyof EventMap>(type: EK, listener: EventListener<EventMap[EK]>) { | ||
listeners[type] = (listeners[type] || []).filter((l) => l !== listener) | ||
} | ||
|
||
function dispatch<EK extends keyof EventMap>(type: EK, data: EventMap[EK]) { | ||
if (!(type in listeners)) return | ||
;(listeners[type] as EventListener<EventMap[EK]>[]).forEach((l) => l(data)) | ||
} | ||
|
||
return deepFreeze({ | ||
on, | ||
off, | ||
dispatch, | ||
}) | ||
} |
33 changes: 33 additions & 0 deletions
33
zoompinch-vue/src/controllers/wheel-gestures/events/WheelTargetObserver.ts
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,33 @@ | ||
import { WheelEventData } from '../types' | ||
import { deepFreeze } from '../utils' | ||
|
||
type UnobserveTarget = () => void | ||
|
||
export function WheelTargetObserver(eventListener: (wheelEvent: WheelEventData) => void) { | ||
let targets: EventTarget[] = [] | ||
|
||
// add event listener to target element | ||
const observe = (target: EventTarget): UnobserveTarget => { | ||
target.addEventListener('wheel', eventListener as EventListener, { passive: false }) | ||
targets.push(target) | ||
|
||
return () => unobserve(target) | ||
} | ||
|
||
/// remove event listener from target element | ||
const unobserve = (target: EventTarget) => { | ||
target.removeEventListener('wheel', eventListener as EventListener) | ||
targets = targets.filter((t) => t !== target) | ||
} | ||
|
||
// stops watching all of its target elements for visibility changes. | ||
const disconnect = () => { | ||
targets.forEach(unobserve) | ||
} | ||
|
||
return deepFreeze({ | ||
observe, | ||
unobserve, | ||
disconnect, | ||
}) | ||
} |
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,5 @@ | ||
export { WheelGestures as default } from './wheel-gestures/wheel-gestures' | ||
export * from './wheel-gestures/wheel-gestures' | ||
export { configDefaults } from './wheel-gestures/options' | ||
export * from './types' | ||
export * from './utils' |
Oops, something went wrong.