Repository navigation
fix: the rectangle label listens to the canvas once for all its labels - #207
Merged
Merged
Conversation
Each label subscribed to object:scaling and object:moving on the canvas when it was drawn, and nothing unsubscribed. The listeners stayed after a label was deleted or the canvas was cleared, so a canvas drawn on for long kept more and more of them. The canvas has the two listeners once, and they look the label up by the target of the event. They are not removed with a label, as undo and redo take its rectangle off the canvas and put it back, and it follows again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Each rectangle label subscribed to
object:scalingandobject:movingon the canvas when it was drawn (RectangleLabelObject), and nothing unsubscribed. The two listeners stayed after the label was deleted or the canvas was cleared, so a canvas which is drawn on for long kept more of them, and each moved or scaled object ran all of them.WeakMapkeyed by the rectangle, so a label is not kept alive by them. AWeakSetof canvases tells which ones already have the listeners.RectangleLabelObject.updateis a method without the event argument, as the target check moved to the lookup.Checks
yarn format:check,yarn lint,yarn typecheckandyarn testpass (450 passing and 1 todo). The 4 new tests are intools.spec.ts:object:movingand oneobject:scalingregistration for three labels (it failed before the change, with three of each);Not checked: a real mouse drag in the showcase. The tests use a real fabric canvas and fire its events.
Notes for review
RectangleLabelObject.setTexthas no callers. It is not touched here.