From 4f14e012a7e6f9139201e5b46547bbda7d706b05 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sun, 14 Nov 2021 10:59:22 +0100 Subject: [PATCH] DEV: Replace `$.extend` with `Object.assign` (#14921) --- app/assets/javascripts/discourse/app/controllers/flag.js | 3 ++- app/assets/javascripts/discourse/app/mixins/upload.js | 5 ++++- app/assets/javascripts/discourse/app/routes/tag-show.js | 2 +- app/assets/javascripts/discourse/app/services/search.js | 2 +- app/assets/javascripts/discourse/app/widgets/header.js | 2 +- .../javascripts/discourse/tests/helpers/qunit-helpers.js | 6 +++++- app/assets/javascripts/discourse/tests/setup-tests.js | 2 +- plugins/lazy-yt/assets/javascripts/lib/lazyYT.js | 4 ++-- .../assets/javascripts/discourse/lib/dummy-data.js | 2 +- 9 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/flag.js b/app/assets/javascripts/discourse/app/controllers/flag.js index e221f5edc9f..042bea17de1 100644 --- a/app/assets/javascripts/discourse/app/controllers/flag.js +++ b/app/assets/javascripts/discourse/app/controllers/flag.js @@ -258,8 +258,9 @@ export default Controller.extend(ModalFunctionality, { let params = this.get("selected.is_custom_flag") ? { message: this.message } : {}; + if (opts) { - params = $.extend(params, opts); + params = Object.assign(params, opts); } this.appEvents.trigger( diff --git a/app/assets/javascripts/discourse/app/mixins/upload.js b/app/assets/javascripts/discourse/app/mixins/upload.js index ff7a73be570..5647471e66f 100644 --- a/app/assets/javascripts/discourse/app/mixins/upload.js +++ b/app/assets/javascripts/discourse/app/mixins/upload.js @@ -94,11 +94,14 @@ export default Mixin.create({ const isValid = validateUploadedFiles(data.files, opts); const type = this.type; let form = type ? { type } : {}; + if (this.data) { - form = $.extend(form, this.data); + form = Object.assign(form, this.data); } + data.formData = form; this.setProperties({ uploadProgress: 0, uploading: isValid }); + return isValid; }); diff --git a/app/assets/javascripts/discourse/app/routes/tag-show.js b/app/assets/javascripts/discourse/app/routes/tag-show.js index bd597a9e01b..bc5c59f58f1 100644 --- a/app/assets/javascripts/discourse/app/routes/tag-show.js +++ b/app/assets/javascripts/discourse/app/routes/tag-show.js @@ -220,7 +220,7 @@ export default DiscourseRoute.extend(FilterModeMixin, { const categoryId = controller.get("category.id"); if (categoryId) { - options = $.extend({}, options, { + options = Object.assign({}, options, { categoryId, includeSubcategories: !controller.noSubcategories, }); diff --git a/app/assets/javascripts/discourse/app/services/search.js b/app/assets/javascripts/discourse/app/services/search.js index 7546dd1ded5..a702e9980b2 100644 --- a/app/assets/javascripts/discourse/app/services/search.js +++ b/app/assets/javascripts/discourse/app/services/search.js @@ -15,7 +15,7 @@ export default EmberObject.extend({ }, set(value, searchContext) { // a bit hacky, consider cleaning this up, need to work through all observers though - const context = $.extend({}, searchContext); + const context = Object.assign({}, searchContext); context.type = value; this.set("searchContext", context); return this.get("searchContext.type"); diff --git a/app/assets/javascripts/discourse/app/widgets/header.js b/app/assets/javascripts/discourse/app/widgets/header.js index 68aab4d7c71..9cfd4091f67 100644 --- a/app/assets/javascripts/discourse/app/widgets/header.js +++ b/app/assets/javascripts/discourse/app/widgets/header.js @@ -402,7 +402,7 @@ export default createWidget("header", { let contentsAttrs = { contents, minimized: !!attrs.topic }; return h( "div.wrap", - this.attach("header-contents", $.extend({}, attrs, contentsAttrs)) + this.attach("header-contents", Object.assign({}, attrs, contentsAttrs)) ); }, diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js index 1ac8ebdd643..92e08149a95 100644 --- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js +++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js @@ -97,7 +97,11 @@ export function withFrozenTime(timeString, timezone, callback) { let _pretenderCallbacks = {}; export function resetSite(siteSettings, extras) { - let siteAttrs = $.extend({}, siteFixtures["site.json"].site, extras || {}); + let siteAttrs = Object.assign( + {}, + siteFixtures["site.json"].site, + extras || {} + ); siteAttrs.store = createStore(); siteAttrs.siteSettings = siteSettings; return Site.resetCurrent(Site.create(siteAttrs)); diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 32d909e9f9a..0731959f176 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -42,7 +42,7 @@ function AcceptanceModal(option, _relatedTarget) { return this.each(function () { let $this = $(this); let data = $this.data("bs.modal"); - let options = $.extend( + let options = Object.assign( {}, Modal.DEFAULTS, $this.data(), diff --git a/plugins/lazy-yt/assets/javascripts/lib/lazyYT.js b/plugins/lazy-yt/assets/javascripts/lib/lazyYT.js index b6f3ddf669f..643bfc7ade7 100644 --- a/plugins/lazy-yt/assets/javascripts/lib/lazyYT.js +++ b/plugins/lazy-yt/assets/javascripts/lib/lazyYT.js @@ -162,10 +162,10 @@ export default function initLazyYt($) { $.fn.lazyYT = function (newSettings) { let defaultSettings = { default_ratio: "16:9", - callback: null, // ToDO execute callback if given + callback: null, // TODO: execute callback if given container_class: "lazyYT-container", }; - let settings = $.extend(defaultSettings, newSettings); + let settings = Object.assign(defaultSettings, newSettings); return this.each(function () { let $el = $(this).addClass(settings.container_class); diff --git a/plugins/styleguide/assets/javascripts/discourse/lib/dummy-data.js b/plugins/styleguide/assets/javascripts/discourse/lib/dummy-data.js index 0e01c5fc44b..df2f90450e9 100644 --- a/plugins/styleguide/assets/javascripts/discourse/lib/dummy-data.js +++ b/plugins/styleguide/assets/javascripts/discourse/lib/dummy-data.js @@ -89,7 +89,7 @@ export function createData(store) { topicId++; return store.createRecord( "topic", - $.extend( + Object.assign( { id: topicId, title: `Example Topic Title ${topicId}`,