Skip to content

Commit

Permalink
Wrap size and reverse properties to recompute paddings
Browse files Browse the repository at this point in the history
  • Loading branch information
tusbar committed Aug 1, 2015
1 parent 027c30e commit 533334e
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions lib/millipede.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,42 @@ function Millipede(size, options) {
this.left = options.left || 0;

this.validate();
this._computePadding();
}

/**
* Size of the `Millipede`
*
* @return {Number} representing the size of the `Millipede`
* @public
*/

Object.defineProperty(Millipede.prototype, 'size', {
get: function () {
return this._size;
},
set: function (value) {
this._size = value;
this._computePadding();
}
});

/**
* Direction of the `Millipede`
*
* @return {Boolean} representing the direction of the `Millipede`
* @public
*/

Object.defineProperty(Millipede.prototype, 'reverse', {
get: function () {
return this._reverse;
},
set: function (value) {
this._reverse = !!value;
this._computePadding();
}
});

/**
* Compute used padding
*
Expand All @@ -48,7 +81,12 @@ Millipede.prototype._computePadding = function () {
this._P = PADDING;

if (this.size < PADDING.length) {
this._P = PADDING.slice(0, this.size);
if (this.reverse) {
this._P = PADDING.slice(PADDING.length - this.size);
}
else {
this._P = PADDING.slice(0, this.size);
}
}

this._PL = this._P.length;
Expand Down

0 comments on commit 533334e

Please sign in to comment.