UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

65 lines (64 loc) 2.51 kB
import { TypedNode } from '../_Base'; import { NodeContext } from '../../poly/NodeContext'; import { NodeParamsConfig } from '../utils/params/ParamsConfig'; import { BaseEventConnectionPoint } from '../utils/io/connections/Event'; import { EventContext } from '../../../core/event/EventContextType'; type DispatchHook = (event_context: EventContext<Event>) => void; /** * * * TypedEventNode is the base class for all nodes that process events. This inherits from [TypedNode](/docs/api/TypedNode). * */ export declare class TypedEventNode<K extends NodeParamsConfig> extends TypedNode<NodeContext.EVENT, K> { static context(): NodeContext; initializeBaseNode(): void; private _cookWithoutInputsBound; _cookWithoutInputs(): void; cook(): void; processEventViaConnectionPoint(eventContext: EventContext<Event>, connectionPoint: BaseEventConnectionPoint): void; processEvent(event_context: EventContext<Event>): void; protected dispatchEventToOutput(output_name: string, event_context: EventContext<Event>): Promise<void>; private _on_dispatch_hooks_by_output_name; /** * onDispatch is called when an output triggers an event. * * Here is an example usage to listen to events: * * ``` ts *let _currentState = false; *function setHit( newState ){ * if( _currentState != newState ){ * if( newState ){ * playSound(); * } * _currentState = newState; * } *} * *const raycastNode = scene.node('<path to the node>'); *raycastNode.onDispatch('hit', ()=>setHit(true) ); *raycastNode.onDispatch('miss', ()=>setHit(false) ); * ``` * * Alternatively, you can also have the following arguments from the callback * * - viewer: the [viewer](https://polygonjs.com/docs/api/TypedViewer) displaying the scene. * - event: the mouse/pointer/keyboard event that originally triggered the event * - emitter: the domElement the event was triggered from (either the canvas or the document) * - value: an optional value linked to the event. * * ``` ts *raycastNode.onDispatch('hit',(eventContext)=>{ * const {viewer, event, emitter, value} = eventContext; *}); * ``` * */ onDispatch(outputName: string, callback: DispatchHook): void; private run_on_dispatch_hook; } export type BaseEventNodeType = TypedEventNode<any>; export declare class BaseEventNodeClass extends TypedEventNode<any> { } export {};