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 | 1 | class Events { |
| 13 | 2 | on(event, callback) { |
| 14 | 3 | if (event.indexOf(" ") >= 0) { |
| 15 | − for (var name of Array.from(event.split(" "))) { | |
| 4 | + for (var name of event.split(" ")) { | |
| 16 | 5 | this.on(name, callback); |
| 17 | 6 | } |
| 18 | 7 | } else { |
| 19 | − let base; | |
| 20 | − ((base = | |
| 21 | − this._callbacks != null ? this._callbacks : (this._callbacks = {}))[ | |
| 22 | − event | |
| 23 | − ] != null | |
| 24 | − ? base[event] | |
| 25 | − : (base[event] = []) | |
| 26 | − ).push(callback); | |
| 8 | + this._callbacks ||= {}; | |
| 9 | + this._callbacks[event] ||= []; | |
| 10 | + this._callbacks[event].push(callback); | |
| 27 | 11 | } |
| 28 | 12 | return this; |
| 29 | 13 | } |
| @@ -31,12 +15,11 @@ class Events { · 1 unmodified line | ||
| 31 | 15 | off(event, callback) { |
| 32 | 16 | let callbacks, index; |
| 33 | 17 | if (event.indexOf(" ") >= 0) { |
| 34 | − for (var name of Array.from(event.split(" "))) { | |
| 18 | + for (var name of event.split(" ")) { | |
| 35 | 19 | this.off(name, callback); |
| 36 | 20 | } |
| 37 | 21 | } else if ( |
| 38 | − (callbacks = | |
| 39 | − this._callbacks != null ? this._callbacks[event] : undefined) && | |
| 22 | + (callbacks = this._callbacks?.[event]) && | |
| 40 | 23 | (index = callbacks.indexOf(callback)) >= 0 |
| 41 | 24 | ) { |
| 42 | 25 | callbacks.splice(index, 1); |
| @@ -51,7 +34,7 @@ class Events { · 8 unmodified lines | ||
| 51 | 34 | this.eventInProgress = { name: event, args }; |
| 52 | 35 | const callbacks = this._callbacks?.[event]; |
| 53 | 36 | if (callbacks) { |
| 54 | − for (let callback of Array.from(callbacks.slice(0))) { | |
| 37 | + for (let callback of callbacks.slice(0)) { | |
| 55 | 38 | if (typeof callback === "function") { |
| 56 | 39 | callback(...args); |
| 57 | 40 | } |
| @@ -59,14 +42,14 @@ class Events { · 1 unmodified line | ||
| 59 | 42 | } |
| 60 | 43 | this.eventInProgress = null; |
| 61 | 44 | if (event !== "all") { |
| 62 | − this.trigger("all", event, ...Array.from(args)); | |
| 45 | + this.trigger("all", event, ...args); | |
| 63 | 46 | } |
| 64 | 47 | return this; |
| 65 | 48 | } |
| 66 | 49 | |
| 67 | 50 | removeEvent(event) { |
| 68 | 51 | if (this._callbacks != null) { |
| 69 | − for (var name of Array.from(event.split(" "))) { | |
| 52 | + for (var name of event.split(" ")) { | |
| 70 | 53 | delete this._callbacks[name]; |
| 71 | 54 | } |
| 72 | 55 | } |