From 999e640484a7fef98de466a22883604e82b899df Mon Sep 17 00:00:00 2001 From: timlyeee <43355299+timlyeee@users.noreply.github.com> Date: Fri, 22 Jul 2022 13:31:21 +0800 Subject: [PATCH] add callbacksInvoker missing api (#12131) --- cocos/core/assets/asset.jsb.ts | 3 ++- cocos/core/utils/jsb-utils.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cocos/core/assets/asset.jsb.ts b/cocos/core/assets/asset.jsb.ts index fdda2fd2ac..5c34eda92b 100644 --- a/cocos/core/assets/asset.jsb.ts +++ b/cocos/core/assets/asset.jsb.ts @@ -31,6 +31,7 @@ import { createMap } from '../utils/js-typed'; import { property } from '../data/class-decorator'; import { getUrlWithUuid } from '../asset-manager/helper'; import { extname } from '../utils/path'; +import { ExtraEventMethods } from '../utils/jsb-utils' import '../data/object'; declare const jsb: any; @@ -41,7 +42,7 @@ declare const jsb: any; */ export type CreateNodeCallback = (error: Error | null, node: Node) => void; -applyMixins(jsb.Asset, [CallbacksInvoker]); +applyMixins(jsb.Asset, [CallbacksInvoker, ExtraEventMethods]); const assetProto: any = jsb.Asset.prototype; diff --git a/cocos/core/utils/jsb-utils.ts b/cocos/core/utils/jsb-utils.ts index 4e013dc7e6..6ca9b0840a 100644 --- a/cocos/core/utils/jsb-utils.ts +++ b/cocos/core/utils/jsb-utils.ts @@ -158,3 +158,13 @@ export function updateChildrenForDeserialize (node: Node) { // }); // node._isChildrenRedefined = true; // } +type EventType = string | number; +export function ExtraEventMethods () {} + +ExtraEventMethods.prototype.once = function once void> (type: EventType, callback: Callback, target?: any) { + return this.on(type, callback, target, true) as Callback; +}; + +ExtraEventMethods.prototype.targetOff = function targetOff (typeOrTarget: any) { + this.removeAll(typeOrTarget); +};