Browse Source

Playing around with removing more lodash calls

JC Brand 6 years ago
parent
commit
969f902d4a
3 changed files with 11 additions and 27 deletions
  1. 1 1
      .eslintrc.json
  2. 4 14
      dist/converse.js
  3. 6 12
      src/converse-rosterview.js

+ 1 - 1
.eslintrc.json

@@ -23,7 +23,7 @@
             "ignoreMethods": [
                 "assign", "every", "keys", "find", "endsWith", "startsWith", "filter",
                 "reduce", "isArray", "create", "map", "replace", "some", "toLower",
-                "split", "trim", "forEach", "toUpperCase", "includes"
+                "split", "trim", "forEach", "toUpperCase", "includes", "values"
             ]
         }],
         "lodash/prefer-invoke-map": "off",

+ 4 - 14
dist/converse.js

@@ -59849,8 +59849,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_4__["default"].plugins
       },
 
       render() {
-        const that = this;
-
         if (!this.mayBeShown()) {
           u.hideElement(this.el);
           return this;
@@ -59861,13 +59859,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_4__["default"].plugins
               requesting = this.model.get('requesting'),
               subscription = this.model.get('subscription');
         const classes_to_remove = ['current-xmpp-contact', 'pending-xmpp-contact', 'requesting-xmpp-contact'].concat(Object.keys(STATUSES));
-
-        _.each(classes_to_remove, function (cls) {
-          if (_.includes(that.el.className, cls)) {
-            that.el.classList.remove(cls);
-          }
-        });
-
+        classes_to_remove.forEach(c => u.removeClass(c, this.el));
         this.el.classList.add(show);
         this.el.setAttribute('data-status', show);
         this.highlight();
@@ -60090,11 +60082,9 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_4__["default"].plugins
       show() {
         u.showElement(this.el);
 
-        _.each(this.getAll(), contact_view => {
-          if (contact_view.mayBeShown() && this.model.get('state') === _converse.OPENED) {
-            u.showElement(contact_view.el);
-          }
-        });
+        if (this.model.get('state') === _converse.OPENED) {
+          Object.values(this.getAll()).filter(v => v.mayBeShown()).forEach(v => u.showElement(v.el));
+        }
 
         return this;
       },

+ 6 - 12
src/converse-rosterview.js

@@ -402,7 +402,6 @@ converse.plugins.add('converse-rosterview', {
             },
 
             render () {
-                const that = this;
                 if (!this.mayBeShown()) {
                     u.hideElement(this.el);
                     return this;
@@ -417,13 +416,8 @@ converse.plugins.add('converse-rosterview', {
                     'pending-xmpp-contact',
                     'requesting-xmpp-contact'
                     ].concat(Object.keys(STATUSES));
+                classes_to_remove.forEach(c => u.removeClass(c, this.el));
 
-                _.each(classes_to_remove,
-                    function (cls) {
-                        if (_.includes(that.el.className, cls)) {
-                            that.el.classList.remove(cls);
-                        }
-                    });
                 this.el.classList.add(show);
                 this.el.setAttribute('data-status', show);
                 this.highlight();
@@ -634,11 +628,11 @@ converse.plugins.add('converse-rosterview', {
 
             show () {
                 u.showElement(this.el);
-                _.each(this.getAll(), (contact_view) => {
-                    if (contact_view.mayBeShown() && this.model.get('state') === _converse.OPENED) {
-                        u.showElement(contact_view.el);
-                    }
-                });
+                if (this.model.get('state') === _converse.OPENED) {
+                    Object.values(this.getAll())
+                        .filter(v => v.mayBeShown())
+                        .forEach(v => u.showElement(v.el));
+                }
                 return this;
             },