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** |
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);
};
/**