Skip to content

Commit

Permalink
Merge pull request #233 from dcleao/master
Browse files Browse the repository at this point in the history
[CLEANUP] Unintended global variables.
  • Loading branch information
pamval committed Aug 7, 2015
2 parents 1e13078 + b8e4a16 commit 2005743
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 61 deletions.
116 changes: 58 additions & 58 deletions package-res/ccc/core/base/optionsMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
/**
* Creates an options manager given an options specification object,
* and, optionally, a corresponding context object.
*
*
* @name pvc.options
* @class An options manager.
* @example
* <pre>
* var foo = {};
*
*
* foo.options = pvc.options({
* Name: {
* cast: String,
Expand All @@ -23,73 +23,73 @@
* }
* }
* }, foo);
*
*
* foo.options.specify({
* 'Name': "Fritz"
* });
*
*
* foo.options('Name2'); // -> "Fritz"
* </pre>
*
*
* @constructor
* @param {object} specs An object whose properties, owned or inherited,
* have the name of an option to define, and whose values are option
* specification objects, each having the following <i>optional</i> properties:
* <ul>
* <li>resolve -
* <li>resolve -
* a method that allows to apply custom value resolution logic for an option.
*
* It is called
* on the {@link pvc.options.Info} instance with the
* previously specified context object as argument.
*
* It is called
* on the {@link pvc.options.Info} instance with the
* previously specified context object as argument.
* </li>
* <li>cast - a cast function, called to normalize the value of an option</li>
* <li>value - the default value of the property, considered already cast</li>
* </li>
* </ul>
*
*
* @param {object} [context=null] Optional context object on which to call
* the 'resolve' function specified in {@link specs}.
*
*
* @type function
*/
function pvc_options(specs, context) {
/*jshint expr:true */
specs || def.fail.argumentRequired('specs');

var _infos = {};

def.each(specs, function(spec, name) {
var info = new pvc_OptionInfo(name, option, context, spec);
_infos[info.name] = info;
});

/** @private */
function resolve(name) {
// Throws if option does not exist. But it's as is because of perf. reasons.
return _infos[name].resolve();
}

/**
* Obtains the value of an option given its name.
* <p>
* If a value for the option hasn't been provided
* a default value is returned,
* a default value is returned,
* from the option specification.
* </p>
* @name pvc.options#option
* @function
* @param {string} name The name of the option.
* @param {booleam} [noDefault=false] Prevents returning a default value.
* If a value for the option hasn't been provided, undefined is returned.
*
*
* @type any
*/
function option(name, noDefault) {
var info = resolve(name);
return noDefault && !info.isSpecified ? undefined : info.value;
}

/**
* Indicates if a value for a given option has been specified.
* @name pvc.options#isSpecified
Expand All @@ -98,23 +98,23 @@ function pvc_options(specs, context) {
* @type boolean
*/
function isSpecified(name) { return resolve(name).isSpecified; }

/**
* Obtains the value of an option given its name,
* but only if it has been specified (not defaulted).
* <p>
* This is a convenience method for calling {@link #option}
* with the <tt>noDefault</tt> argument with the value <tt>true</tt>.
* </p>
*
*
* @name pvc.options#specified
* @function
* @param {string} name The name of the option.
*
*
* @type any
*/
function specified(name) { return option(name, /*noDefault*/true); }

/**
* Indicates if an option with the given name is defined.
* @name pvc.options#isDefined
Expand All @@ -123,26 +123,26 @@ function pvc_options(specs, context) {
* @type boolean
*/
function isDefined(name) { return def.hasOwn(_infos, name); }

/**
* Specifies options' values given an object
* with properties as option names
* and values as option values.
* <p>
* Only properties whose name is the name of a defined option
* Only properties whose name is the name of a defined option
* are taken into account.
* </p>
* <p>
* Every property, own or inherited, is considered,
* Every property, own or inherited, is considered,
* as long as its value is not <c>undefined</c>.
* </p>
* @name pvc.options#specify
* @function
* @param {object} [opts] An object with option values
* @returns {function} The options manager.
* @returns {function} The options manager.
*/
function specify(opts) { return set(opts, false); }

/**
* Sets options' default values.
* @name pvc.options#defaults
Expand All @@ -152,7 +152,7 @@ function pvc_options(specs, context) {
* @see #specify
*/
function defaults(opts) { return set(opts, true); }

/**
* Obtains the default value of an option, given its name.
* <p>
Expand All @@ -163,7 +163,7 @@ function pvc_options(specs, context) {
* @param {string} name The name of the option.
*/
function getDefaultValue(name) { return resolve(name)._dv; }

/** @private */
function set(opts, isDefault) {
var name, info, value;
Expand All @@ -173,9 +173,9 @@ function pvc_options(specs, context) {
}
return option;
}

// ------------

option.option = option;
option.specified = specified;
option.defaultValue = getDefaultValue;
Expand All @@ -185,19 +185,19 @@ function pvc_options(specs, context) {

option.specify = specify;
option.defaults = defaults;

return option;
}

// ------------
// Creates a resolve method,
// that combines a list of resolvers.

// Creates a resolve method,
// that combines a list of resolvers.
// The resolve stops when the first resolver returns the value <c>true</c>,
// returning <c>true</c> as well.
function options_resolvers(list) {
return function(optionInfo) {
var i, m;
var i, m, L;
for(i = 0, L = list.length ; i < L ; i++) {
m = list[i];
if(typeof m === 'string') m = this[m];
Expand Down Expand Up @@ -242,26 +242,26 @@ pvc.options = pvc_options;
* @class An option in an options manager.
* @private
*/
var pvc_OptionInfo =
var pvc_OptionInfo =
def.type() // Anonymous type
.init(function(name, option, context, spec) {
this.name = name;
this.option = option;

// Assumed already cast.
this._dv = this.value = def.get(spec, 'value');

this._resolve = def.get(spec, 'resolve'); // function or string
var resolved = !this._resolve;

this.isResolved = resolved;
this.isSpecified = false;
this._setCalled = false;
this._context = context;
this._cast = def.get(spec, 'cast');

this._getDefault = resolved ? null : def.get(spec, 'getDefault'); // function or string

this.data = def.get(spec, 'data');
})
.add(/** @lends pvc.options.OptionInfo# */{
Expand All @@ -273,13 +273,13 @@ def.type() // Anonymous type
if(!this.isResolved) {
// In case of re-entry, the initial default value is obtained.
this.isResolved = true;

// Must call 'set', 'specify' or 'defaultValue'
// Otherwise, the current default value becomes _the_ value.
this._setCalled = false;

this._getFunProp('_resolve').call(this._context, this);

// Handle the case where none of the above referred methods is called.
if(!this._setCalled) {
this.isSpecified = false;
Expand All @@ -288,18 +288,18 @@ def.type() // Anonymous type
// else maintain existing default value
}
}

return this;
},

/**
* Specifies the value of the option.
*
*
* @param {any} value the option value.
* @type pvc.options.Info
*/
specify: function(value) { return this.set(value, false); },

/**
* Gets, and optionally sets, the default value.
* @param {any} [defaultValue=undefined] the option default value.
Expand All @@ -309,43 +309,43 @@ def.type() // Anonymous type
if(arguments.length) this.set(defaultValue, true);
return this._dv;
},

cast: function(value) {
if(value != null) {
var cast = this._getFunProp('_cast');
if(cast) {
if(cast) {
value = cast.call(this._context, value);
// TODO: should log cast error when == null?
// Or is that the responsibility of the cast function?
}
}
return value;
},

/**
* Sets the option's value or default value.
*
*
* @param {any} [value=undefined] the option value or default value.
* @param {boolean} [isDefault=false] indicates if the operation sets the default value.
*
*
* @type pvc.options.Info
*/
set: function(value, isDefault) {

this._setCalled = true;

if(value != null) value = this.cast(value);

if(value == null) {
value = this._dynDefault();
// If null, maintain current default.
if(value == null) {
if(value == null) {
if(!this.isSpecified) return this;
value = this._dv;
}
isDefault = true;
}

if(isDefault) {
this._dv = value;
// Don't touch an already specified value
Expand All @@ -356,7 +356,7 @@ def.type() // Anonymous type
}
return this;
},

_dynDefault: function() {
var get = this._getFunProp('_getDefault');
return get && this.cast(get.call(this._context, this));
Expand All @@ -367,4 +367,4 @@ def.type() // Anonymous type
if(fun && (ctx = this._context) && def.string.is(fun)) fun = ctx[fun];
return fun;
}
});
});
4 changes: 2 additions & 2 deletions package-res/cdo/oper/linear-interp-oper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def
this._isCatDiscrete = catRole.grouping.isDiscrete();
this._stretchEnds = stretchEnds;
this._catInfos = qAllCatDatas.select(function(allCatData, catIndex) {
var catData = visibleData.child(allCatData.key);
var catData = visibleData.child(allCatData.key),
catInfo = {
data: catData || allCatData, // may be null?
value: allCatData.value,
Expand Down Expand Up @@ -82,4 +82,4 @@ def
if(!catSerInfo.isNull) return catSerInfo;
}
}
});
});
Loading

0 comments on commit 2005743

Please sign in to comment.