History

Sanity-check decaffeinate class App

Simon Legner committed 2 years ago

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

Showing the changes to assets/javascripts (1 of 1 file). Show all

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 */
11class App extends Events {1class App extends Events {
12 _$ = $;2 _$ = $;
13 _$$ = $$;3 _$$ = $$;
@@ -81,10 +71,7 @@ class App extends Events { · 67 unmodified lines
81 tags: {71 tags: {
82 mode: this.isSingleDoc() ? "single" : "full",72 mode: this.isSingleDoc() ? "single" : "full",
83 iframe: (window.top !== window).toString(),73 iframe: (window.top !== window).toString(),
84 electron: (!!__guard__(74 electron: (!!window.process?.versions?.electron).toString(),
85 window.process != null ? window.process.versions : undefined,
86 (x) => x.electron,
87 )).toString(),
88 },75 },
89 shouldSendCallback: () => {76 shouldSendCallback: () => {
90 try {77 try {
@@ -131,7 +118,7 @@ class App extends Events { · 40 unmodified lines
131 118
132 bootAll() {119 bootAll() {
133 const docs = this.settings.getDocs();120 const docs = this.settings.getDocs();
134 for (var doc of Array.from(this.DOCS)) {121 for (var doc of this.DOCS) {
135 (docs.indexOf(doc.slug) >= 0 ? this.docs : this.disabledDocs).add(doc);122 (docs.indexOf(doc.slug) >= 0 ? this.docs : this.disabledDocs).add(doc);
136 }123 }
137 this.migrateDocs();124 this.migrateDocs();
@@ -144,13 +131,13 @@ class App extends Events { · 6 unmodified lines
144 131
145 start() {132 start() {
146 let doc;133 let doc;
147 for (doc of Array.from(this.docs.all())) {134 for (doc of this.docs.all()) {
148 this.entries.add(doc.toEntry());135 this.entries.add(doc.toEntry());
149 }136 }
150 for (doc of Array.from(this.disabledDocs.all())) {137 for (doc of this.disabledDocs.all()) {
151 this.entries.add(doc.toEntry());138 this.entries.add(doc.toEntry());
152 }139 }
153 for (doc of Array.from(this.docs.all())) {140 for (doc of this.docs.all()) {
154 this.initDoc(doc);141 this.initDoc(doc);
155 }142 }
156 this.trigger("ready");143 this.trigger("ready");
@@ -165,7 +152,7 @@ class App extends Events { · 8 unmodified lines
165 }152 }
166 153
167 initDoc(doc) {154 initDoc(doc) {
168 for (var type of Array.from(doc.types.all())) {155 for (var type of doc.types.all()) {
169 doc.entries.add(type.toEntry());156 doc.entries.add(type.toEntry());
170 }157 }
171 this.entries.add(doc.entries.all());158 this.entries.add(doc.entries.all());
@@ -173,7 +160,7 @@ class App extends Events { · 1 unmodified line
173 160
174 migrateDocs() {161 migrateDocs() {
175 let needsSaving;162 let needsSaving;
176 for (var slug of Array.from(this.settings.getDocs())) {163 for (var slug of this.settings.getDocs()) {
177 if (!this.docs.findBy("slug", slug)) {164 if (!this.docs.findBy("slug", slug)) {
178 var doc;165 var doc;
179 166
@@ -227,7 +214,7 @@ class App extends Events { · 47 unmodified lines
227 }214 }
228 215
229 saveDocs() {216 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));
231 this.db.migrate();218 this.db.migrate();
232 return this.serviceWorker != null219 return this.serviceWorker != null
233 ? this.serviceWorker.updateInBackground()220 ? this.serviceWorker.updateInBackground()
@@ -333,11 +320,11 @@ class App extends Events { · 99 unmodified lines
333 if (this.cookieBlocked) {320 if (this.cookieBlocked) {
334 return;321 return;
335 }322 }
336 if (this.isInjectionError(...Array.from(args || []))) {323 if (this.isInjectionError(...args)) {
337 this.onInjectionError();324 this.onInjectionError();
338 } else if (this.isAppError(...Array.from(args || []))) {325 } else if (this.isAppError(...args)) {
339 if (typeof this.previousErrorHandler === "function") {326 if (typeof this.previousErrorHandler === "function") {
340 this.previousErrorHandler(...Array.from(args || []));327 this.previousErrorHandler(...args);
341 }328 }
342 this.hideLoadingScreen();329 this.hideLoadingScreen();
343 if (!this.errorNotif) {330 if (!this.errorNotif) {
@@ -387,9 +374,7 @@ Please check your browser extensions/addons. `); · 43 unmodified lines
387 insertAdjacentHTML: !!document.body.insertAdjacentHTML,374 insertAdjacentHTML: !!document.body.insertAdjacentHTML,
388 defaultPrevented:375 defaultPrevented:
389 document.createEvent("CustomEvent").defaultPrevented === false,376 document.createEvent("CustomEvent").defaultPrevented === false,
390 cssVariables: !!__guardMethod__(CSS, "supports", (o) =>377 cssVariables: !!CSS.supports?.("(--t: 0)"),
391 o.supports("(--t: 0)"),
392 ),
393 };378 };
394 379
395 for (var key in features) {380 for (var key in features) {
@@ -434,21 +419,4 @@ Please check your browser extensions/addons. `); · 38 unmodified lines
434 }419 }
435}420}
436 421
437function __guard__(value, transform) {
438 return typeof value !== "undefined" && value !== null
439 ? transform(value)
440 : undefined;
441}
442function __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
454this.app = new App();422this.app = new App();