History

Sanity-check decaffeinate class App

Simon Legner committed 2 years ago

Commit dc3dd671 parent a945db91 file · +12 −44Browse files

Unified · Split

assets/javascripts/app/app.js+12−44
@@ -1,13 +1,3 @@
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− * DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
8− * DS207: Consider shorter variations of null checks
9− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
10− */
111 class App extends Events {
122 _$ = $;
133 _$$ = $$;
@@ -81,10 +71,7 @@ class App extends Events { · 67 unmodified lines
8171 tags: {
8272 mode: this.isSingleDoc() ? "single" : "full",
8373 iframe: (window.top !== window).toString(),
84− electron: (!!__guard__(
85− window.process != null ? window.process.versions : undefined,
86− (x) => x.electron,
87− )).toString(),
74+ electron: (!!window.process?.versions?.electron).toString(),
8875 },
8976 shouldSendCallback: () => {
9077 try {
@@ -131,7 +118,7 @@ class App extends Events { · 40 unmodified lines
131118
132119 bootAll() {
133120 const docs = this.settings.getDocs();
134− for (var doc of Array.from(this.DOCS)) {
121+ for (var doc of this.DOCS) {
135122 (docs.indexOf(doc.slug) >= 0 ? this.docs : this.disabledDocs).add(doc);
136123 }
137124 this.migrateDocs();
@@ -144,13 +131,13 @@ class App extends Events { · 6 unmodified lines
144131
145132 start() {
146133 let doc;
147− for (doc of Array.from(this.docs.all())) {
134+ for (doc of this.docs.all()) {
148135 this.entries.add(doc.toEntry());
149136 }
150− for (doc of Array.from(this.disabledDocs.all())) {
137+ for (doc of this.disabledDocs.all()) {
151138 this.entries.add(doc.toEntry());
152139 }
153− for (doc of Array.from(this.docs.all())) {
140+ for (doc of this.docs.all()) {
154141 this.initDoc(doc);
155142 }
156143 this.trigger("ready");
@@ -165,7 +152,7 @@ class App extends Events { · 8 unmodified lines
165152 }
166153
167154 initDoc(doc) {
168− for (var type of Array.from(doc.types.all())) {
155+ for (var type of doc.types.all()) {
169156 doc.entries.add(type.toEntry());
170157 }
171158 this.entries.add(doc.entries.all());
@@ -173,7 +160,7 @@ class App extends Events { · 1 unmodified line
173160
174161 migrateDocs() {
175162 let needsSaving;
176− for (var slug of Array.from(this.settings.getDocs())) {
163+ for (var slug of this.settings.getDocs()) {
177164 if (!this.docs.findBy("slug", slug)) {
178165 var doc;
179166
@@ -227,7 +214,7 @@ class App extends Events { · 47 unmodified lines
227214 }
228215
229216 saveDocs() {
230− this.settings.setDocs(Array.from(this.docs.all()).map((doc) => doc.slug));
217+ this.settings.setDocs(this.docs.all().map((doc) => doc.slug));
231218 this.db.migrate();
232219 return this.serviceWorker != null
233220 ? this.serviceWorker.updateInBackground()
@@ -333,11 +320,11 @@ class App extends Events { · 99 unmodified lines
333320 if (this.cookieBlocked) {
334321 return;
335322 }
336− if (this.isInjectionError(...Array.from(args || []))) {
323+ if (this.isInjectionError(...args)) {
337324 this.onInjectionError();
338− } else if (this.isAppError(...Array.from(args || []))) {
325+ } else if (this.isAppError(...args)) {
339326 if (typeof this.previousErrorHandler === "function") {
340− this.previousErrorHandler(...Array.from(args || []));
327+ this.previousErrorHandler(...args);
341328 }
342329 this.hideLoadingScreen();
343330 if (!this.errorNotif) {
@@ -387,9 +374,7 @@ Please check your browser extensions/addons. `); · 43 unmodified lines
387374 insertAdjacentHTML: !!document.body.insertAdjacentHTML,
388375 defaultPrevented:
389376 document.createEvent("CustomEvent").defaultPrevented === false,
390− cssVariables: !!__guardMethod__(CSS, "supports", (o) =>
391− o.supports("(--t: 0)"),
392− ),
377+ cssVariables: !!CSS.supports?.("(--t: 0)"),
393378 };
394379
395380 for (var key in features) {
@@ -434,21 +419,4 @@ Please check your browser extensions/addons. `); · 38 unmodified lines
434419 }
435420 }
436421
437−function __guard__(value, transform) {
438− return typeof value !== "undefined" && value !== null
439− ? transform(value)
440− : undefined;
441−}
442−function __guardMethod__(obj, methodName, transform) {
443− if (
444− typeof obj !== "undefined" &&
445− obj !== null &&
446− typeof obj[methodName] === "function"
447− ) {
448− return transform(obj, methodName);
449− } else {
450− return undefined;
451− }
452−}
453−
454422 this.app = new App();