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

feat(generators): add .generatorTag symbol to Generators #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fedeci
Copy link
Contributor

@fedeci fedeci commented Oct 28, 2022

No description provided.

@fedeci fedeci requested a review from clo4 October 28, 2022 07:39
@@ -1211,3 +1216,7 @@ declare namespace Fig {
cache?: Cache;
}
}

interface SymbolConstructor {
readonly generatorTag: unique symbol;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative name may be this one:

Suggested change
readonly generatorTag: unique symbol;
readonly generatorName: unique symbol;

@@ -140,6 +140,8 @@ function filepathsFn(options: FilepathsOptions = {}): Fig.Generator {
};

return {
[Symbol.generatorTag]: "filepathsTemplate",
Copy link
Contributor Author

@fedeci fedeci Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: adding symbols properties to our objects makes a strong requirement for those creating tools relying on specs (e.g. AE, Dashboard) and running generators. They are basically a protocol that should be implemented.
e.g.

const generator: Fig.Generator = {
  [Symbol.generatorTag]: "name"
}
// if `Symbol.generatorTag` is not defined in the environment (see the ref PR in AE to understand how it is defined)
// the objects assumes the following shape
const generator: Fig.Generator = {
  undefined: "name"
}
// which means that if I try to access `undefined` I get "name"
generator[undefined] // "name"
generator["undefPropertyName"] // "name"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant