From d0bf0dec6f6c72fb6dd3bccccbabf858c71368a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 14 Apr 2014 15:49:00 +0200 Subject: [PATCH] fnpjs: Action - refactor update*Params --- src/fnpjs/actions.js | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/fnpjs/actions.js b/src/fnpjs/actions.js index 8b002bf..d369ff0 100644 --- a/src/fnpjs/actions.js +++ b/src/fnpjs/actions.js @@ -19,14 +19,14 @@ _.extend(Action.prototype, Backbone.Events, { getPluginName: function() { return this.fqName.split('.')[0]; }, - updateContextParam: function(contextName, value) { + updateParam: function(filter, value) { var changed = false; _.pairs(this.definition.params).forEach(function(pair) { var paramName = pair[0], paramDesc = pair[1]; - if(paramDesc.type === 'context' && paramDesc.name === contextName) { - this.params[paramName] = value; - changed = true; + if(filter(paramDesc, paramName)) { + this.params[paramName] = value; + changed = true; } }.bind(this)); if(changed) { @@ -34,30 +34,20 @@ _.extend(Action.prototype, Backbone.Events, { this.trigger('paramsChanged'); } }, + updateContextParam: function(contextName, value) { + this.updateParam(function(paramDesc) { + return paramDesc.type === 'context' && paramDesc.name === contextName; + }, value); + }, updateKeyParam: function(keyName, toggled) { - var changed = false; - _.pairs(this.definition.params).forEach(function(pair) { - var paramName = pair[0], - paramDesc = pair[1]; - if(paramDesc.type === 'key' && paramDesc.key === keyName) { - this.params[paramName] = toggled; - changed = true; - } - }.bind(this)); - - if(changed) { - this._cache = null; - this.trigger('paramsChanged'); - } + this.updateParam(function(paramDesc) { + return paramDesc.type === 'key' && paramDesc.key === keyName; + }, toggled); }, updateWidgetParam: function(name, value) { - var paramDesc = this.definition.params[name]; - if(paramDesc.type === 'context' || paramDesc.type === 'key') { - throw new Error(''); - } - this.params[name] = value; - this._cache = null; - this.trigger('paramsChanged'); + this.updateParam(function(paramDesc, paramName) { + return !_.contains(['context', 'key'], paramDesc.type) && paramName === name; + }, value); }, getState: function() { var gotState; -- 2.20.1