Test code for Path#segments change observation.

This commit is contained in:
Jürg Lehni 2011-03-08 17:20:03 +00:00
parent 3927836441
commit 484b2b0c94

View file

@ -27,37 +27,6 @@ var Path = this.Path = PathItem.extend({
|| typeof segments[0] != 'object' ? arguments : segments);
},
/**
* The segments contained within the path.
*/
getSegments: function() {
return this._segments;
},
setSegments: function(segments) {
var length = segments.length;
if (!this._segments) {
this._segments = new Array(length);
/*
this._segments = Base.each(
['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'],
function(name) {
var prev = this[name];
this[name] = function() {
return prev.apply(this, arguments);
}
},
new Array(length)
);
*/
} else {
this._segments.length = length;
}
for(var i = 0; i < length; i++) {
this._add(Segment.read(segments, i, 1));
}
},
/**
* The curves contained within the path.
*/
@ -200,6 +169,44 @@ var Path = this.Path = PathItem.extend({
ctx.restore();
}
}
}, new function() { // Scope for segments list change detection
var segmentsFields = Base.each(
['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'],
function(name) {
var func = Array.prototype[name];
this[name] = function() {
return func.apply(this, arguments);
}
}, {});
return {
beans: true,
/**
* The segments contained within the path.
*/
getSegments: function() {
return this._segments;
},
setSegments: function(segments) {
var length = segments.length;
if (!this._segments) {
// Enhance the _segments array with functions that watch for
// change.
this._segments = Base.each(segmentsFields,
function(value, name) {
this[name] = value;
}, []);
} else {
this._segments.length = 0;
}
for(var i = 0; i < length; i++) {
this._add(Segment.read(segments, i, 1));
}
}
}
}, new function() { // Inject methods that require scoped privates
/**