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 a 'defer' option to custom block args #22855
Conversation
70a06ec
to
610d227
Compare
f24d121
to
97eaab4
Compare
I'm not sure why you'd want to, but no need to clutter the code with this extra check.
Hmm, expected that these deferred accessor function are visible in the "Show Code" dialog? whenTouching(function () {
return mySprite;
}, function () {
return other;
}, function () {
}); |
It's expected, but that doesn't make it any less ugly. An alternative would be to move those functions up by the variable declarations, so that it would look more like:
|
What does codegen look like when we eventually add Something like: whenTouching({symbol: 'mySprite'}, {costume: 'bear'}, function () {
// ...
} |
@@ -11,7 +11,8 @@ | |||
"args": [ | |||
{ | |||
"name": "SPRITE", | |||
"type": "Sprite" | |||
"type": "Sprite", | |||
"defer": true |
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.
My concern is that requiring Block Editors to add the defer
attribute opens us up to possible bugs. In most cases it'll just work, but in specific cases the missing defer
will cause errors that depend on the order of the blocks in the workspace.
Can we defend against this, or make it easier to understand when defer
should be required? Should "Sprite" type args always have "defer": true
?
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.
We could make defer: true
the default for event/eventLoop block inputs, and you'd have to explicitly set defer: false
to turn it off. (This PR originally deferred all such inputs, there was no explicit defer
option, but I thought it should be configurable).
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.
When might you want the defer: false
behavior?
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.
It's not super important, but if you have a field input (e.g. 'when {DIR} key pressed'), then deferring it would needlessly clutter the generated code.
What does the code generation look like for the "when" block above? |
This is what the when block's codegen looks like:
Here's the block config and helper code too:
|
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 to make the breaking change for June 11. We should revisit after the deadline to explore how we want to enable the where
selector.
Given an event handler like:
Instead of generating code that just grabs the value of
mySprite
andother
at the beginning of the program:We can replace the arguments with getters that can return the current values of
mySprite
andother
:This is done by setting the
defer
option on the event block's arguments.The draw loop can then call those getters every tick, so that when the value of
mySprite
changes, the event handler reacts accordingly.