Editor: Defers Commands initialization #28360
Closed
+196
−30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update: This post has converted to draft as #28398 seems to be more appropriated, see #28398 (comment) for reason why constructor should not be bothered by states recovery, thanks.
Related: #28345 ( issue 1 )
Issue: Commands don't respect current recovery mechanics:
A placeholder command is created in (A), however, some commands don't handle this case, i.e. commands may throw at (A), or some states may wrongly be assigned to
undefined
if they depends on constructor parameters but now missing, in this case the error will be thrown when performing Undo/Redo instead.To reproduce:
Cannot read properties of undefined (reading 'color')
in console.Solution (This PR): Defers command initialization
In History.js,
.fromJSON()
is now constructing command with an Defer object, as a sentinel:Then in each command constructor, guarding initialization via check against the sentinel:
This way is more explicit than using
arguments.length>1
as a guard, solved #28345 (comment)