DEV: removes _.include from codebase (#6620)

DEV: removes _.include from codebase (#6620)

From 4c8cfe0f29b5d1827823c964bced2697b05eacfb Mon Sep 17 00:00:00 2001
From: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Date: Mon, 19 Nov 2018 12:08:54 +0100
Subject: [PATCH] DEV: removes _.include from codebase (#6620)


diff --git a/app/assets/javascripts/admin/controllers/admin-badges-show.js.es6 b/app/assets/javascripts/admin/controllers/admin-badges-show.js.es6
index c0d58e3..cdb5337 100644
--- a/app/assets/javascripts/admin/controllers/admin-badges-show.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-badges-show.js.es6
@@ -54,10 +54,8 @@ export default Ember.Controller.extend(BufferedContent, {
         ];
 
         if (this.get("buffered.system")) {
-          var protectedFields = this.get("protectedSystemFields");
-          fields = _.filter(fields, function(f) {
-            return !_.include(protectedFields, f);
-          });
+          var protectedFields = this.get("protectedSystemFields") || [];
+          fields = _.filter(fields, f => protectedFields.includes(f));
         }
 
         this.set("saving", true);
@@ -77,7 +75,7 @@ export default Ember.Controller.extend(BufferedContent, {
         const buffered = this.get("buffered");
         fields.forEach(function(field) {
           var d = buffered.get(field);
-          if (_.include(boolFields, field)) {
+          if (boolFields.includes(field)) {
             d = !!d;
           }
           data[field] = d;
diff --git a/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6 b/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6
index 2ca0ad8..b72cdae 100644
--- a/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6
@@ -25,10 +25,7 @@ export default Ember.Controller.extend(GrantBadgeController, {
           lastGranted < badge.granted_at ? badge.granted_at : lastGranted;
       });
 
-      if (
-        badges.length === 1 ||
-        _.include(expandedBadges, badges[0].badge.id)
-      ) {
+      if (badges.length === 1 || expandedBadges.includes(badges[0].badge.id)) {
         _.each(badges, badge => expanded.push(badge));
         return;
       }
diff --git a/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6 b/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6
index 55ea376..1e0e0ec 100644
--- a/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6
+++ b/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6
@@ -45,7 +45,10 @@ const TopicTrackingState = Discourse.Model.extend({
         const muted_category_ids = Discourse.User.currentProp(
           "muted_category_ids"
         );
-        if (_.include(muted_category_ids, data.payload.category_id)) {
+        if (
+          muted_category_ids &&
+          muted_category_ids.includes(data.payload.category_id)
+        ) {
           return;
         }
       }
@@ -145,7 +148,8 @@ const TopicTrackingState = Discourse.Model.extend({
         "suppressed_from_latest_category_ids"
       );
       if (
-        _.include(suppressed_from_latest_category_ids, data.payload.category_id)
+        suppressed_from_latest_category_ids &&
+        suppressed_from_latest_category_ids.includes(data.payload.category_id)
       ) {
         return;
       }

GitHub

1 Like

I hope this lands soon :blush:

1 Like

Yes me too, in the end today, this is most of the value of lodash over native, it handles all the null object cases for you.

2 Likes