-
Notifications
You must be signed in to change notification settings - Fork 18
Add initialize_global and global_declaration_entry blocks #69
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
Add initialize_global and global_declaration_entry blocks #69
Conversation
|
If I were to do something like this, @TannerGabriel, I think I would create another block, similar to the "initialize local" block that the "global initialize" blocks that you are proposing would have to go into. You could use the Blockly type checking mechanisms to ensure that only those "global initialize" blocks could go in there. That would fit a bit better with the general idea in the plugin (which comes from App Inventor) that anything with next/prev connectors does not generate code when placed at the top level of the workspace. I.e., that the need to be within some kind of container block. A potential advantage of this approach is that you could, optionally, limit it so that there is at most only one of these "initialize globals" blocks on a workspace, which would show all the global variables for a program. So your globals wouldn't be scattered all around the place. Note that you are free to use the fields and API in this plugin to create any blocks you want in your own app that uses the plugin. In this PR I'm only commenting on blocks that the plugin itself provides. |
…lobal-declaration-improvements
|
Hey @mark-friedman, I'm coming back to this after some time. I’ve warmed up to your idea while using the plugin, but I want to clarify a few points since this change has a bigger impact than I first expected:
Let me know if I’m missing anything. I don’t think a small feature like this justifies a breaking change, so if my understanding is correct, I’d either look for a different approach or hold off on implementing it for now. |
I am suggesting creating a new block similar to the I was suggesting using the Blockly type system to enforce that the
I would still maintain the
|
|
@TannerGabriel Did you see my earlier suggestion about using the Blockly type system to help enforce that a global_declarations2 block must be placed in the new initialize_global block and also that only global_declaration2 blocks could be placed in the new initialize_global block. Also note that the general approach in the plugin to invalid block placement is to set a warning and not to disable invalid blocks. This, of course, is related to your PR #71.
|
|
Yes, I saw your earlier suggestions. As I understand it, the Blockly type system only defines which blocks can connect, but it doesn’t stop blocks from being placed at the top level. Connection checks also pass if either block has a |
Good point! I forgot about the |
|
Thanks for the review. The issue occurs with the I also fixed another bug related to block disabling when dragging multiple blocks or reloading the page. |
mark-friedman
left a comment
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.
Style changes requested.
mark-friedman
left a comment
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.
LGTM
mark-friedman
left a comment
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.
Do you want to document the new blocks in the README file in this PR or do it in another PR?
|
I'm fine with both, whatever you prefer. Should I also only disable the blocks if |
If you don't mind, then we should document the new blocks, and the warning not to mix and match the two types of global declarations, in this PR.
That makes sense to me. |
…lobal-declaration-improvements
mark-friedman
left a comment
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.
LGTM



As described in #35 it would be nice to allow previousStatement and nextStatement to make multiple declarations look neater. To avoid confusion like #22 I would also only allow declaring global variables at the top level.