-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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(blocks): Migrate blocks/variables.js
and blocks/variables_dynamic.js
to TypeScript
#7001
refactor(blocks): Migrate blocks/variables.js
and blocks/variables_dynamic.js
to TypeScript
#7001
Conversation
blocks/variables.js
and blocks/variables_dynamic.js
to TypeScript
(Retitled for consistency and findability in search.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small items. I think most apply to both variables.ts
and variables_dynamic.ts
, so please check both in case I overlooked it in one or the other.
@@ -249,7 +250,8 @@ const CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = { | |||
* @param options List of menu options to add to. | |||
*/ | |||
customContextMenu: function( | |||
this: CustomContextMenuBlock, options: Array<any>) { | |||
this: CustomContextMenuBlock, | |||
options: Array<ContextMenuOption|LegacyContextMenuOption>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure why you're adding this here, since options
is not used in the body of the function. Is it needed because this serves as a type declaration that is overridden elsewhere? If so, could the parameter not be omitted here and made optional (for type compatibility) on the override, with a runtime check to ensure it is actually supplied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options
is used on line 267, where we push the new option onto the array.
blocks/variables.ts
Outdated
|
||
options.push({ | ||
enabled: this.workspace.remainingCapacity() > 0, | ||
text: text, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can be concise here if you like:
text: text, | |
text, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just inlined type
instead since it's only used in this place.
blocks/variables_dynamic.ts
Outdated
import {Abstract as AbstractEvent} from '../core/events/events_abstract.js'; | ||
import type {ContextMenuOption, LegacyContextMenuOption} from '../core/contextmenu_registry.js'; | ||
import * as ContextMenu from '../core/contextmenu.js'; | ||
import {FieldVariable} from '../core/field_variable.js'; | ||
import * as Extensions from '../core/extensions.js'; | ||
import * as Variables from '../core/variables.js'; | ||
import type {WorkspaceSvg} from '../core/workspace_svg.js'; | ||
import * as xml from '../core/utils/xml.js'; | ||
import type {Block} from '../core/block.js'; | ||
import {Msg} from '../core/msg.js'; | ||
import {createBlockDefinitionsFromJsonArray, defineBlocks} from '../core/common.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import ordering:
import {Abstract as AbstractEvent} from '../core/events/events_abstract.js'; | |
import type {ContextMenuOption, LegacyContextMenuOption} from '../core/contextmenu_registry.js'; | |
import * as ContextMenu from '../core/contextmenu.js'; | |
import {FieldVariable} from '../core/field_variable.js'; | |
import * as Extensions from '../core/extensions.js'; | |
import * as Variables from '../core/variables.js'; | |
import type {WorkspaceSvg} from '../core/workspace_svg.js'; | |
import * as xml from '../core/utils/xml.js'; | |
import type {Block} from '../core/block.js'; | |
import {Msg} from '../core/msg.js'; | |
import {createBlockDefinitionsFromJsonArray, defineBlocks} from '../core/common.js'; | |
import * as ContextMenu from '../core/contextmenu.js'; | |
import * as Extensions from '../core/extensions.js'; | |
import * as Variables from '../core/variables.js'; | |
import * as xml from '../core/utils/xml.js'; | |
import {Abstract as AbstractEvent} from '../core/events/events_abstract.js'; | |
import type {Block} from '../core/block.js'; | |
import type {ContextMenuOption, LegacyContextMenuOption} from '../core/contextmenu_registry.js'; | |
import {FieldVariable} from '../core/field_variable.js'; | |
import {Msg} from '../core/msg.js'; | |
import type {WorkspaceSvg} from '../core/workspace_svg.js'; | |
import {createBlockDefinitionsFromJsonArray, defineBlocks} from '../core/common.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(But why do the imports from common.js
go at the end?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it that way because lowercase letters come after uppercase in asciibetical order—but now I realise I'm not actually sure what the rules are (and they no longer exist in the styleguide, since it just says to use the tooling). Maybe we should be ordering by filename? Who knows. Anyway… feel free to do something different if you have a principled reason for doing so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and ready for re-review
blocks/variables_dynamic.ts
Outdated
import {Abstract as AbstractEvent} from '../core/events/events_abstract.js'; | ||
import type {ContextMenuOption, LegacyContextMenuOption} from '../core/contextmenu_registry.js'; | ||
import * as ContextMenu from '../core/contextmenu.js'; | ||
import {FieldVariable} from '../core/field_variable.js'; | ||
import * as Extensions from '../core/extensions.js'; | ||
import * as Variables from '../core/variables.js'; | ||
import type {WorkspaceSvg} from '../core/workspace_svg.js'; | ||
import * as xml from '../core/utils/xml.js'; | ||
import type {Block} from '../core/block.js'; | ||
import {Msg} from '../core/msg.js'; | ||
import {createBlockDefinitionsFromJsonArray, defineBlocks} from '../core/common.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
blocks/variables_dynamic.ts
Outdated
import {Abstract as AbstractEvent} from '../core/events/events_abstract.js'; | ||
import type {ContextMenuOption, LegacyContextMenuOption} from '../core/contextmenu_registry.js'; | ||
import * as ContextMenu from '../core/contextmenu.js'; | ||
import {FieldVariable} from '../core/field_variable.js'; | ||
import * as Extensions from '../core/extensions.js'; | ||
import * as Variables from '../core/variables.js'; | ||
import type {WorkspaceSvg} from '../core/workspace_svg.js'; | ||
import * as xml from '../core/utils/xml.js'; | ||
import type {Block} from '../core/block.js'; | ||
import {Msg} from '../core/msg.js'; | ||
import {createBlockDefinitionsFromJsonArray, defineBlocks} from '../core/common.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(But why do the imports from common.js
go at the end?)
The basics
npm run format
andnpm run lint
The details
Resolves
Part of #6828