Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events): type spread event props #2608

Merged
merged 1 commit into from Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/fiber/src/core/events.ts
Expand Up @@ -4,6 +4,7 @@ import { getRootState } from './utils'
import type { UseBoundStore } from 'zustand'
import type { Instance } from './renderer'
import type { RootState } from './store'
import type { Properties } from '../three-types'

export interface Intersection extends THREE.Intersection {
/** The event source (the object which registered the handler) */
Expand Down Expand Up @@ -34,7 +35,7 @@ export interface IntersectionEvent<TSourceEvent> extends Intersection {
}

export type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera
export type ThreeEvent<TEvent> = IntersectionEvent<TEvent>
export type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
export type DomEvent = PointerEvent | MouseEvent | WheelEvent

export type Events = {
Expand Down
3 changes: 1 addition & 2 deletions packages/fiber/src/core/index.tsx
Expand Up @@ -32,14 +32,13 @@ import {
} from './utils'
import { useStore } from './hooks'
import { OffscreenCanvas } from 'three'
import type { Properties } from '../three-types'

const roots = new Map<Element, Root>()
const { invalidate, advance } = createLoop(roots)
const { reconciler, applyProps } = createRenderer(roots, getEventPriority)
const shallowLoose = { objects: 'shallow', strict: false } as EquConfig

type Properties<T> = Pick<T, { [K in keyof T]: T[K] extends (_: any) => any ? never : K }[keyof T]>

type GLProps =
| Renderer
| ((canvas: HTMLCanvasElement) => Renderer)
Expand Down
1 change: 1 addition & 0 deletions packages/fiber/src/three-types.ts
Expand Up @@ -2,6 +2,7 @@ import * as THREE from 'three'
import { EventHandlers } from './core/events'
import { AttachType } from './core/renderer'

export type Properties<T> = Pick<T, { [K in keyof T]: T[K] extends (_: any) => any ? never : K }[keyof T]>
export type NonFunctionKeys<T> = { [K in keyof T]-?: T[K] extends Function ? never : K }[keyof T]
export type Overwrite<T, O> = Omit<T, NonFunctionKeys<O>> & O

Expand Down