From f84fea5c0e638ed308d1a1a9d4aa4e27b2081321 Mon Sep 17 00:00:00 2001 From: yunji Date: Tue, 6 Jul 2021 17:22:11 +0800 Subject: [PATCH] feat(scene): add once event for scene --- packages/core/src/services/scene/ISceneService.ts | 1 + packages/scene/src/index.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/packages/core/src/services/scene/ISceneService.ts b/packages/core/src/services/scene/ISceneService.ts index 28b77cf473..42cea47212 100644 --- a/packages/core/src/services/scene/ISceneService.ts +++ b/packages/core/src/services/scene/ISceneService.ts @@ -9,6 +9,7 @@ export interface ISceneService { fontFamily: string; loadFont: boolean; on(type: string, handle: (...args: any[]) => void): void; + once(type: string, handle: (...args: any[]) => void): void; off(type: string, handle: (...args: any[]) => void): void; removeAllListeners(event?: string): this; init(config: IMapConfig & IRenderConfig): void; diff --git a/packages/scene/src/index.ts b/packages/scene/src/index.ts index 6b5046edf8..b08a955be2 100644 --- a/packages/scene/src/index.ts +++ b/packages/scene/src/index.ts @@ -266,6 +266,12 @@ class Scene : this.sceneService.on(type, handle); } + public once(type: string, handle: (...args: any[]) => void): void { + SceneEventList.indexOf(type) === -1 + ? this.mapService.once(type, handle) + : this.sceneService.once(type, handle); + } + public off(type: string, handle: (...args: any[]) => void): void { SceneEventList.indexOf(type) === -1 ? this.mapService.off(type, handle)