rename to ts, tslint auto fix

This commit is contained in:
Leslie
2019-01-08 16:05:03 +08:00
parent af691e621f
commit 59723a976f
4 changed files with 55 additions and 61 deletions
@@ -35,10 +35,10 @@ class CallbackList {
this.containCanceled = false;
}
removeBy (array, value) {
public removeBy (array, value) {
var callbacks = this.callbacks;
var targets = this.targets;
for (var i = 0; i < array.length; ++i) {
for (let i = 0; i < array.length; ++i) {
if (array[i] === value) {
fastRemoveAt(callbacks, i);
fastRemoveAt(targets, i);
@@ -47,14 +47,14 @@ class CallbackList {
}
}
cancel (index) {
public cancel (index) {
this.callbacks[index] = this.targets[index] = null;
this.containCanceled = true;
}
cancelAll () {
let callbacks = this.callbacks;
let targets = this.targets;
public cancelAll () {
const callbacks = this.callbacks;
const targets = this.targets;
for (let i = 0; i < callbacks.length; i++) {
callbacks[i] = targets[i] = null;
}
@@ -62,14 +62,14 @@ class CallbackList {
}
// filter all removed callbacks and compact array
purgeCanceled () {
public purgeCanceled () {
this.removeBy(this.callbacks, null);
this.containCanceled = false;
}
}
const MAX_SIZE = 16;
let callbackListPool = new js.Pool(function (list) {
const callbackListPool = new js.Pool(function (list) {
list.callbacks.length = 0;
list.targets.length = 0;
list.isInvoking = false;
@@ -98,7 +98,7 @@ CallbacksHandler.prototype = {
* @param {Object} [target] - can be null
*/
add (key, callback, target) {
var list = this._callbackTable[key];
let list = this._callbackTable[key];
if (!list) {
list = this._callbackTable[key] = callbackListPool.get();
}
@@ -116,13 +116,13 @@ CallbacksHandler.prototype = {
* @return {Boolean}
*/
hasEventListener (key, callback, target) {
var list = this._callbackTable[key];
const list = this._callbackTable[key];
if (!list) {
return false;
}
// check any valid callback
var callbacks = list.callbacks;
const callbacks = list.callbacks;
if (!callback) {
// Make sure no cancelled callbacks
if (list.isInvoking) {
@@ -132,14 +132,13 @@ CallbacksHandler.prototype = {
}
}
return false;
}
else {
} else {
return callbacks.length > 0;
}
}
target = target || null;
var targets = list.targets;
const targets = list.targets;
for (let i = 0; i < callbacks.length; ++i) {
if (callbacks[i] === callback && targets[i] === target) {
return true;
@@ -156,30 +155,27 @@ CallbacksHandler.prototype = {
removeAll (keyOrTarget) {
if (typeof keyOrTarget === 'string') {
// remove by key
let list = this._callbackTable[keyOrTarget];
const list = this._callbackTable[keyOrTarget];
if (list) {
if (list.isInvoking) {
list.cancelAll();
}
else {
} else {
callbackListPool.put(list);
delete this._callbackTable[keyOrTarget];
}
}
}
else if (keyOrTarget) {
} else if (keyOrTarget) {
// remove by target
for (let key in this._callbackTable) {
let list = this._callbackTable[key];
for (const key in this._callbackTable) {
const list = this._callbackTable[key];
if (list.isInvoking) {
let targets = list.targets;
const targets = list.targets;
for (let i = 0; i < targets.length; ++i) {
if (targets[i] === keyOrTarget) {
list.cancel(i);
}
}
}
else {
} else {
list.removeBy(list.targets, keyOrTarget);
}
}
@@ -193,17 +189,16 @@ CallbacksHandler.prototype = {
* @param {Object} [target]
*/
remove (key, callback, target) {
var list = this._callbackTable[key];
const list = this._callbackTable[key];
if (list) {
target = target || null;
var callbacks = list.callbacks;
var targets = list.targets;
for (var i = 0; i < callbacks.length; ++i) {
const callbacks = list.callbacks;
const targets = list.targets;
for (let i = 0; i < callbacks.length; ++i) {
if (callbacks[i] === callback && targets[i] === target) {
if (list.isInvoking) {
list.cancel(i);
}
else {
} else {
fastRemoveAt(callbacks, i);
fastRemoveAt(targets, i);
}
@@ -211,7 +206,7 @@ CallbacksHandler.prototype = {
}
}
}
}
},
};
/**
@@ -236,21 +231,20 @@ js.mixin(CallbacksInvoker.prototype, {
* @param {any} [p5]
*/
emit (key, p1, p2, p3, p4, p5) {
var list = this._callbackTable[key];
const list = this._callbackTable[key];
if (list) {
var rootInvoker = !list.isInvoking;
const rootInvoker = !list.isInvoking;
list.isInvoking = true;
var callbacks = list.callbacks;
var targets = list.targets;
for (var i = 0, len = callbacks.length; i < len; ++i) {
var callback = callbacks[i];
const callbacks = list.callbacks;
const targets = list.targets;
for (let i = 0, len = callbacks.length; i < len; ++i) {
const callback = callbacks[i];
if (callback) {
var target = targets[i];
const target = targets[i];
if (target) {
callback.call(target, p1, p2, p3, p4, p5);
}
else {
} else {
callback(p1, p2, p3, p4, p5);
}
}
@@ -263,7 +257,7 @@ js.mixin(CallbacksInvoker.prototype, {
}
}
}
}
},
});
if (CC_TEST) {
@@ -272,5 +266,5 @@ if (CC_TEST) {
export {
CallbacksHandler,
CallbacksInvoker
CallbacksInvoker,
};
@@ -103,8 +103,9 @@ js.mixin(EventTarget.prototype, {
if ( !this.hasEventListener(type, callback, target) ) {
this.add(type, callback, target);
if (target && target.__eventTargets)
if (target && target.__eventTargets) {
target.__eventTargets.push(this);
}
}
return callback;
},
@@ -133,8 +134,7 @@ js.mixin(EventTarget.prototype, {
off (type, callback, target) {
if (!callback) {
this.removeAll(type);
}
else {
} else {
this.remove(type, callback, target);
if (target && target.__eventTargets) {
@@ -181,11 +181,11 @@ js.mixin(EventTarget.prototype, {
* }, node);
*/
once (type, callback, target) {
var eventType_hasOnceListener = '__ONCE_FLAG:' + type;
var hasOnceListener = this.hasEventListener(eventType_hasOnceListener, callback, target);
const eventType_hasOnceListener = '__ONCE_FLAG:' + type;
const hasOnceListener = this.hasEventListener(eventType_hasOnceListener, callback, target);
if (!hasOnceListener) {
var self = this;
var onceWrapper = function (arg1, arg2, arg3, arg4, arg5) {
const self = this;
const onceWrapper = function (arg1, arg2, arg3, arg4, arg5) {
self.off(type, onceWrapper, target);
self.remove(eventType_hasOnceListener, callback, target);
callback.call(this, arg1, arg2, arg3, arg4, arg5);
@@ -225,7 +225,7 @@ js.mixin(EventTarget.prototype, {
*/
dispatchEvent (event) {
this.invoke(event.type, event);
}
},
});
cc.EventTarget = EventTarget;
@@ -107,7 +107,7 @@ class Event {
* @method unuse
* @returns {String}
*/
unuse () {
public unuse () {
this.type = cc.Event.NO_TYPE;
this.target = null;
this.currentTarget = null;
@@ -122,7 +122,7 @@ class Event {
* @method reuse
* @returns {String}
*/
reuse (type, bubbles) {
public reuse (type, bubbles) {
this.type = type;
this.bubbles = bubbles || false;
}
@@ -132,7 +132,7 @@ class Event {
* !#zh 停止传递当前事件。
* @method stopPropagation
*/
stopPropagation () {
public stopPropagation () {
this._propagationStopped = true;
}
@@ -142,7 +142,7 @@ class Event {
* !#zh 立即停止当前事件的传递,事件甚至不会被分派到所连接的当前目标。
* @method stopPropagationImmediate
*/
stopPropagationImmediate () {
public stopPropagationImmediate () {
this._propagationImmediateStopped = true;
}
@@ -152,7 +152,7 @@ class Event {
* @method isStopped
* @returns {Boolean}
*/
isStopped () {
public isStopped () {
return this._propagationStopped || this._propagationImmediateStopped;
}
@@ -167,7 +167,7 @@ class Event {
* @method getCurrentTarget
* @returns {Node} The target with which the event associates.
*/
getCurrentTarget () {
public getCurrentTarget () {
return this.currentTarget;
}
@@ -177,12 +177,12 @@ class Event {
* @method getType
* @returns {String}
*/
getType () {
public getType () {
return this.type;
}
}
//event type
// event type
/**
* !#en Code for event without type.
* !#zh 没有类型的事件
@@ -225,7 +225,7 @@ Event.KEYBOARD = 'keyboard';
*/
Event.ACCELERATION = 'acceleration';
//event phase
// event phase
/**
* !#en Events not currently dispatched are in this phase
* !#zh 尚未派发事件阶段
@@ -266,4 +266,4 @@ Event.AT_TARGET = 2;
Event.BUBBLING_PHASE = 3;
cc.Event = Event;
export default Event;
export default Event;
@@ -25,4 +25,4 @@
****************************************************************************/
export { default as Event } from './event';
export { default as EventTarget } from './event-target';
export { default as EventTarget } from './event-target';