Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
noEvents,
invalidateFrameloop: false,
frames: 0,
aspect: 0,
subscribers: [],
camera: defaultCam,
scene: defaultScene,
raycaster: defaultRaycaster,
mouse,
clock,
gl,
size,
viewport: { width: 0, height: 0, factor: 0 },
initialClick: [0, 0],
initialHits: [],
pointer: new TinyEmitter(),
captured: undefined,
events: (undefined as unknown) as PointerEvents,
subscribe: (ref: React.MutableRefObject, priority: number = 0) => {
// If this subscription was given a priority, it takes rendering into its own hands
// For that reason we switch off automatic rendering and increase the manual flag
// As long as this flag is positive (there could be multiple render subscription)
// ..there can be no internal rendering at all
if (priority) state.current.manual++
state.current.subscribers.push({ ref, priority: priority })
// Sort layers from lowest to highest, meaning, highest priority renders last (on top of the other frames)
state.current.subscribers = state.current.subscribers.sort((a, b) => a.priority - b.priority)
return () => {
// Decrease manual flag if this subscription had a priority
if (priority) state.current.manual--