Automated class transform
npx lebab --replace src --transform class
This commit is contained in:
@@ -20,17 +20,99 @@ import EventType from './events/EventType.js';
|
||||
* @struct
|
||||
* @api
|
||||
*/
|
||||
const Observable = function() {
|
||||
class Observable {
|
||||
constructor() {
|
||||
|
||||
EventTarget.call(this);
|
||||
EventTarget.call(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.revision_ = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
* Increases the revision counter and dispatches a 'change' event.
|
||||
* @api
|
||||
*/
|
||||
this.revision_ = 0;
|
||||
changed() {
|
||||
++this.revision_;
|
||||
this.dispatchEvent(EventType.CHANGE);
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Get the version number for this object. Each time the object is modified,
|
||||
* its version number will be incremented.
|
||||
* @return {number} Revision.
|
||||
* @api
|
||||
*/
|
||||
getRevision() {
|
||||
return this.revision_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for a certain type of event.
|
||||
* @param {string|Array.<string>} type The event type or array of event types.
|
||||
* @param {function(?): ?} listener The listener function.
|
||||
* @return {module:ol/events~EventsKey|Array.<module:ol/events~EventsKey>} Unique key for the listener. If
|
||||
* called with an array of event types as the first argument, the return
|
||||
* will be an array of keys.
|
||||
* @api
|
||||
*/
|
||||
on(type, listener) {
|
||||
if (Array.isArray(type)) {
|
||||
const len = type.length;
|
||||
const keys = new Array(len);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
keys[i] = listen(this, type[i], listener);
|
||||
}
|
||||
return keys;
|
||||
} else {
|
||||
return listen(this, /** @type {string} */ (type), listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen once for a certain type of event.
|
||||
* @param {string|Array.<string>} type The event type or array of event types.
|
||||
* @param {function(?): ?} listener The listener function.
|
||||
* @return {module:ol/events~EventsKey|Array.<module:ol/events~EventsKey>} Unique key for the listener. If
|
||||
* called with an array of event types as the first argument, the return
|
||||
* will be an array of keys.
|
||||
* @api
|
||||
*/
|
||||
once(type, listener) {
|
||||
if (Array.isArray(type)) {
|
||||
const len = type.length;
|
||||
const keys = new Array(len);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
keys[i] = listenOnce(this, type[i], listener);
|
||||
}
|
||||
return keys;
|
||||
} else {
|
||||
return listenOnce(this, /** @type {string} */ (type), listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlisten for a certain type of event.
|
||||
* @param {string|Array.<string>} type The event type or array of event types.
|
||||
* @param {function(?): ?} listener The listener function.
|
||||
* @api
|
||||
*/
|
||||
un(type, listener) {
|
||||
if (Array.isArray(type)) {
|
||||
for (let i = 0, ii = type.length; i < ii; ++i) {
|
||||
unlisten(this, type[i], listener);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
unlisten(this, /** @type {string} */ (type), listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Observable, EventTarget);
|
||||
|
||||
@@ -52,16 +134,6 @@ export function unByKey(key) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Increases the revision counter and dispatches a 'change' event.
|
||||
* @api
|
||||
*/
|
||||
Observable.prototype.changed = function() {
|
||||
++this.revision_;
|
||||
this.dispatchEvent(EventType.CHANGE);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dispatches an event and calls all listeners listening for events
|
||||
* of this type. The event parameter can either be a string or an
|
||||
@@ -76,77 +148,4 @@ Observable.prototype.changed = function() {
|
||||
Observable.prototype.dispatchEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Get the version number for this object. Each time the object is modified,
|
||||
* its version number will be incremented.
|
||||
* @return {number} Revision.
|
||||
* @api
|
||||
*/
|
||||
Observable.prototype.getRevision = function() {
|
||||
return this.revision_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Listen for a certain type of event.
|
||||
* @param {string|Array.<string>} type The event type or array of event types.
|
||||
* @param {function(?): ?} listener The listener function.
|
||||
* @return {module:ol/events~EventsKey|Array.<module:ol/events~EventsKey>} Unique key for the listener. If
|
||||
* called with an array of event types as the first argument, the return
|
||||
* will be an array of keys.
|
||||
* @api
|
||||
*/
|
||||
Observable.prototype.on = function(type, listener) {
|
||||
if (Array.isArray(type)) {
|
||||
const len = type.length;
|
||||
const keys = new Array(len);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
keys[i] = listen(this, type[i], listener);
|
||||
}
|
||||
return keys;
|
||||
} else {
|
||||
return listen(this, /** @type {string} */ (type), listener);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Listen once for a certain type of event.
|
||||
* @param {string|Array.<string>} type The event type or array of event types.
|
||||
* @param {function(?): ?} listener The listener function.
|
||||
* @return {module:ol/events~EventsKey|Array.<module:ol/events~EventsKey>} Unique key for the listener. If
|
||||
* called with an array of event types as the first argument, the return
|
||||
* will be an array of keys.
|
||||
* @api
|
||||
*/
|
||||
Observable.prototype.once = function(type, listener) {
|
||||
if (Array.isArray(type)) {
|
||||
const len = type.length;
|
||||
const keys = new Array(len);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
keys[i] = listenOnce(this, type[i], listener);
|
||||
}
|
||||
return keys;
|
||||
} else {
|
||||
return listenOnce(this, /** @type {string} */ (type), listener);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Unlisten for a certain type of event.
|
||||
* @param {string|Array.<string>} type The event type or array of event types.
|
||||
* @param {function(?): ?} listener The listener function.
|
||||
* @api
|
||||
*/
|
||||
Observable.prototype.un = function(type, listener) {
|
||||
if (Array.isArray(type)) {
|
||||
for (let i = 0, ii = type.length; i < ii; ++i) {
|
||||
unlisten(this, type[i], listener);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
unlisten(this, /** @type {string} */ (type), listener);
|
||||
}
|
||||
};
|
||||
export default Observable;
|
||||
|
||||
Reference in New Issue
Block a user