From 604ded655964f55c673d2506f2e68827e26cd731 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 13 Dec 2018 14:45:08 +0300 Subject: [PATCH 1/3] correct call static methods --- src/controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controller.js b/src/controller.js index 8c6d421..7444c10 100644 --- a/src/controller.js +++ b/src/controller.js @@ -50,7 +50,7 @@ static registerControls(controls) { for (const name in controls) { if (controls.hasOwnProperty(name)) { - self.registerControl(name, controls[name]); + Controller.registerControl(name, controls[name]); } else { return false; } @@ -90,11 +90,11 @@ let binded = false; if (element.getAttribute('control')) { - binded = self.singleBind(element); + binded = Controller.singleBind(element); } element.querySelectorAll('[data-control]').forEach((control) => { - self.singleBind(control); + Controller.singleBind(control); binded = true; }); From d336b63f9b515e0e46910eb3f2927734e5bc54d3 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 13 Dec 2018 14:53:37 +0300 Subject: [PATCH 2/3] correct get data-control attribute --- src/controller.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/controller.js b/src/controller.js index 7444c10..a81e05e 100644 --- a/src/controller.js +++ b/src/controller.js @@ -65,8 +65,12 @@ * @returns {boolean} */ static singleBind(element) { + if (!element.getAttribute('data-control')) { + return false; + } + // separate the control names by ' ' or ',' - const names = element.getAttribute('control').replace(/[, ]+/g, ' ').split(' '); + const names = element.getAttribute('data-control').replace(/[, ]+/g, ' ').split(' '); let binded = false; // find control by name @@ -88,10 +92,7 @@ static bind(element) { element = element || document.getElementsByTagName('body')[0]; - let binded = false; - if (element.getAttribute('control')) { - binded = Controller.singleBind(element); - } + let binded = Controller.singleBind(element); element.querySelectorAll('[data-control]').forEach((control) => { Controller.singleBind(control); From 1845891e4639152667e5fd6af0e47223ee19fcb3 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 13 Dec 2018 14:58:06 +0300 Subject: [PATCH 3/3] rename vars --- src/controller.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/controller.js b/src/controller.js index a81e05e..6f55430 100644 --- a/src/controller.js +++ b/src/controller.js @@ -23,7 +23,10 @@ } }(this, function () { - const registeredControls = []; + /** + * @type {Object.} + */ + const registry = []; class Controller { /** @@ -34,7 +37,7 @@ */ static registerControl(name, control) { if (typeof control === 'function') { - registeredControls[name] = control; + registry[name] = control; return true; } @@ -70,13 +73,13 @@ } // separate the control names by ' ' or ',' - const names = element.getAttribute('data-control').replace(/[, ]+/g, ' ').split(' '); + const control_names = element.getAttribute('data-control').replace(/[, ]+/g, ' ').split(' '); let binded = false; // find control by name - for (let i = 0; i < names.length; i++) { - if (typeof registeredControls[names[i]] === 'function') { - registeredControls[names[i]](element); + for (let i = 0; i < control_names.length; i++) { + if (typeof registry[control_names[i]] === 'function') { + registry[control_names[i]](element); binded = true; } }