-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
refactor(): _findTargetCorner
now returns the key and the control
#9668
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
3018d9c
to
80ba731
Compare
Control had a name property, at least all my fabric 5.x apps have one. |
The constructor of Control uses Object.assign, so you can probably just pass in the name and get it in the control. |
That’s true. Didn’t think about it. |
Question: |
Might be a good idea but out of the scope of this PR. I guess it'd be similar to |
im sure the name was in at some point. I think i removed it because i realized it was duplicate of the key. Changing the return of the function of the internal function is not terrible anyway. |
_findTargetCorner( | ||
pointer: Point, | ||
forTouch = false | ||
): { key: string; control: Control } | undefined { |
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.
this return type changed like 4 times in 2023
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.
Sign of bad API. If name
is re-introduced, the return type could just be : Control
, which is much better IMO.
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.
But it should also be called findTargetControl, not findTargetCorner. But anyway.
Can you add a sentence in perfect english on top of _findTargetCorner
that explains in simple words your use case for overriding.
Something like:
If you are using interactive groups, it may happen to you that the control of your outer group is preferred to the overlapping control of the inner object, if you find this annoying please consider that you can override this method in order to return the control you prefer.
If this is your use case, can you add it there that will serve as an hint when documenting but also as an hint to be careful with changes that this method is half internal half not.
I overrided it as well in the past
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.
Or add your personal use case whichever it is if is not secret
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.
But it should also be called findTargetControl
I thought about that as well, I'd honestly prefer renaming but did not want to break the API, although it's internal. But if you're okay with it I think it would make more sense.
The name is not the issue but I'd welcome the change.
The change of returned value is still necessary for me to allow overriding the method to return a Group's subTarget control. There is no reason why fabric should first call I'm not suggesting fabric should start caring about devs overriding internal methods, it's just that this seems a win-win for both. Fabric gets a simpler code, I get an overridable method "by chance" 😄 All thanks to improve return value |
Build Stats
|
_findTargetCorner
now returns the key and the control
_findTargetCorner
now returns the key and the control_findTargetCorner
now returns the key and the control - test update
_findTargetCorner
now returns the key and the control - test update_findTargetCorner
now returns the key and the control
_findTargetCorner
now returns the key and the control_findTargetCorner
now returns the key and the control - test update again
_findTargetCorner
now returns the key and the control - test update again_findTargetCorner
now returns the key and the control
_findTargetCorner
now returns the key and the control_findTargetCorner
now returns the key and the control - test update 3
_findTargetCorner
now returns the key and the control - update 8_findTargetCorner
now returns the key and the control
I fixed the action for the changelog, first try! JJhiRdcYfcokU.mp4 |
@jiayihu and @ShaMan123 if you want to merge this PR fix the unit tests or tell me you can't but you would and i ll fix the unit tests. |
@ShaMan123 do you have opinions 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.
pending @ShaMan123 review
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 also am for renaming the method
Yeah, maybe we should call it |
How about |
|
At this point changing what the method returns or what returns and how is called is the same. |
i m good with findControl but probably i don't want to touch anything else. |
I am now migrating this breaking change and I have noticed that the only usage left of The dev should be in charge of understanding what the active control is, they can look at |
updated comment |
The point of __corner, name apart, is that is precalculated by your last mouse movement and is used by developers too. |
Funny for something called |
it is like that, funny or not is exposed through the object during events |
Just like
getActiveControl
, this PR refactors_findTargetCorner
to return the Control as well. This allows to override the returned control, for instance allowing a Group to return children controls to allow "pass-through" interactions.Honestly, I believe
Control
should have akey/name
property. It's very common to need that information and havinggetActiveControl
and_findTargetCorner
return{ key: string, control: Control }
instead of justControl
is a clear sign of that.For the Control itself it's very convenient to know the key as
this.key
, for instance you may have several instances of the same Control class, but with different keys, e.g. resize controls.