add callbacksInvoker missing api (#12131)

This commit is contained in:
timlyeee
2022-07-22 13:31:21 +08:00
committed by GitHub
parent 8ca73f71eb
commit 999e640484
2 changed files with 12 additions and 1 deletions
+2 -1
View File
@@ -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;
+10
View File
@@ -158,3 +158,13 @@ export function updateChildrenForDeserialize (node: Node) {
// });
// node._isChildrenRedefined = true;
// }
type EventType = string | number;
export function ExtraEventMethods () {}
ExtraEventMethods.prototype.once = function once <Callback extends (...any) => 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);
};