mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-07 00:02:53 +08:00
* remove asserts from addChild * expose js._registeredClassIds & js._registeredClassNames (sync #3174) To unload scripts dynamically. Also revert part of changes from https://github.com/cocos-creator/engine/pull/3204/files#diff-cabe5229c3c6e31339220008e54fe853L421 * remove unused code (sync #3174) * minor tweak (sync #3421) * should not invoke component if destroy() called before node activating (sync #3430) * node should removed and destroyed with scene (sync #3456 #3483) * fix WebGL detection on Android browsers (sync #3510) * remove redundant right shift for bitwise operation (sync #3754) * fix label blur when using dark font color (sync #3949) * refine tooltip of Block Input Event (sync #4053) * fix IE/Edge exception when output log/warn before engine initialization(sync #4447, #4500) * sync class, attribute (#4689, #4712, #4781, #4712) * fix loading unknown texture format (sync #4820) * prefer toLowerCase to toLocaleLowerCase + sync #5114 * optimize bezier calculation (sync #5155) * fix potential memory leak in scene-editor (sync #5643) * fix _posDirty error of Mask on native platform (sync #6168)
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
|
|
module('EventTarget');
|
|
|
|
test('once', function () {
|
|
var target = new cc.EventTarget();
|
|
var fireEvent = new cc.Event('fire');
|
|
var cb1 = new Callback();
|
|
|
|
// once
|
|
target.once('fire', cb1.enable());
|
|
target.dispatchEvent(fireEvent);
|
|
cb1.once('should be invoked if registered by once')
|
|
.disable('should only invoke once 1');
|
|
target.dispatchEvent(fireEvent);
|
|
|
|
// once + on
|
|
var cb2 = new Callback().enable();
|
|
|
|
target.once('fire', cb1.enable());
|
|
target.on('fire', cb2);
|
|
|
|
target.dispatchEvent(fireEvent);
|
|
cb1.once('should be invoked if registered by once and before other callback');
|
|
cb2.once('should still be invoked if previous event was removed');
|
|
|
|
cb1.disable('should only invoke once 2');
|
|
target.dispatchEvent(fireEvent);
|
|
cb2.once('should not remove common event');
|
|
|
|
// on + once
|
|
|
|
target.once('fire', cb1.enable());
|
|
target.dispatchEvent(fireEvent);
|
|
cb2.once();
|
|
cb1.once('should be invoked if registered by once and after other callback')
|
|
.disable('should only invoke once 3');
|
|
target.dispatchEvent(fireEvent);
|
|
cb2.once();
|
|
});
|
|
|
|
test('call "once" twice', function () {
|
|
var target = new cc.EventTarget();
|
|
var cb1 = new Callback().enable();
|
|
var ctx = {};
|
|
|
|
target.once('fire', cb1, ctx, true);
|
|
target.once('fire', cb1, ctx, true);
|
|
target.emit('fire');
|
|
cb1.once('should be invoked only once')
|
|
.disable('should only invoke once');
|
|
target.emit('fire');
|
|
});
|
|
|
|
test('call "off" without handler twice during invoking', function () {
|
|
var target = new cc.EventTarget();
|
|
var ctx = {};
|
|
|
|
function handler () {
|
|
target.off('fire');
|
|
target.off('fire', handler, ctx);
|
|
}
|
|
target.on('fire', handler, ctx, true);
|
|
target.emit('fire');
|
|
|
|
expect(0);
|
|
});
|