Skip to content

EFv2: How do I add additional types to emit for model/union expressions? #6700

Answered by tadfisher
tadfisher asked this question in Q&A
Discussion options

You must be logged in to vote

I managed to do this with Alloy contexts and no mutation. The context has a function to deanonymize a type:

export interface NamespaceContext {
  /** Create a clone of [type] with a generated name and return a reference to that type. */
  deanonymizeType(type: Model | Union): Refkey;
}

And the component implements it like:

export function NamespaceDeclaration(props: NamespaceDeclarationProps) {
  const additionalTypes: [Refkey, Type][] = reactive([]);

  const namespaceContext: NamespaceContext = {
    deanonymizeType(type) {
      const clone = $.type.clone({ ...type, name: generateName(type) });
      const refkey = getRefkey(type);
      additionalTypes.push([refkey, clone]);
      return

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tadfisher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant