History

Sanity-check decaffeinate app.views.DocPicker

Simon Legner committed 2 years ago

Commit 49dbba31 parent b201fb21 file · +11 −35Browse files

Unified · Split

assets/javascripts/views/sidebar/doc_picker.js+11−35
@@ -1,23 +1,10 @@
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− * DS206: Consider reworking classes to avoid initClass
9− * DS207: Consider shorter variations of null checks
10− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
11− */
121 app.views.DocPicker = class DocPicker extends app.View {
13− static initClass() {
14− this.className = "_list _list-picker";
2+ static className = "_list _list-picker";
153
16− this.events = {
17− mousedown: "onMouseDown",
18− mouseup: "onMouseUp",
19− };
20− }
4+ static events = {
5+ mousedown: "onMouseDown",
6+ mouseup: "onMouseUp",
7+ };
218
229 init() {
2310 this.addSubview((this.listFold = new app.views.ListFold(this.el)));
@@ -42,14 +29,12 @@ app.views.DocPicker = class DocPicker extends app.View { · 18 unmodified lines
4229 render() {
4330 let doc;
4431 let html = this.tmpl("docPickerHeader");
45− let docs = app.docs
46− .all()
47− .concat(...Array.from(app.disabledDocs.all() || []));
32+ let docs = app.docs.all().concat(...(app.disabledDocs.all() || []));
4833
4934 while ((doc = docs.shift())) {
5035 if (doc.version != null) {
5136 var versions;
52− [docs, versions] = Array.from(this.extractVersions(docs, doc));
37+ [docs, versions] = this.extractVersions(docs, doc);
5338 html += this.tmpl(
5439 "sidebarVersionedDoc",
5540 doc,
@@ -65,14 +50,12 @@ app.views.DocPicker = class DocPicker extends app.View { · 9 unmodified lines
6550
6651 this.html(html + this.tmpl("docPickerNote"));
6752
68− $.requestAnimationFrame(() =>
69− __guard__(this.findByTag("input"), (x) => x.focus()),
70− );
53+ $.requestAnimationFrame(() => this.findByTag("input")?.focus());
7154 }
7255
7356 renderVersions(docs) {
7457 let html = "";
75− for (var doc of Array.from(docs)) {
58+ for (var doc of docs) {
7659 html += this.tmpl("sidebarLabel", doc, {
7760 checked: app.docs.contains(doc),
7861 });
@@ -83,7 +66,7 @@ app.views.DocPicker = class DocPicker extends app.View { · 4 unmodified lines
8366 extractVersions(originalDocs, version) {
8467 const docs = [];
8568 const versions = [version];
86− for (var doc of Array.from(originalDocs)) {
69+ for (var doc of originalDocs) {
8770 (doc.name === version.name ? versions : docs).push(doc);
8871 }
8972 return [docs, versions];
@@ -95,7 +78,7 @@ app.views.DocPicker = class DocPicker extends app.View { · 5 unmodified lines
9578 }
9679
9780 getSelectedDocs() {
98− return Array.from(this.findAllByTag("input"))
81+ return this.findAllByTag("input")
9982 .filter((input) => (input != null ? input.checked : undefined))
10083 .map((input) => input.name);
10184 }
@@ -146,10 +129,3 @@ app.views.DocPicker = class DocPicker extends app.View { · 44 unmodified lines
146129 this.focusEl = target;
147130 }
148131 };
149−app.views.DocPicker.initClass();
150−
151−function __guard__(value, transform) {
152− return typeof value !== "undefined" && value !== null
153− ? transform(value)
154− : undefined;
155−}