Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Record DependableTrait directly on instance #2962

Merged
merged 1 commit into from
Jun 20, 2019
Merged
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
10 changes: 5 additions & 5 deletions packages/@aws-cdk/cdk/lib/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class ConcreteDependable implements IDependable {
}
}

const DEPENDABLE_SYMBOL = Symbol.for('@aws-cdk/core.DependableTrait');

/**
* Trait for IDependable
*
Expand Down Expand Up @@ -68,27 +70,25 @@ export abstract class DependableTrait {
// I would also like to reference classes (to cut down on the list of objects
// we need to manage), but we can't do that either since jsii doesn't have the
// concept of a class reference.
DependableTrait.traitMap.set(instance, trait);
(instance as any)[DEPENDABLE_SYMBOL] = trait;
}

/**
* Return the matching DependableTrait for the given class instance.
*/
public static get(instance: IDependable): DependableTrait {
const ret = DependableTrait.traitMap.get(instance);
const ret = (instance as any)[DEPENDABLE_SYMBOL];
if (!ret) {
throw new Error(`${instance} does not implement DependableTrait`);
}
return ret;
}

private static traitMap = new WeakMap<IDependable, DependableTrait>();

/**
* The set of constructs that form the root of this dependable
*
* All resources under all returned constructs are included in the ordering
* dependency.
*/
public abstract readonly dependencyRoots: IConstruct[];
}
}