Browse Source

REFA: fefactored base classes/logic of SideUnitDependendAttributes

renamed: SideUnitDependendAttribute -> DirectionUnitDependentAttribute
moved logic from Siding into DirectionUnitDependentAttribute
removed Siding class
updated inheritance to DirectionUnitDependentAttribute
master
chris 6 months ago
parent
commit
060918fe51
  1. 6
      src/sizeSide/dimensions.js
  2. 2
      src/sizeSide/shapes.js
  3. 66
      src/sizeSide/siding.js

6
src/sizeSide/dimensions.js

@ -1,13 +1,13 @@
const SidingRefDimensions = Object.freeze({
WIDTH: (sideUnitDependentAttribute) => sideUnitDependentAttribute._fFirst,
HEIGHT: (sideUnitDependentAttribute) => sideUnitDependentAttribute._fSecond
WIDTH: (DirectionUnitDependentAttribute) => DirectionUnitDependentAttribute._fFirst,
HEIGHT: (DirectionUnitDependentAttribute) => DirectionUnitDependentAttribute._fSecond
})
/**
* Simple Dimensions container for the height and width in pixels.
*/
class Dimensions extends SideUnitDependentAttribute {
class Dimensions extends DirectionUnitDependentAttribute {
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super();
this._unit = defaultUnit;

2
src/sizeSide/shapes.js

@ -5,7 +5,7 @@ const SidingRefCorners = Object.freeze({
BOTTOMRIGHT: (sideUnitDependentAttribute) => sideUnitDependentAttribute._fForth
})
class Shape extends Siding {
class Shape extends DirectionUnitDependentAttribute {
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super(defaultValue, defaultUnit);
}

66
src/sizeSide/siding.js

@ -4,17 +4,25 @@ const SizeUnits = Object.freeze({
})
class SideUnitDependentAttribute {
class DirectionUnitDependentAttribute {
_unit;
_fFirst;
_fSecond;
_fThird;
_fForth;
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
this._unit = defaultUnit;
this._fFirst = defaultValue;
this._fSecond = defaultValue;
this._fThird = defaultValue;
this._fForth = defaultValue;
}
/**
*
* @param {Units} unit The unit of the amount or style
* @returns {SideUnitDependentAttribute} this - Object
* @returns {DirectionUnitDependentAttribute} this - Object
*/
setUnit(unit) {
this._unit = unit;
@ -32,7 +40,7 @@ class SideUnitDependentAttribute {
*
* @param {SidingRef} sidingRef
* @param {*} value
* @returns {SideUnitDependentAttribute} this
* @returns {DirectionUnitDependentAttribute} this
*/
setBySidingRef(sidingRef, value) {
sidingRef(this) = value;
@ -58,25 +66,19 @@ const SidingRefSides = Object.freeze({
})
/**
* The Class holds values from each side/direction of an element.
* Used for margin/padding.
* Extended Logic is used for Dimensions, Shape, Border as well.
*/
class Siding extends SideUnitDependentAttribute {
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super();
this._unit = defaultUnit;
this._fFirst = defaultValue;
this._fSecond = defaultValue;
this._fThird = defaultValue;
this._fForth = defaultValue;
/**
* Placeholder for overrides
* @returns {Object}
*/
toModifications() {
return this.getOrderedValues()
}
/**
* sets the amount-value for all sides.
* @param {number} amount siding from all sides
* @returns {Siding} this Siding Object
* sets the amount-value for all directions.
* @param {number} amount value to set for all directions
* @returns {DirectionUnitDependentAttribute} this
*/
all(amount) {
this._fFirst = amount;
@ -86,6 +88,20 @@ class Siding extends SideUnitDependentAttribute {
return this;
}
}
class Sides extends DirectionUnitDependentAttribute {
/**
*
* @param {number|string} defaultValue
* @param {SizeUnits} defaultUnit
*/
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super(defaultValue, defaultUnit);
}
/**
* sets the amount-value for the left side.
* @param {number} amount siding for left
@ -137,15 +153,6 @@ class Siding extends SideUnitDependentAttribute {
}
class Sides extends Siding {
/**
*
* @param {number|string} defaultValue
* @param {*} defaultUnit
*/
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super(defaultValue, defaultUnit);
}
/**
* sets the amount-value for the horizontal sides (left and right).
* @param {number} amount siding for left and right.
@ -169,7 +176,8 @@ class Sides extends Siding {
}
}
class PaddingChain extends Sides{
class PaddingChain extends Sides {
_modifier;
constructor(modifier) {
super();

Loading…
Cancel
Save