From bb021beb5176dece45489596fb343ffb17a5daaf Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Thu, 19 Feb 2026 09:39:50 +0000 Subject: [PATCH 1/2] feat: move with() implementation to Node class Provide a default implementation of with() on Node, making it easy for custom IConstruct implementations to support mixins by delegating to this.node.with(). --- src/construct.ts | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/construct.ts b/src/construct.ts index fb5da567..0340f6de 100644 --- a/src/construct.ts +++ b/src/construct.ts @@ -432,6 +432,29 @@ export class Node { this._locked = true; } + /** + * Applies one or more mixins to this construct. + * + * Mixins are applied in order. The list of constructs is captured at the + * start of the call, so constructs added by a mixin will not be visited. + * Use multiple `with()` calls if subsequent mixins should apply to added + * constructs. + * + * @param mixins The mixins to apply + * @returns This construct for chaining + */ + public with(...mixins: IMixin[]): IConstruct { + const allConstructs = this.findAll(); + for (const mixin of mixins) { + for (const construct of allConstructs) { + if (mixin.supports(construct)) { + mixin.applyTo(construct); + } + } + } + return this.host; + }; + /** * Adds a child construct to this node. * @@ -529,15 +552,7 @@ export class Construct implements IConstruct { * @returns This construct for chaining */ public with(...mixins: IMixin[]): IConstruct { - const allConstructs = this.node.findAll(); - for (const mixin of mixins) { - for (const construct of allConstructs) { - if (mixin.supports(construct)) { - mixin.applyTo(construct); - } - } - } - return this; + return this.node.with(...mixins); }; /** From 5ac0582ecc5e7c60af1c9d879a60606de56a419e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:41:03 +0000 Subject: [PATCH 2/2] chore: self mutation Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- API.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/API.md b/API.md index d961cbd9..1f2716dd 100644 --- a/API.md +++ b/API.md @@ -625,6 +625,7 @@ new Node(host: Construct, scope: IConstruct, id: string) | tryGetContext | Retrieves a value from tree context. | | tryRemoveChild | Remove the child with the given name, if present. | | validate | Validates this construct. | +| with | Applies one or more mixins to this construct. | --- @@ -868,6 +869,27 @@ Validates this construct. Invokes the `validate()` method on all validations added through `addValidation()`. +##### `with` + +```typescript +public with(mixins: ...IMixin[]): IConstruct +``` + +Applies one or more mixins to this construct. + +Mixins are applied in order. The list of constructs is captured at the +start of the call, so constructs added by a mixin will not be visited. +Use multiple `with()` calls if subsequent mixins should apply to added +constructs. + +###### `mixins`Required + +- *Type:* ...IMixin[] + +The mixins to apply. + +--- + #### Static Functions | **Name** | **Description** |