From 55c9c54b8baa219afba9f038f413125f19d019bc Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 31 Aug 2020 16:34:14 -0400 Subject: [PATCH] REFACTOR: Remove `_.range` and use ES6 instead --- .../javascripts/discourse/app/models/composer.js | 1 - .../discourse/app/models/post-stream.js | 4 +++- .../controllers/poll-ui-builder.js.es6 | 9 +++++---- test/javascripts/helpers/create-pretender.js | 16 +++++++--------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js index 41fca8f26c8..f1913b0c411 100644 --- a/app/assets/javascripts/discourse/app/models/composer.js +++ b/app/assets/javascripts/discourse/app/models/composer.js @@ -23,7 +23,6 @@ import Site from "discourse/models/site"; import User from "discourse/models/user"; import deprecated from "discourse-common/lib/deprecated"; import bootbox from "bootbox"; -import { isEmpty } from "@ember/utils"; // The actions the composer can take export const CREATE_TOPIC = "createTopic", diff --git a/app/assets/javascripts/discourse/app/models/post-stream.js b/app/assets/javascripts/discourse/app/models/post-stream.js index c9b35f3dccb..c36cf9ac1fb 100644 --- a/app/assets/javascripts/discourse/app/models/post-stream.js +++ b/app/assets/javascripts/discourse/app/models/post-stream.js @@ -362,7 +362,9 @@ export default RestModel.extend({ if (this.isMegaTopic) { this.set("loadingBelow", true); - const fakePostIds = _.range(-1, -this.get("topic.chunk_size"), -1); + const fakePostIds = [ + ...Array(this.get("topic.chunk_size") - 1).keys() + ].map(i => -i - 1); postsWithPlaceholders.appending(fakePostIds); return this.fetchNextWindow( diff --git a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 index 2c0c4ff36e0..7c2c9e11180 100644 --- a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 +++ b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 @@ -334,10 +334,11 @@ export default Controller.extend({ return EmberObject.create(options); }, - _comboboxOptions(start_index, end_index) { - return _.range(start_index, end_index).map(number => { - return { value: number, name: number }; - }); + _comboboxOptions(startIndex, endIndex) { + return [...Array(endIndex - startIndex).keys()].map(number => ({ + value: number + startIndex, + name: number + startIndex + })); }, _setupPoll() { diff --git a/test/javascripts/helpers/create-pretender.js b/test/javascripts/helpers/create-pretender.js index 1ed9e4c4b05..3b648b5b912 100644 --- a/test/javascripts/helpers/create-pretender.js +++ b/test/javascripts/helpers/create-pretender.js @@ -521,17 +521,15 @@ export function applyDefaultHandlers(pretender) { post_number: parseInt(p, 10) })); } else if (postNumber && request.queryParams.asc === "true") { - posts = _.range(postNumber + 1, postNumber + 6).map(p => ({ - id: parseInt(p, 10), - post_number: parseInt(p, 10) + posts = [...Array(5).keys()].map(p => ({ + id: p + postNumber + 1, + post_number: p + postNumber + 1 })); } else if (postNumber && request.queryParams.asc === "false") { - posts = _.range(postNumber - 5, postNumber) - .reverse() - .map(p => ({ - id: parseInt(p, 10), - post_number: parseInt(p, 10) - })); + posts = [...Array(5).keys()].map(p => ({ + id: postNumber - p - 1, + post_number: postNumber - p - 1 + })); } return response(200, { post_stream: { posts } });