mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -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];
|
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);
|
||||||
|
|
Loading…
Reference in a new issue