From 7ac96114a5dece75e9a150bbb6f7c82c3eb77168 Mon Sep 17 00:00:00 2001 From: Tobias Moebert <moebert@uni-potsdam.de> Date: Wed, 18 Mar 2015 15:13:24 +0100 Subject: [PATCH] # code cleanup # better support for interpreters --- dist/contactJS.js | 72 ++++++++++++++------------- js/modules/abstractList.js | 19 +++---- js/modules/aggregator/aggregator.js | 13 ++++- js/modules/interpreter/interpreter.js | 4 +- js/modules/widget/widgetHandleList.js | 36 +++++++------- qunitTest/widgetHandleListTest.js | 2 +- 6 files changed, 77 insertions(+), 69 deletions(-) diff --git a/dist/contactJS.js b/dist/contactJS.js index 99f43bf..763f6df 100644 --- a/dist/contactJS.js +++ b/dist/contactJS.js @@ -524,7 +524,7 @@ define('abstractList',[ 'easejs' ], function(easejs) { /** * @alias counter * @protected - * @type {integer} + * @type {int} * @memberof AbstractList# * @desc Number of Items. */ @@ -607,10 +607,7 @@ define('abstractList',[ 'easejs' ], function(easejs) { * @returns {boolean} */ 'public containsKey' : function(_key) { - if (typeof _key !== 'undefined' && typeof this.items[_key] !== 'undefined') { - return true; - } - return false; + return !!(typeof _key !== 'undefined' && typeof this.items[_key] !== 'undefined'); }, /** @@ -636,7 +633,7 @@ define('abstractList',[ 'easejs' ], function(easejs) { if (this.containsKey(_key)) { delete this.items[_key]; this.counter--; - }; + } }, /** @@ -676,7 +673,7 @@ define('abstractList',[ 'easejs' ], function(easejs) { * @public * @alias size * @memberof AbstractList# - * @returns {integer} + * @returns {int} */ 'public size' : function() { return this.counter; @@ -690,11 +687,7 @@ define('abstractList',[ 'easejs' ], function(easejs) { * @returns {boolean} */ 'public isEmpty' : function() { - if (this.counter == 0) { - return true; - } else { - return false; - } + return this.counter == 0; }, /** @@ -704,7 +697,7 @@ define('abstractList',[ 'easejs' ], function(easejs) { * @memberof AbstractList# */ 'public clear' : function() { - this.items = new Array(); + this.items = []; this.counter = 0; } @@ -4930,41 +4923,41 @@ define('widgetHandleList',[ 'easejs', 'abstractList', 'widgetHandle', 'widget'], * @requires WidgetHandle */ var WidgetHandleList = Class('WidgetHandleList').extend(AbstractList,{ - /** - * @alias counter - * @protected - * @type {integer} - * @memberof WidgetHandleList# - * @desc Number of items. - */ - 'protected counter' : 0, + + /** + * @alias counter + * @protected + * @type {int} + * @memberof AbstractList# + * @desc Number of Items. + */ + 'protected counter' : 0, /** * @alias items * @protected - * @type {WidgetHandleList} + * @type {Array} * @memberof WidgetHandleList# * @desc ItemList. */ 'protected items' : [], - + /** * Builder for item list. * * @public * @alias withItems * @memberof WidgetHandleList# - * @param {(WidgetHandleList|Array)} - * _widgetHandleList WidgetHandleList + * @param {WidgetHandleList|Array} _widgetHandleListOrArray WidgetHandleList * @returns {WidgetHandleList} */ - 'public withItems' : function(_widgetHandleList) { + 'public withItems' : function(_widgetHandleListOrArray) { var list = []; - if (_widgetHandleList instanceof Array) { - list = _widgetHandleList; - } else if (Class.isA(WidgetHandleList, _widgetHandleList)) { - list = _widgetHandleList.getItems(); + if (_widgetHandleListOrArray instanceof Array) { + list = _widgetHandleListOrArray; + } else if (Class.isA(WidgetHandleList, _widgetHandleListOrArray)) { + list = _widgetHandleListOrArray.getItems(); } - for ( var i in list) { + for (var i in list) { var widgetHandle = list[i]; if (Class.isA(WidgetHandle, widgetHandle)) { this.items[widgetHandle.getName()] = widgetHandle; @@ -5110,7 +5103,9 @@ define('aggregator',['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandl * @desc List of subscribed Widgets. */ 'protected widgets' : [], - + + 'protected interpreters' : [], + /** * @alias db * @protected @@ -5146,6 +5141,7 @@ define('aggregator',['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandl this.id = Math.uuid(); this.widgets = new WidgetHandleList(); this.initWidgetHandles(); + this.interpreters = []; this.__super(_discoverer); this.aggregatorSetup(); }, @@ -5663,6 +5659,14 @@ define('aggregator',['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandl } }); } + }, + + 'public addInterpreter': function(_theInterpreter) { + this.interpreters.push(_theInterpreter.getId()); + }, + + 'public getInterpreters': function() { + return this.interpreters; } }); @@ -6348,7 +6352,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList for ( var i in list) { this.setOutAttribute(list[i].getName(), list[i].getType(), 'unavailable'); } - + _function(); } }, @@ -6461,7 +6465,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList this.discoverer.registerNewComponent(this); } - }, + } // /** // * Unregisters the component to the associated discoverer diff --git a/js/modules/abstractList.js b/js/modules/abstractList.js index 7bc9d07..2eb9739 100644 --- a/js/modules/abstractList.js +++ b/js/modules/abstractList.js @@ -17,7 +17,7 @@ define([ 'easejs' ], function(easejs) { /** * @alias counter * @protected - * @type {integer} + * @type {int} * @memberof AbstractList# * @desc Number of Items. */ @@ -100,10 +100,7 @@ define([ 'easejs' ], function(easejs) { * @returns {boolean} */ 'public containsKey' : function(_key) { - if (typeof _key !== 'undefined' && typeof this.items[_key] !== 'undefined') { - return true; - } - return false; + return !!(typeof _key !== 'undefined' && typeof this.items[_key] !== 'undefined'); }, /** @@ -129,7 +126,7 @@ define([ 'easejs' ], function(easejs) { if (this.containsKey(_key)) { delete this.items[_key]; this.counter--; - }; + } }, /** @@ -169,7 +166,7 @@ define([ 'easejs' ], function(easejs) { * @public * @alias size * @memberof AbstractList# - * @returns {integer} + * @returns {int} */ 'public size' : function() { return this.counter; @@ -183,11 +180,7 @@ define([ 'easejs' ], function(easejs) { * @returns {boolean} */ 'public isEmpty' : function() { - if (this.counter == 0) { - return true; - } else { - return false; - } + return this.counter == 0; }, /** @@ -197,7 +190,7 @@ define([ 'easejs' ], function(easejs) { * @memberof AbstractList# */ 'public clear' : function() { - this.items = new Array(); + this.items = []; this.counter = 0; } diff --git a/js/modules/aggregator/aggregator.js b/js/modules/aggregator/aggregator.js index 11fcce2..2b66cb0 100644 --- a/js/modules/aggregator/aggregator.js +++ b/js/modules/aggregator/aggregator.js @@ -44,7 +44,9 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', * @desc List of subscribed Widgets. */ 'protected widgets' : [], - + + 'protected interpreters' : [], + /** * @alias db * @protected @@ -80,6 +82,7 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', this.id = Math.uuid(); this.widgets = new WidgetHandleList(); this.initWidgetHandles(); + this.interpreters = []; this.__super(_discoverer); this.aggregatorSetup(); }, @@ -597,6 +600,14 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', } }); } + }, + + 'public addInterpreter': function(_theInterpreter) { + this.interpreters.push(_theInterpreter.getId()); + }, + + 'public getInterpreters': function() { + return this.interpreters; } }); diff --git a/js/modules/interpreter/interpreter.js b/js/modules/interpreter/interpreter.js index 8e7f950..ee0716c 100644 --- a/js/modules/interpreter/interpreter.js +++ b/js/modules/interpreter/interpreter.js @@ -305,7 +305,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', for ( var i in list) { this.setOutAttribute(list[i].getName(), list[i].getType(), 'unavailable'); } - + _function(); } }, @@ -418,7 +418,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', this.discoverer.registerNewComponent(this); } - }, + } // /** // * Unregisters the component to the associated discoverer diff --git a/js/modules/widget/widgetHandleList.js b/js/modules/widget/widgetHandleList.js index f575e2a..700b02d 100644 --- a/js/modules/widget/widgetHandleList.js +++ b/js/modules/widget/widgetHandleList.js @@ -17,41 +17,41 @@ define([ 'easejs', 'abstractList', 'widgetHandle', 'widget'], * @requires WidgetHandle */ var WidgetHandleList = Class('WidgetHandleList').extend(AbstractList,{ - /** - * @alias counter - * @protected - * @type {integer} - * @memberof WidgetHandleList# - * @desc Number of items. - */ - 'protected counter' : 0, + + /** + * @alias counter + * @protected + * @type {int} + * @memberof AbstractList# + * @desc Number of Items. + */ + 'protected counter' : 0, /** * @alias items * @protected - * @type {WidgetHandleList} + * @type {Array} * @memberof WidgetHandleList# * @desc ItemList. */ 'protected items' : [], - + /** * Builder for item list. * * @public * @alias withItems * @memberof WidgetHandleList# - * @param {(WidgetHandleList|Array)} - * _widgetHandleList WidgetHandleList + * @param {WidgetHandleList|Array} _widgetHandleListOrArray WidgetHandleList * @returns {WidgetHandleList} */ - 'public withItems' : function(_widgetHandleList) { + 'public withItems' : function(_widgetHandleListOrArray) { var list = []; - if (_widgetHandleList instanceof Array) { - list = _widgetHandleList; - } else if (Class.isA(WidgetHandleList, _widgetHandleList)) { - list = _widgetHandleList.getItems(); + if (_widgetHandleListOrArray instanceof Array) { + list = _widgetHandleListOrArray; + } else if (Class.isA(WidgetHandleList, _widgetHandleListOrArray)) { + list = _widgetHandleListOrArray.getItems(); } - for ( var i in list) { + for (var i in list) { var widgetHandle = list[i]; if (Class.isA(WidgetHandle, widgetHandle)) { this.items[widgetHandle.getName()] = widgetHandle; diff --git a/qunitTest/widgetHandleListTest.js b/qunitTest/widgetHandleListTest.js index b88c023..3014dc6 100644 --- a/qunitTest/widgetHandleListTest.js +++ b/qunitTest/widgetHandleListTest.js @@ -8,7 +8,7 @@ require(['configTest'], function() { var geoWidget = new GeoLocationWidget(new contactJS.Discoverer()); - var array = new Array(); + var array = []; array.push(widgetHandle2); array.push(widgetHandle3); var list = new contactJS.WidgetHandleList().withItems(array); -- GitLab