-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Project dirty state fixes #1962
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
Conversation
… scratch-blocks events are fired.
…changes in scenarios that were previously taking advantage of runtime._step()
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.
Overall this looks great, thanks for all the tests! I don't think this necessarily has to change before merging, there were just more than a few questions/suggestions.
src/engine/blocks.js
Outdated
@@ -564,7 +582,8 @@ class Blocks { | |||
// Changing the value in a dropdown | |||
block.fields[args.name].value = args.value; | |||
|
|||
if (!optRuntime){ | |||
if (!this.runtime){ | |||
log.warn('Runtime is not optional, it should get passed in when the block container is created.'); |
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 think this check should be farther up (and fatal) or can just be removed altogether. We assume it exists above... and all over the place elsewhere.
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.
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!
src/engine/blocks.js
Outdated
@@ -592,7 +611,8 @@ class Blocks { | |||
block.mutation = mutationAdapter(args.value); | |||
break; | |||
case 'checkbox': { | |||
if (!optRuntime) { | |||
if (!this.runtime) { | |||
log.warn('Runtime is not optional, it should get passed in when the block container is created.'); |
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.
Remove?
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!
src/engine/blocks.js
Outdated
@@ -663,6 +683,10 @@ class Blocks { | |||
} | |||
} | |||
|
|||
// TODO maybe track actual changes, |
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.
Is this super hard to figure out in this pass?
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.
Ah I had actually put this in here as a note to myself to see whether we needed to track actual changes or if this was good enough. I think in general it is usually rare that we would receive a change
event from scratch-blocks where a change did not occur. This is unlike the other cases (create, move, delete) where we get the respective events from scratch-blocks but effectively no change occurs in the VM.
I don't think it's possible to get a change event for a block without some user interaction with the block. @picklesrus, I would be interested to know, can you think of scenarios where this would happen?
I think I'll probably remove this TODO comment.
src/virtual-machine.js
Outdated
} | ||
if (projectVersion === 3) { | ||
return this._addSprite3(validatedInput[0], validatedInput[1]); | ||
return this._addSprite3(validatedInput[0], validatedInput[1]) | ||
.then(() => this.runtime.emitProjectChanged()); |
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.
Since we reject in case of neither of these, can't we put this in the next then()
? I.e. chained to .then(validatedInput =>...).then(/* here? */)
?
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.
Yep, that makes sense! Good catch!
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!
this.runtime.on(Runtime.TARGETS_UPDATE, () => { | ||
this.emitTargetsUpdate(); | ||
this.runtime.on(Runtime.TARGETS_UPDATE, emitProjectChanged => { | ||
this.emitTargetsUpdate(emitProjectChanged); |
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.
Is this ever 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.
Right now it isn't, but I don't know whether it's better to just assume always false here...
In a future pass we plan to completely separate out targets update and project changed, so we can fix this there then too. I'll file an actual issue for it.
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.
Filed in #1964
Towards resolving scratchfoundation/scratch-gui#4275 |
5a4a11b
to
b270fae
Compare
…`.then` (at the higher level)
b270fae
to
13e69ba
Compare
Proposed Changes
Depends on #1941 (and currently the diff includes changes from that PR).
@chrisgarrity and I worked on all of these changes together.
Fix erroneous project changed state reporting.
This PR starts to decouple emitting a targets update from emitting a project changed.
Prior to this PR, we were erroneously emitting a project changed state in the following cases:
The above scenarios were getting triggered by emitting project changes in the following scenarios:
vm.clear()
(which happens during load project),runtime._step()
which is always running (before/during/after project load)After investigating and comparing the cases in which Scratch 2.0 and Scratch 3.0 track dirty state, we decided to resolve these issues by:
runtime._step()
vm.clear()
runtime._step
, we now specifically track project changes that were previously being emitted as a side effect (e.g. adding a sprite, adding a costume, etc. -- all the changes insrc/virtual-machine.js
)renameSprite()
to only emit a project change/targets update if an actual rename occurred.Test Coverage
Added lots of unit tests and an integration test. Also did lots of manual testing!
We have documented our investigation and manual testing in the following doc. We have also documented some known issues in the doc.
https://docs.google.com/document/d/1DKM4rf-ajioOrAeipsgtuIluJNMIo71L3MfgB84y3JE/edit
Changes can be tested at https://llk.github.io/scratch-gui/project-state-changes