Skip to content

A platform for community discussion. Free, open, simple.

REFACTOR: Remove `_.first` from codebase

Robin Ward66021abe41ca
diff --git a/app/assets/javascripts/discourse/app/lib/theme-selector.js b/app/assets/javascripts/discourse/app/lib/theme-selector.js
index 82d838fd766..4768616e1da 100644
--- a/app/assets/javascripts/discourse/app/lib/theme-selector.js
+++ b/app/assets/javascripts/discourse/app/lib/theme-selector.js
@@ -16,7 +16,7 @@ export function currentThemeKey() {
export function currentThemeIds() {
const themeIds = [];
- const elem = _.first($(keySelector));
+ const elem = $(keySelector)[0];
if (elem) {
elem.content.split(",").forEach(num => {
num = parseInt(num, 10);
diff --git a/app/assets/javascripts/discourse/app/models/post-stream.js b/app/assets/javascripts/discourse/app/models/post-stream.js
index c36cf9ac1fb..4a9a2458854 100644
--- a/app/assets/javascripts/discourse/app/models/post-stream.js
+++ b/app/assets/javascripts/discourse/app/models/post-stream.js
@@ -145,8 +145,12 @@ export default RestModel.extend({
**/
@discourseComputed("posts.[]", "stream.[]")
previousWindow() {
+ if (!this.posts) {
+ return [];
+ }
+
// If we can't find the last post loaded, bail
- const firstPost = _.first(this.posts);
+ const firstPost = this.posts[0];
if (!firstPost) {
return [];
}
diff --git a/app/assets/javascripts/discourse/app/routes/user-private-messages-group-archive.js b/app/assets/javascripts/discourse/app/routes/user-private-messages-group-archive.js
index 74ad2f5d14f..5d84562d909 100644
--- a/app/assets/javascripts/discourse/app/routes/user-private-messages-group-archive.js
+++ b/app/assets/javascripts/discourse/app/routes/user-private-messages-group-archive.js
@@ -29,8 +29,9 @@ export default createPMRoute("groups", "private-messages-groups").extend({
const split = model.get("filter").split("/");
const groupName = split[split.length - 2];
this.set("groupName", groupName);
- const groups = this.modelFor("user").get("groups");
- const group = _.first(groups.filterBy("name", groupName));
+ const group = this.modelFor("user")
+ .get("groups")
+ .filterBy("name", groupName)[0];
this.controllerFor("user-private-messages").set("group", group);
},
diff --git a/app/assets/javascripts/discourse/app/routes/user-private-messages-group.js b/app/assets/javascripts/discourse/app/routes/user-private-messages-group.js
index f3e606ae96e..f4e9b6fe078 100644
--- a/app/assets/javascripts/discourse/app/routes/user-private-messages-group.js
+++ b/app/assets/javascripts/discourse/app/routes/user-private-messages-group.js
@@ -23,8 +23,9 @@ export default createPMRoute("groups", "private-messages-groups").extend({
afterModel(model) {
const groupName = _.last(model.get("filter").split("/"));
this.set("groupName", groupName);
- const groups = this.modelFor("user").get("groups");
- const group = _.first(groups.filterBy("name", groupName));
+ const group = this.modelFor("user")
+ .get("groups")
+ .filterBy("name", groupName)[0];
this.controllerFor("user-private-messages").set("group", group);
},
diff --git a/test/javascripts/helpers/qunit-helpers.js b/test/javascripts/helpers/qunit-helpers.js
index 1b1446afb0c..e640473af2c 100644
--- a/test/javascripts/helpers/qunit-helpers.js
+++ b/test/javascripts/helpers/qunit-helpers.js
@@ -267,7 +267,7 @@ QUnit.assert.present = function(actual, message) {
};
QUnit.assert.containsInstance = function(collection, klass, message) {
- const result = klass.detectInstance(_.first(collection));
+ const result = klass.detectInstance(collection[0]);
this.pushResult({
result,
message