Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 24 additions & 9 deletions src/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
};

/**
Expand Down
Loading