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: basic block factory implementation #1995

Closed
wants to merge 26 commits into from

Conversation

maribethb
Copy link
Contributor

The basics

The details

Resolves

Proposed Changes

Can be reviewed commit-wise.

Basic implementation of developer tools. There is still some placeholder text and things that need to be cleaned up. More work is following this :)

  • Copies over the block definitions from core/demos, and updates them to use TypeScript, es5 syntax, JSON serialization helpers where appropriate
    • Does not copy over the angle, colour, or multiline text field blocks since those will be used from the plugin.
  • Changes the input block to be a single block type with a dropdown for the input type. This makes it easier to change input styles.
  • Changes the type block to be a single block type with a dropdown for the type. This makes it easier to change types.
  • Uses a CodeGenerator class to construct the JSON definition for the blocks
    • This is a copy of the JS generator that I commented a bunch of stuff out in. I plan to clean this up separately as I needed more investigation as to what was required and what wasn't.
    • I plan to follow a similar path for creating the JS definition, as well as preamble code like import statements needed for plugin fields, the generator stubs, etc.

Most of the code currently in src/index.ts will be rearranged and moved to different files. I have another branch branched from this one where I've started rearranging the logic to use controllers and separate out the dom manipulation code. I wanted to start by validating the CodeGenerator approach instead of starting by creating a bunch of application scaffolding.

Since this isn't being published anywhere I think it's fine to go directly into master but can also put it in a branch if that's preferred.

Reason for Changes

Modernizing dev-tools.

Test Coverage

No unit tests yet. We lack infrastructure for running tests in examples/

Documentation

Additional Information

desktop view
image

mobile view
image

@maribethb maribethb requested a review from a team as a code owner September 28, 2023 23:47
@maribethb maribethb requested review from rachel-fenichel and removed request for a team September 28, 2023 23:47
Copy link
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

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

Overall looks reasonable. I prefer that you put it into a feature branch rather than master.

examples/developer-tools/src/blocks/factory_base.ts Outdated Show resolved Hide resolved
examples/developer-tools/src/blocks/factory_base.ts Outdated Show resolved Hide resolved
/**
* Label (non-serializable) field.
*/
export const fieldLabel = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A small opinion: block definitions that can be written only in JSON should be. JavaScript definitions should be used for more dynamic blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This gets complicated if I'm trying to export the block definitions so that they can be registered from a different file than they're defined in. I would have to know whether the thing I'm exporting is a JS definition or a JSON definition, and then call them differently in the register call. I think it's simpler and less prone to error to define and export them all consistently even though that means using JS when I could use JSON.

We have been trying to remove side effects from our files but in core we still register blocks in the file we declare them so I don't have a good pattern to follow. I'm open to suggestions if this is important to you.

@BeksOmega BeksOmega self-requested a review October 30, 2023 22:21
@maribethb maribethb changed the base branch from master to developer-tools January 4, 2024 22:16
@maribethb
Copy link
Contributor Author

@BeksOmega ready for review; I believe I addressed the feedback so far and I created a new feature branch for this. Thanks!

Copy link
Contributor

@BeksOmega BeksOmega left a comment

Choose a reason for hiding this comment

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

Left comments on the first five commits. Will continue in the morning.

examples/developer-tools/tsconfig.json Outdated Show resolved Hide resolved
export const factoryBase = {
// Base of new block.
init: function() {
this.setColour(120);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we care about using best practices? If so this should probably be using a theme. I won't comment on any other "best practices" things until I know if we care or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using a theme sounds good, but I'd prefer to do that in a separate PR. I'll also update the toolbox to not just reuse logic_category etc.

I do care about best practices, with the caveat that for some stuff this is just an initial PR to prove the feasibility of using the code generator approach instead of the manual approach used in the old tool, so some of the best practices will be done in later PRs

examples/developer-tools/src/blocks/factory_base.ts Outdated Show resolved Hide resolved
examples/developer-tools/src/blocks/factory_base.ts Outdated Show resolved Hide resolved
examples/developer-tools/src/blocks/inputs.ts Outdated Show resolved Hide resolved
examples/developer-tools/src/blocks/inputs.ts Outdated Show resolved Hide resolved
examples/developer-tools/src/blocks/inputs.ts Outdated Show resolved Hide resolved
examples/developer-tools/src/toolbox.ts Outdated Show resolved Hide resolved
Comment on lines 78 to 81
if (e.isUiEvent || e.type == Blockly.Events.FINISHED_LOADING ||
mainWorkspace.isDragging()) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally more predictable + future proof to use allow lists rather than deny lists for change listeners. E.g. google/blockly#6337

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want pretty much all non-UI events though. I feel like this is a standard pattern we use elsewhere, and a list of every non-UI event would be harder to read and scan for accuracy (easy to forget one).

examples/developer-tools/src/index.ts Show resolved Hide resolved
@BeksOmega
Copy link
Contributor

Heya @maribethb do you think you could split this up into a few different PRs? I don't think this is actually comit-wise reviewable because things in the earlier commits change in later commits.

@BeksOmega
Copy link
Contributor

@maribethb can I close this?

@maribethb maribethb closed this Jan 22, 2024
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.

4 participants