mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Improve ProxyContext: Use JSON.stringify() for rendering values correctly, and streamline code.
This commit is contained in:
parent
d45ba19914
commit
fb6ff59218
1 changed files with 15 additions and 16 deletions
|
@ -64,28 +64,27 @@ var ProxyContext = new function() {
|
|||
isFunction = !!match[2];
|
||||
if (isFunction) {
|
||||
fields[name] = function() {
|
||||
if (name == 'restore') {
|
||||
if (name === 'restore')
|
||||
this._indents--;
|
||||
}
|
||||
var args = Array.prototype.slice.call(arguments, 0).join(', '),
|
||||
string = 'ctx.' + name + '(' + args + ');';
|
||||
console.log(this.getIndentation() + string);
|
||||
if (name == 'save') {
|
||||
console.log(this.getIndentation() + 'ctx.' + name + '('
|
||||
+ Array.prototype.slice.call(arguments, 0)
|
||||
.map(JSON.stringify).join(', ')
|
||||
+ ');');
|
||||
if (name === 'save')
|
||||
this._indents++;
|
||||
}
|
||||
return this._ctx[name].apply(this._ctx, arguments);
|
||||
};
|
||||
} else {
|
||||
var capitalized = Base.capitalize(name);
|
||||
fields['set' + capitalized] = function(value) {
|
||||
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() {
|
||||
fields[name] = {
|
||||
get: function() {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue