Unified · Split
| @@ -1,29 +1,13 @@ | |||
| 1 | // TODO: This file was created by bulk-decaffeinate. | ||
| 2 | // Sanity-check the conversion and remove this comment. | ||
| 3 | /* | ||
| 4 | * decaffeinate suggestions: | ||
| 5 | * DS101: Remove unnecessary use of Array.from | ||
| 6 | * DS102: Remove unnecessary code created because of implicit returns | ||
| 7 | * DS104: Avoid inline assignments | ||
| 8 | * DS207: Consider shorter variations of null checks | ||
| 9 | * DS208: Avoid top-level this | ||
| 10 | * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md | ||
| 11 | */ | ||
| 12 | class Events { | 1 | class Events { |
| 13 | on(event, callback) { | 2 | on(event, callback) { |
| 14 | if (event.indexOf(" ") >= 0) { | 3 | if (event.indexOf(" ") >= 0) { |
| 15 | for (var name of Array.from(event.split(" "))) { | 4 | for (var name of event.split(" ")) { |
| 16 | this.on(name, callback); | 5 | this.on(name, callback); |
| 17 | } | 6 | } |
| 18 | } else { | 7 | } else { |
| 19 | let base; | 8 | this._callbacks ||= {}; |
| 20 | ((base = | 9 | this._callbacks[event] ||= []; |
| 21 | this._callbacks != null ? this._callbacks : (this._callbacks = {}))[ | 10 | this._callbacks[event].push(callback); |
| 22 | event | ||
| 23 | ] != null | ||
| 24 | ? base[event] | ||
| 25 | : (base[event] = []) | ||
| 26 | ).push(callback); | ||
| 27 | } | 11 | } |
| 28 | return this; | 12 | return this; |
| 29 | } | 13 | } |
| @@ -31,12 +15,11 @@ class Events { · 1 unmodified line | |||
| 31 | off(event, callback) { | 15 | off(event, callback) { |
| 32 | let callbacks, index; | 16 | let callbacks, index; |
| 33 | if (event.indexOf(" ") >= 0) { | 17 | if (event.indexOf(" ") >= 0) { |
| 34 | for (var name of Array.from(event.split(" "))) { | 18 | for (var name of event.split(" ")) { |
| 35 | this.off(name, callback); | 19 | this.off(name, callback); |
| 36 | } | 20 | } |
| 37 | } else if ( | 21 | } else if ( |
| 38 | (callbacks = | 22 | (callbacks = this._callbacks?.[event]) && |
| 39 | this._callbacks != null ? this._callbacks[event] : undefined) && | ||
| 40 | (index = callbacks.indexOf(callback)) >= 0 | 23 | (index = callbacks.indexOf(callback)) >= 0 |
| 41 | ) { | 24 | ) { |
| 42 | callbacks.splice(index, 1); | 25 | callbacks.splice(index, 1); |
| @@ -51,7 +34,7 @@ class Events { · 8 unmodified lines | |||
| 51 | this.eventInProgress = { name: event, args }; | 34 | this.eventInProgress = { name: event, args }; |
| 52 | const callbacks = this._callbacks?.[event]; | 35 | const callbacks = this._callbacks?.[event]; |
| 53 | if (callbacks) { | 36 | if (callbacks) { |
| 54 | for (let callback of Array.from(callbacks.slice(0))) { | 37 | for (let callback of callbacks.slice(0)) { |
| 55 | if (typeof callback === "function") { | 38 | if (typeof callback === "function") { |
| 56 | callback(...args); | 39 | callback(...args); |
| 57 | } | 40 | } |
| @@ -59,14 +42,14 @@ class Events { · 1 unmodified line | |||
| 59 | } | 42 | } |
| 60 | this.eventInProgress = null; | 43 | this.eventInProgress = null; |
| 61 | if (event !== "all") { | 44 | if (event !== "all") { |
| 62 | this.trigger("all", event, ...Array.from(args)); | 45 | this.trigger("all", event, ...args); |
| 63 | } | 46 | } |
| 64 | return this; | 47 | return this; |
| 65 | } | 48 | } |
| 66 | 49 | ||
| 67 | removeEvent(event) { | 50 | removeEvent(event) { |
| 68 | if (this._callbacks != null) { | 51 | if (this._callbacks != null) { |
| 69 | for (var name of Array.from(event.split(" "))) { | 52 | for (var name of event.split(" ")) { |
| 70 | delete this._callbacks[name]; | 53 | delete this._callbacks[name]; |
| 71 | } | 54 | } |
| 72 | } | 55 | } |