Skip to content

Commit

Permalink
Rearrange Base.read argument sequence.
Browse files Browse the repository at this point in the history
options are used more often than length.
  • Loading branch information
lehni committed Jan 5, 2014
1 parent cd6bfa0 commit 706fe2c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/basic/Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
// Do not modify scale, center, since that would arguments of which
// we're reading from!
var scale = Point.read(arguments),
center = Point.read(arguments, 0, 0, { readNull: true });
center = Point.read(arguments, 0, { readNull: true });
if (center)
this.translate(center);
this._a *= scale.x;
Expand Down Expand Up @@ -278,7 +278,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
// Do not modify point, center, since that would arguments of which
// we're reading from!
var shear = Point.read(arguments),
center = Point.read(arguments, 0, 0, { readNull: true });
center = Point.read(arguments, 0, { readNull: true });
if (center)
this.translate(center);
var a = this._a,
Expand Down Expand Up @@ -314,7 +314,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
*/
skew: function(/* skew, center */) {
var skew = Point.read(arguments),
center = Point.read(arguments, 0, 0, { readNull: true }),
center = Point.read(arguments, 0, { readNull: true }),
toRadians = Math.PI / 180,
shear = new Point(Math.tan(skew.x * toRadians),
Math.tan(skew.y * toRadians));
Expand Down
14 changes: 7 additions & 7 deletions src/core/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Base.inject(/** @lends Base# */{
* passed objects should be cloned if they are already provided in the
* required type
*/
read: function(list, start, length, options) {
read: function(list, start, options, length) {
// See if it's called directly on Base, and if so, read value and
// return without object conversion.
if (this === Base) {
Expand Down Expand Up @@ -215,12 +215,12 @@ Base.inject(/** @lends Base# */{
* required type
*/
readAll: function(list, start, options) {
var res = [], entry;
var res = [],
entry;
for (var i = start || 0, l = list.length; i < l; i++) {
res.push(Array.isArray(entry = list[i])
// lenghh = 0 for length = max
? this.read(entry, 0, 0, options)
: this.read(list, i, 1, options));
? this.read(entry, 0, options)
: this.read(list, i, options, 1));
}
return res;
},
Expand All @@ -236,7 +236,7 @@ Base.inject(/** @lends Base# */{
* @param {Number} start the index at which to start reading in the list
* @param {String} name the property name to read from.
*/
readNamed: function(list, name, start, length, options) {
readNamed: function(list, name, start, options, length) {
var value = this.getNamed(list, name),
hasObject = value !== undefined;
if (hasObject) {
Expand All @@ -253,7 +253,7 @@ Base.inject(/** @lends Base# */{
// shine through.
filtered[name] = undefined;
}
return this.read(hasObject ? [value] : list, start, length, options);
return this.read(hasObject ? [value] : list, start, options, length);
},

/**
Expand Down
6 changes: 3 additions & 3 deletions src/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
var current = this.getScaling();
if (current != null) {
// Clone existing points since we're caching internally.
var scaling = Point.read(arguments, 0, 0, { clone: true }),
var scaling = Point.read(arguments, 0, { clone: true }),
// See #setRotation() for preservation of _decomposed.
decomposed = this._decomposed;
this.scale(scaling.x / current.x, scaling.y / current.y);
Expand Down Expand Up @@ -2600,14 +2600,14 @@ var Item = Base.extend(Callback, /** @lends Item# */{
*/
rotate: function(angle /*, center */) {
return this.transform(new Matrix().rotate(angle,
Point.read(arguments, 1, 0, { readNull: true })
Point.read(arguments, 1, { readNull: true })
|| this.getPosition(true)));
}
}, Base.each(['scale', 'shear', 'skew'], function(name) {
this[name] = function() {
// See Matrix#scale for explanation of this:
var point = Point.read(arguments),
center = Point.read(arguments, 0, 0, { readNull: true });
center = Point.read(arguments, 0, { readNull: true });
return this.transform(new Matrix()[name](point,
center || this.getPosition(true)));
};
Expand Down
2 changes: 1 addition & 1 deletion src/path/Path.Constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Path.inject({ statics: new function() {
*/
Rectangle: function(/* rectangle */) {
var rect = Rectangle.readNamed(arguments, 'rectangle'),
radius = Size.readNamed(arguments, 'radius', 0, 0,
radius = Size.readNamed(arguments, 'radius', 0,
{ readNull: true }),
bl = rect.getBottomLeft(true),
tl = rect.getTopLeft(true),
Expand Down
9 changes: 4 additions & 5 deletions src/style/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ var Color = Base.extend(new function() {
parser = componentParsers[type][index] = name === 'gradient'
? function(value) {
var current = this._components[0];
value = Gradient.read(
Array.isArray(value) ? value : arguments,
0, 0, { readNull: true });
value = Gradient.read(Array.isArray(value) ? value
: arguments, 0, { readNull: true });
if (current !== value) {
if (current)
current._removeOwner(this);
Expand All @@ -251,7 +250,7 @@ var Color = Base.extend(new function() {
}
: type === 'gradient'
? function(/* value */) {
return Point.read(arguments, 0, 0, {
return Point.read(arguments, 0, {
readNull: name === 'highlight',
clone: true
});
Expand Down Expand Up @@ -1136,7 +1135,7 @@ var Color = Base.extend(new function() {

return Base.each(operators, function(operator, name) {
this[name] = function(color) {
color = Color.read(arguments, 0, 0);
color = Color.read(arguments);
var type = this._type,
properties = this._properties,
components1 = this._components,
Expand Down
4 changes: 2 additions & 2 deletions src/style/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ var Style = Base.extend(new function() {
this._values[key] = value;
} else if (isColor && !(value && value.constructor === Color)) {
// Convert to a Color and stored result of conversion.
this._values[key] = value = Color.read(
[value], 0, 0, { readNull: true, clone: true });
this._values[key] = value = Color.read([value], 0,
{ readNull: true, clone: true });
if (value)
value._owner = this._item;
}
Expand Down

0 comments on commit 706fe2c

Please sign in to comment.