Improve ProxyContext: Use JSON.stringify() for rendering values correctly, and streamline code.

This commit is contained in:
Jürg Lehni 2013-10-16 16:09:11 +02:00
parent d45ba19914
commit fb6ff59218

View file

@ -64,28 +64,27 @@ var ProxyContext = new function() {
isFunction = !!match[2]; isFunction = !!match[2];
if (isFunction) { if (isFunction) {
fields[name] = function() { fields[name] = function() {
if (name == 'restore') { if (name === 'restore')
this._indents--; this._indents--;
} console.log(this.getIndentation() + 'ctx.' + name + '('
var args = Array.prototype.slice.call(arguments, 0).join(', '), + Array.prototype.slice.call(arguments, 0)
string = 'ctx.' + name + '(' + args + ');'; .map(JSON.stringify).join(', ')
console.log(this.getIndentation() + string); + ');');
if (name == 'save') { if (name === 'save')
this._indents++; this._indents++;
}
return this._ctx[name].apply(this._ctx, arguments); return this._ctx[name].apply(this._ctx, arguments);
}; };
} else { } else {
var capitalized = Base.capitalize(name); fields[name] = {
fields['set' + capitalized] = function(value) { get: function() {
var logValue = value && value.substring ? '\'' + value + '\'' : value,
string = 'ctx.' + name + ' = ' + logValue + ';';
console.log(this.getIndentation() + string);
return this._ctx[name] = value;
};
fields['get' + capitalized] = function() {
return this._ctx[name]; return this._ctx[name];
}; },
set: function(value) {
console.log(this.getIndentation() + 'ctx.' + name + ' = '
+ JSON.stringify(value) + ';');
return this._ctx[name] = value;
}
}
} }
}); });
return Base.extend(fields); return Base.extend(fields);