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

refactor: convert registry files to es6 classes #5940

Merged
merged 5 commits into from
Feb 18, 2022

Conversation

rachel-fenichel
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

The details

Resolves

Part of #5860

Proposed Changes

  • Change the shortcut registry and context menu registry to have internal registry variables that are exported under appropriate names.
  • Add reset functions to the shortcut registry and context menu registry.
  • Update tests as needed.
  • Change the Type object in registry.js to an es6 class.

Behavior Before Change

Clearing the shortcut registry or context menu registry in tests was done by calling the constructor.

Behavior After Change

Now clearing those registries is done by calling reset.

Reason for Changes

Movement toward Typescript.

Test Coverage

Documentation

Additional Information

Typescript warns that keyMap_ and registry_ and so on can be undefined, because I'm setting them in the reset function instead of directly in the constructor. Typescript has the definite assignment assertion operator to deal with this.

core/registry.js Outdated
@@ -73,28 +73,31 @@ exports.DEFAULT = DEFAULT;

/**
* A name with the type of the element stored in the generic.
* @param {string} name The name of the registry type.
* @constructor
* @template T
* @alias Blockly.registry.Type
Copy link
Contributor

Choose a reason for hiding this comment

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

For the other classes you've moved the @alias down to the constructor as well. Not sure which one makes the JsDoc tool happier but I had been assuming it was on the constructor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, for consistency. I'm not sure and slightly expect I'll have to do a cleanup pass when I get to API extractor; so far I've been ignoring the JsDoc tool.


exports.contextMenuRegistry = ContextMenuRegistry.registry;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we exporting this (and for shortcut registry) now? Is it just as a shorthand for ContextMenuRegistry.registry? I don't like introducing API/naming changes (also needs documentation changes if we intend developers to use this) buried in what seems like a refactoring change.

I think this is a good idea, it would match the fieldRegistry and class registry patterns, but also needs a few other updates like changing the internal usages and the jsdoc for the class explaining how to use the registry.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I've backed it out and filed #5950 to track and/or discuss.

@rachel-fenichel rachel-fenichel merged commit f1148f1 into google:develop Feb 18, 2022
@rachel-fenichel rachel-fenichel deleted the convert_registries branch February 18, 2022 19:36
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.

2 participants