4 changed files with 209 additions and 214 deletions
@ -0,0 +1,122 @@ |
|||||
|
/** |
||||
|
* @extends Modifier |
||||
|
* @inheritdoc |
||||
|
*/ |
||||
|
class ChainableModifier extends Modifier { |
||||
|
/** |
||||
|
* @type {Component} |
||||
|
*/ |
||||
|
_component; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param {Component} component |
||||
|
*/ |
||||
|
constructor(component) { |
||||
|
super(); |
||||
|
this._component = component; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritdoc |
||||
|
* |
||||
|
* In Case it is called from a ChainableModifier chain, |
||||
|
* the Return type would be DimensionsChainedModifier instead of DimensionsChain. |
||||
|
* @override |
||||
|
* @param {Dimensions | number | undefined} [modify=null] dimensions |
||||
|
* @returns {ChainableModifier | DimensionsChainedModifier} |
||||
|
*/ |
||||
|
dimensions(modify = null) { |
||||
|
if (modify instanceof Dimensions || Number.isInteger(modify)) { |
||||
|
return super.dimensions(modify); |
||||
|
} |
||||
|
return new DimensionsChainedModifier(this); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritdoc |
||||
|
* @override |
||||
|
* @param {Padding | number | undefined} [modify=null] modify as in modifiers |
||||
|
* @returns {ChainableModifier | PaddingChainedModifier} |
||||
|
*/ |
||||
|
padding(modify = null) { |
||||
|
if (modify instanceof Padding || Number.isInteger(modify)) { |
||||
|
return super.padding(modify); |
||||
|
} |
||||
|
return new PaddingChainedModifier(this); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritdoc |
||||
|
* @override |
||||
|
* @param {Margin | number | undefined} [modify=null] modify as in modifiers |
||||
|
* @returns {ChainableModifier | MarginChainedModifier} |
||||
|
*/ |
||||
|
margin(modify = null) { |
||||
|
if (modify instanceof Margin || Number.isInteger(modify)) { |
||||
|
return super.margin(modify); |
||||
|
} |
||||
|
return new MarginChainedModifier(this); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritdoc |
||||
|
* |
||||
|
* @override |
||||
|
* @param {Shape | number | undefined} [modify=null] modify |
||||
|
* @returns {ChainableModifier | ShapeChainedModifier} |
||||
|
*/ |
||||
|
clip(modify = null) { |
||||
|
if (modify instanceof Shape || Number.isInteger(modify)) { |
||||
|
return super.clip(modify); |
||||
|
} |
||||
|
return new ShapeChainedModifier(this); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @inheritdoc |
||||
|
* |
||||
|
* @override |
||||
|
* @param {Border | number | undefined} [modify=null] modify |
||||
|
* @returns {ChainableModifier | BorderChainedModifier} |
||||
|
*/ |
||||
|
border(modify = null) { |
||||
|
if (modify instanceof Border || Number.isInteger(modify)) { |
||||
|
return super.border(modify); |
||||
|
} |
||||
|
return new BorderChainedModifier(this); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @returns {Component} |
||||
|
*/ |
||||
|
toComponent() { |
||||
|
return this._component.modifier(this); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param {Component|Array<Component>} innerComponent |
||||
|
* @returns {Component} the parent Component |
||||
|
*/ |
||||
|
childContext(innerComponent) { |
||||
|
return this._component |
||||
|
.modifier(this) |
||||
|
.childContext(innerComponent); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Calls chainChild() from Component (ChildbearerComponent) |
||||
|
* @see {ChildbearerComponent.chainChild} |
||||
|
* @returns {builder} |
||||
|
*/ |
||||
|
chainChild() { |
||||
|
return this._component |
||||
|
.modifier(this) |
||||
|
.chainChild(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,87 @@ |
|||||
|
/** |
||||
|
* @abstract |
||||
|
*/ |
||||
|
class ModificationSubChain { |
||||
|
/** |
||||
|
* @type {Modifier} |
||||
|
*/ |
||||
|
_modifier; |
||||
|
/** |
||||
|
* @type {string} |
||||
|
*/ |
||||
|
_modMethod; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param {Modifier} modifier |
||||
|
* @param {string} modMethod |
||||
|
*/ |
||||
|
constructor(modifier, modMethod) { |
||||
|
this._modifier = modifier; |
||||
|
this._modMethod = modMethod; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns the Modifier SubChain to the Modifier |
||||
|
* @returns {Modifier|ChainableModifier} |
||||
|
*/ |
||||
|
toModifier() { |
||||
|
return this._modifier[this._modMethod](this); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns chain to the Modifier |
||||
|
* @returns {Modifier|ChainableModifier} |
||||
|
*/ |
||||
|
ensureModifier() { |
||||
|
return this.toModifier(); |
||||
|
} |
||||
|
} |
||||
|
/** |
||||
|
* @inheritdoc |
||||
|
* @extends ModificationSubChain |
||||
|
* @abstract |
||||
|
*/ |
||||
|
class ModificationSubChainReComp extends ModificationSubChain { |
||||
|
/** |
||||
|
* |
||||
|
* @param {ChainableModifier} modifier |
||||
|
* @param {string} modMethod |
||||
|
*/ |
||||
|
constructor(modifier) { |
||||
|
super(); |
||||
|
this._modifier = modifier; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns chain to the component that is under modification |
||||
|
* @returns {Component} the Component that was (supposed to be) modified by this obj. |
||||
|
*/ |
||||
|
toComponent() { |
||||
|
return this._modifier[this._modMethod](this) |
||||
|
.toComponent(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns chain to the component that is under modification |
||||
|
* and adds the given innerComponent as children to the component. |
||||
|
* @param {Component|Array<Component>} innerComponent |
||||
|
* @returns {Component} |
||||
|
*/ |
||||
|
childContext(innerComponent) { |
||||
|
return this._modifier[this._modMethod](this) |
||||
|
.toComponent() |
||||
|
.childContext(innerComponent); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Closes modifier chain and returns builder to define the next child of the component |
||||
|
* @returns {Component} |
||||
|
*/ |
||||
|
chainChild() { |
||||
|
return this._modifier[this._modMethod](this) |
||||
|
.toComponent() |
||||
|
.chainChild(); |
||||
|
} |
||||
|
} |
||||
|
|
Loading…
Reference in new issue