History

Sanity-check decaffeinate app.views.DocPicker

Simon Legner committed 2 years ago

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

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

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 */
12app.views.DocPicker = class DocPicker extends app.View {1app.views.DocPicker = class DocPicker extends app.View {
13 static initClass() {2 static className = "_list _list-picker";
14 this.className = "_list _list-picker";
15 3
16 this.events = {4 static events = {
17 mousedown: "onMouseDown",5 mousedown: "onMouseDown",
18 mouseup: "onMouseUp",6 mouseup: "onMouseUp",
19 };7 };
20 }
21 8
22 init() {9 init() {
23 this.addSubview((this.listFold = new app.views.ListFold(this.el)));10 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
42 render() {29 render() {
43 let doc;30 let doc;
44 let html = this.tmpl("docPickerHeader");31 let html = this.tmpl("docPickerHeader");
45 let docs = app.docs32 let docs = app.docs.all().concat(...(app.disabledDocs.all() || []));
46 .all()
47 .concat(...Array.from(app.disabledDocs.all() || []));
48 33
49 while ((doc = docs.shift())) {34 while ((doc = docs.shift())) {
50 if (doc.version != null) {35 if (doc.version != null) {
51 var versions;36 var versions;
52 [docs, versions] = Array.from(this.extractVersions(docs, doc));37 [docs, versions] = this.extractVersions(docs, doc);
53 html += this.tmpl(38 html += this.tmpl(
54 "sidebarVersionedDoc",39 "sidebarVersionedDoc",
55 doc,40 doc,
@@ -65,14 +50,12 @@ app.views.DocPicker = class DocPicker extends app.View { · 9 unmodified lines
65 50
66 this.html(html + this.tmpl("docPickerNote"));51 this.html(html + this.tmpl("docPickerNote"));
67 52
68 $.requestAnimationFrame(() =>53 $.requestAnimationFrame(() => this.findByTag("input")?.focus());
69 __guard__(this.findByTag("input"), (x) => x.focus()),
70 );
71 }54 }
72 55
73 renderVersions(docs) {56 renderVersions(docs) {
74 let html = "";57 let html = "";
75 for (var doc of Array.from(docs)) {58 for (var doc of docs) {
76 html += this.tmpl("sidebarLabel", doc, {59 html += this.tmpl("sidebarLabel", doc, {
77 checked: app.docs.contains(doc),60 checked: app.docs.contains(doc),
78 });61 });
@@ -83,7 +66,7 @@ app.views.DocPicker = class DocPicker extends app.View { · 4 unmodified lines
83 extractVersions(originalDocs, version) {66 extractVersions(originalDocs, version) {
84 const docs = [];67 const docs = [];
85 const versions = [version];68 const versions = [version];
86 for (var doc of Array.from(originalDocs)) {69 for (var doc of originalDocs) {
87 (doc.name === version.name ? versions : docs).push(doc);70 (doc.name === version.name ? versions : docs).push(doc);
88 }71 }
89 return [docs, versions];72 return [docs, versions];
@@ -95,7 +78,7 @@ app.views.DocPicker = class DocPicker extends app.View { · 5 unmodified lines
95 }78 }
96 79
97 getSelectedDocs() {80 getSelectedDocs() {
98 return Array.from(this.findAllByTag("input"))81 return this.findAllByTag("input")
99 .filter((input) => (input != null ? input.checked : undefined))82 .filter((input) => (input != null ? input.checked : undefined))
100 .map((input) => input.name);83 .map((input) => input.name);
101 }84 }
@@ -146,10 +129,3 @@ app.views.DocPicker = class DocPicker extends app.View { · 44 unmodified lines
146 this.focusEl = target;129 this.focusEl = target;
147 }130 }
148};131};
149app.views.DocPicker.initClass();
150
151function __guard__(value, transform) {
152 return typeof value !== "undefined" && value !== null
153 ? transform(value)
154 : undefined;
155}