From 068be0ded4be3275a58a2be0e6bc6d199e7313c0 Mon Sep 17 00:00:00 2001
From: Hermann Blum <hermannsblum@yahoo.de>
Date: Sat, 27 Jan 2018 20:17:17 +0100
Subject: [PATCH] restructuring and linter issues

---
 src/auth.js             |  4 +---
 src/userTool.js         |  3 +--
 src/utils.js            | 19 +++++++++++++++++++
 src/views/elements.js   | 10 +++++-----
 src/views/selectList.js | 22 +---------------------
 5 files changed, 27 insertions(+), 31 deletions(-)
 create mode 100644 src/utils.js

diff --git a/src/auth.js b/src/auth.js
index 31945a5..3a30596 100644
--- a/src/auth.js
+++ b/src/auth.js
@@ -187,9 +187,7 @@ export class ResourceHandler {
   post(item) {
     return new Promise((resolve, reject) => {
       getSession().then((api) => {
-        api.post(this.resource, {
-          data: item,
-        }).then((response) => {
+        api.post(this.resource, item).then((response) => {
           if (response.status >= 400) {
             resetSession();
             reject();
diff --git a/src/userTool.js b/src/userTool.js
index dd29c59..41eeb50 100644
--- a/src/userTool.js
+++ b/src/userTool.js
@@ -72,9 +72,8 @@ class UserView extends ItemView {
         this.groupmemberships.handler.post({
           user: this.data._id,
           group: group._id,
-        }).then((data) => {
+        }).then(() => {
           this.groupmemberships.refresh();
-
         });
       },
     });
diff --git a/src/utils.js b/src/utils.js
new file mode 100644
index 0000000..0844554
--- /dev/null
+++ b/src/utils.js
@@ -0,0 +1,19 @@
+// as taken from underscore:
+// Returns a function, that, as long as it continues to be invoked, will not
+// be triggered. The function will be called after it stops being called for
+// N milliseconds. If `immediate` is passed, trigger the function on the
+// leading edge, instead of the trailing.
+export function debounce(func, wait, immediate) {
+  let timeout;
+  return function outer(...args) {
+    const context = this;
+    function later() {
+      timeout = null;
+      if (!immediate) func.apply(context, args);
+    }
+    const callNow = immediate && !timeout;
+    clearTimeout(timeout);
+    timeout = setTimeout(later, wait);
+    if (callNow) func.apply(context, args);
+  };
+}
diff --git a/src/views/elements.js b/src/views/elements.js
index 90e37c3..83d8805 100644
--- a/src/views/elements.js
+++ b/src/views/elements.js
@@ -43,11 +43,11 @@ export class selectGroup {
 }
 
 export class submitButton {
-  view(vnode) {
-    const args = vnode.attrs.args;
-    if (!vnode.attrs.active) {
-      args.disabled = 'disabled';
+  view({ attrs: { args, active, text } }) {
+    const argsCopy = args;
+    if (!active) {
+      argsCopy.disabled = 'disabled';
     }
-    return m('div.btn', args, vnode.attrs.text);
+    return m('div.btn', argsCopy, text);
   }
 }
diff --git a/src/views/selectList.js b/src/views/selectList.js
index b322a2c..2e7739e 100644
--- a/src/views/selectList.js
+++ b/src/views/selectList.js
@@ -1,28 +1,8 @@
 import { submitButton } from './elements';
+import { debounce } from '../utils';
 
 const m = require('mithril');
 
-// as taken from underscore:
-// Returns a function, that, as long as it continues to be invoked, will not
-// be triggered. The function will be called after it stops being called for
-// N milliseconds. If `immediate` is passed, trigger the function on the
-// leading edge, instead of the trailing.
-function debounce(func, wait, immediate) {
-  let timeout;
-  return function () {
-    const context = this;
-    const args = arguments;
-    const later = function () {
-      timeout = null;
-      if (!immediate) func.apply(context, args);
-    };
-    const callNow = immediate && !timeout;
-    clearTimeout(timeout);
-    timeout = setTimeout(later, wait);
-    if (callNow) func.apply(context, args);
-  };
-}
-
 export default class SelectList {
   constructor() {
     this.selected = null;
-- 
GitLab