History

Use spread syntax

https://caniuse.com/mdn-javascript_operators_spread

Simon Legner committed 2 years ago

Commit ff7a10c1 parent 416363a4 files · +7 −21Browse files

Unified · Split

4 files
  1. assets/javascripts/app/app.js +2 −1
  2. assets/javascripts/app/searcher.js +3 −3
  3. assets/javascripts/lib/util.js +1 −16
  4. assets/javascripts/views/misc/notif.js +1 −1
assets/javascripts/app/app.js+2−1
@@ -87,7 +87,8 @@ class App extends Events { · 86 unmodified lines
8787 },
8888 dataCallback(data) {
8989 try {
90− $.extend(data.user || (data.user = {}), app.settings.dump());
90+ data.user ||= {};
91+ Object.assign(data.user, app.settings.dump());
9192 if (data.user.docs) {
9293 data.user.docs = data.user.docs.split("/");
9394 }
assets/javascripts/app/searcher.js+3−3
@@ -185,7 +185,7 @@ app.Searcher = class Searcher extends Events { · 184 unmodified lines
185185
186186 constructor(options) {
187187 super();
188− this.options = $.extend({}, Searcher.DEFAULTS, options || {});
188+ this.options = { ...Searcher.DEFAULTS, ...(options || {}) };
189189 }
190190
191191 find(data, attr, q) {
@@ -332,7 +332,7 @@ app.Searcher = class Searcher extends Events { · 140 unmodified lines
332332 for (let j = this.scoreMap.length - 1; j >= 0; j--) {
333333 var objects = this.scoreMap[j];
334334 if (objects) {
335− results.push.apply(results, objects);
335+ results.push(...objects);
336336 }
337337 }
338338 return results.slice(0, this.options.max_results);
@@ -369,7 +369,7 @@ app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher { · 30 unmodified lines
369369 if (!this.allResults) {
370370 this.allResults = [];
371371 }
372− this.allResults.push.apply(this.allResults, this.getResults());
372+ this.allResults.push(...this.getResults());
373373 }
374374 return super.match(...arguments);
375375 }
assets/javascripts/lib/util.js+1−16
@@ -421,18 +421,6 @@ $.smoothScroll = function (el, end) { · 420 unmodified lines
421421 // Utilities
422422 //
423423
424−$.extend = function (target, ...objects) {
425− for (var object of objects) {
426− if (object) {
427− for (var key in object) {
428− var value = object[key];
429− target[key] = value;
430− }
431− }
432− }
433− return target;
434−};
435−
436424 $.makeArray = function (object) {
437425 if (Array.isArray(object)) {
438426 return object;
@@ -573,10 +561,7 @@ const HIGHLIGHT_DEFAULTS = { · 134 unmodified lines
573561 };
574562
575563 $.highlight = function (el, options) {
576− if (options == null) {
577− options = {};
578− }
579− options = $.extend({}, HIGHLIGHT_DEFAULTS, options);
564+ options = { ...HIGHLIGHT_DEFAULTS, ...(options || {}) };
580565 el.classList.add(options.className);
581566 setTimeout(() => el.classList.remove(options.className), options.delay);
582567 };
assets/javascripts/views/misc/notif.js+1−1
@@ -10,7 +10,7 @@ app.views.Notif = class Notif extends app.View { · 9 unmodified lines
1010 constructor(type, options) {
1111 super();
1212 this.type = type;
13− this.options = $.extend({}, this.constructor.defaultOptions, options || {});
13+ this.options = { ...this.constructor.defaultOptions, ...(options || {}) };
1414 this.init0(); // needs this.options
1515 this.refreshElements();
1616 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t