From ff7a10c00349c375a820e32377375d7954062a50 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sat, 6 Jan 2024 17:32:18 +0100 Subject: [PATCH] Use spread syntax https://caniuse.com/mdn-javascript_operators_spread --- assets/javascripts/app/app.js | 3 ++- assets/javascripts/app/searcher.js | 6 +++--- assets/javascripts/lib/util.js | 17 +---------------- assets/javascripts/views/misc/notif.js | 2 +- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/assets/javascripts/app/app.js b/assets/javascripts/app/app.js index 91d380b9..06d5327e 100644 --- a/assets/javascripts/app/app.js +++ b/assets/javascripts/app/app.js @@ -87,7 +87,8 @@ class App extends Events { }, dataCallback(data) { try { - $.extend(data.user || (data.user = {}), app.settings.dump()); + data.user ||= {}; + Object.assign(data.user, app.settings.dump()); if (data.user.docs) { data.user.docs = data.user.docs.split("/"); } diff --git a/assets/javascripts/app/searcher.js b/assets/javascripts/app/searcher.js index 47a0b820..7cd6e826 100644 --- a/assets/javascripts/app/searcher.js +++ b/assets/javascripts/app/searcher.js @@ -185,7 +185,7 @@ app.Searcher = class Searcher extends Events { constructor(options) { super(); - this.options = $.extend({}, Searcher.DEFAULTS, options || {}); + this.options = { ...Searcher.DEFAULTS, ...(options || {}) }; } find(data, attr, q) { @@ -332,7 +332,7 @@ app.Searcher = class Searcher extends Events { for (let j = this.scoreMap.length - 1; j >= 0; j--) { var objects = this.scoreMap[j]; if (objects) { - results.push.apply(results, objects); + results.push(...objects); } } return results.slice(0, this.options.max_results); @@ -369,7 +369,7 @@ app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher { if (!this.allResults) { this.allResults = []; } - this.allResults.push.apply(this.allResults, this.getResults()); + this.allResults.push(...this.getResults()); } return super.match(...arguments); } diff --git a/assets/javascripts/lib/util.js b/assets/javascripts/lib/util.js index 4da077ba..97d4e733 100644 --- a/assets/javascripts/lib/util.js +++ b/assets/javascripts/lib/util.js @@ -421,18 +421,6 @@ $.smoothScroll = function (el, end) { // Utilities // -$.extend = function (target, ...objects) { - for (var object of objects) { - if (object) { - for (var key in object) { - var value = object[key]; - target[key] = value; - } - } - } - return target; -}; - $.makeArray = function (object) { if (Array.isArray(object)) { return object; @@ -573,10 +561,7 @@ const HIGHLIGHT_DEFAULTS = { }; $.highlight = function (el, options) { - if (options == null) { - options = {}; - } - options = $.extend({}, HIGHLIGHT_DEFAULTS, options); + options = { ...HIGHLIGHT_DEFAULTS, ...(options || {}) }; el.classList.add(options.className); setTimeout(() => el.classList.remove(options.className), options.delay); }; diff --git a/assets/javascripts/views/misc/notif.js b/assets/javascripts/views/misc/notif.js index 03c2c261..d2b1858e 100644 --- a/assets/javascripts/views/misc/notif.js +++ b/assets/javascripts/views/misc/notif.js @@ -10,7 +10,7 @@ app.views.Notif = class Notif extends app.View { constructor(type, options) { super(); this.type = type; - this.options = $.extend({}, this.constructor.defaultOptions, options || {}); + this.options = { ...this.constructor.defaultOptions, ...(options || {}) }; this.init0(); // needs this.options this.refreshElements(); }