Use ES6 style class
This commit is contained in:
parent
5fc671f522
commit
f830af49c2
1 changed files with 16 additions and 16 deletions
|
@ -1,15 +1,16 @@
|
||||||
var CallbacksRegistry;
|
'use strict';
|
||||||
|
|
||||||
var slice = [].slice;
|
var slice = [].slice;
|
||||||
|
|
||||||
const v8Util = process.atomBinding('v8_util');
|
const v8Util = process.atomBinding('v8_util');
|
||||||
|
|
||||||
module.exports = CallbacksRegistry = (function() {
|
class CallbacksRegistry {
|
||||||
function CallbacksRegistry() {
|
constructor() {
|
||||||
this.nextId = 0;
|
this.nextId = 0;
|
||||||
this.callbacks = {};
|
this.callbacks = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.add = function(callback) {
|
add(callback) {
|
||||||
// The callback is already added.
|
// The callback is already added.
|
||||||
var filenameAndLine, id, location, match, ref, regexp, stackString, x;
|
var filenameAndLine, id, location, match, ref, regexp, stackString, x;
|
||||||
id = v8Util.getHiddenValue(callback, 'callbackId');
|
id = v8Util.getHiddenValue(callback, 'callbackId');
|
||||||
|
@ -37,29 +38,28 @@ module.exports = CallbacksRegistry = (function() {
|
||||||
v8Util.setHiddenValue(callback, 'callbackId', id);
|
v8Util.setHiddenValue(callback, 'callbackId', id);
|
||||||
v8Util.setHiddenValue(callback, 'location', filenameAndLine);
|
v8Util.setHiddenValue(callback, 'location', filenameAndLine);
|
||||||
return id;
|
return id;
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.get = function(id) {
|
get(id) {
|
||||||
var ref;
|
var ref;
|
||||||
return (ref = this.callbacks[id]) != null ? ref : function() {};
|
return (ref = this.callbacks[id]) != null ? ref : function() {};
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.call = function() {
|
call() {
|
||||||
var args, id, ref;
|
var args, id, ref;
|
||||||
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||||
return (ref = this.get(id)).call.apply(ref, [global].concat(slice.call(args)));
|
return (ref = this.get(id)).call.apply(ref, [global].concat(slice.call(args)));
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.apply = function() {
|
apply() {
|
||||||
var args, id, ref;
|
var args, id, ref;
|
||||||
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||||
return (ref = this.get(id)).apply.apply(ref, [global].concat(slice.call(args)));
|
return (ref = this.get(id)).apply.apply(ref, [global].concat(slice.call(args)));
|
||||||
};
|
}
|
||||||
|
|
||||||
CallbacksRegistry.prototype.remove = function(id) {
|
remove(id) {
|
||||||
return delete this.callbacks[id];
|
return delete this.callbacks[id];
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CallbacksRegistry;
|
modules.exports = CallbacksRegistry
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue