Skip to content
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(controls): deprecate 🚫 SHARED 🚫 controls #7914

Closed
wants to merge 15 commits into from

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Apr 30, 2022

This PR refactors Object#controls from a shared object attached to the prototype into a unique object attached to an instance.

Motivation

#7596 (comment)
I hate the shared controls and the shared concept altogether.
It's extremely unintuitive and many issues were raised because of this. I have spoken to fabric devs and they all mentioned this.
IMO sharing instances should never be done in fabric (and maybe even at all - except for mega perf enhancements) and anyways rewriting JS to use class will and MUST deprecate this bad practice in favor of static properties/methods or simply bound properties/methods.

Gist

  • created ObjectControls, TextboxControls classes that hold the default controls.

  • controls must have an attach method - best practice is to subclass ObjectControls | TextboxControls. When migrating to TS we could/should use an abstract class to define this class that the dev will have to subclass.

  • BREAKING control API since fabricObject is no longer needed as it is referenced in the control.object

  • I have no idea why this test fails.
    image

Migration

If a dev needs to change controls across many objects they can subclass or they can pass a controls object in initialization. But it cannot be SHARED

Post PR

We should consider moving control logic from src/mixins/object_interactivity.mixin.js to ObjectControls

@ShaMan123 ShaMan123 added the v6 label Apr 30, 2022
Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 failing test - why does it fail?
1 comment

Besides this is good to go.

@@ -1002,6 +1004,9 @@
else if (key === 'shadow' && value && !(value instanceof fabric.Shadow)) {
value = new fabric.Shadow(value);
}
else if (key === 'controls') {
value.attach(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we need this because I couldn't get controls to be set in setOptions without breaking all tests

@ShaMan123 ShaMan123 changed the title refactor(controls): deprecated SHARED controls refactor(controls): deprecate 🚫**SHARED**🚫 controls Apr 30, 2022
@ShaMan123 ShaMan123 changed the title refactor(controls): deprecate 🚫**SHARED**🚫 controls refactor(controls): deprecate 🚫 **SHARED** 🚫 controls Apr 30, 2022
@ShaMan123 ShaMan123 changed the title refactor(controls): deprecate 🚫 **SHARED** 🚫 controls refactor(controls): deprecate 🚫 SHARED 🚫 controls Apr 30, 2022
@asturur
Copy link
Member

asturur commented Apr 30, 2022

I don't know custom controls works, this a change in name of best practices of which i see very little utility.
We have a TON of breaking changes, if we are not fixing anything i don't want to change this.

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented May 1, 2022

I don't know custom controls works, this a change in name of best practices of which i see very little utility.

Didn't understand

We have a TON of breaking changes, if we are not fixing anything i don't want to change this.

Absolutely. And the TS rewrite will introduce even more.
That's why I think we should release v6 with this in it because it already requires a major adjustment. Plus, once we migrate this will happen naturally. It will require a very awkward workaround to continue sharing objects between instances when written with proper classes.

actionHandler: scalingXOrSkewingY,
getActionName: scaleOrSkewActionName,
});
class ObjectControls {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are not migrating yet, this should still be the function + prototype class.

@asturur
Copy link
Member

asturur commented May 1, 2022

To be clear i see this is more polished.
I don't think the current control api is broken or terrible.
It allows you to plug in your functions.
Even if we want to move to class system, there is no need to use attach and to move render function in.
Let's mitigate the impact, we can still get rid of the shared object ( that would be mitigated anyway when you go and read how it works ) but we don't need to break the api.
I have a bunch of custom controls and they just works.

Also i have questions, if i have a control group class for each object, as soon as i want to add a single control to all objects, like a delete button, how do i do for the instantiated objects? I have to loop and reassign controls.

What is good of the current pattern is that you may have multiple control set ready to be used by object, for example:

  • locked object controls
  • cropping picture controls
  • normal controls
    And just swap them when needed.
    In this case you would have to write a class, and instantiate it each time.

I don't know custom controls works, this a change in name of best practices of which i see very little utility.

With this i meant, i don't like to fix what is not broken, in the name of this is a better practice.
Was late and i wrote hastly.

@ShaMan123
Copy link
Contributor Author

I don't think the control API is horrible at all.
I simply dislike the shared object practice. Someone new to fabric will bash their head against the wall until they understand that's the origin of what they are experiencing as did I. Numerous issues have been raised and the devs I speak to dislike it as well (dislike is a soft term).
I do think it makes sense to iterate over objects to set controls over them. Entirely on the dev.
And if I look from above it adds a logical layer to fabric that IMO should not exist.

Anyways you indulge me with the things I want/need/think are important so now it's my turn.

@stale
Copy link

stale bot commented Jun 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jun 12, 2022
@ShaMan123 ShaMan123 removed the stale Issue marked as stale by the stale bot label Jun 13, 2022
@stale
Copy link

stale bot commented Jun 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jun 28, 2022
@ShaMan123 ShaMan123 removed the stale Issue marked as stale by the stale bot label Jun 28, 2022
@stale
Copy link

stale bot commented Jul 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jul 30, 2022
@ShaMan123 ShaMan123 removed the stale Issue marked as stale by the stale bot label Aug 1, 2022
@stale
Copy link

stale bot commented Sep 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Sep 21, 2022
@ShaMan123 ShaMan123 removed the stale Issue marked as stale by the stale bot label Sep 21, 2022
@ShaMan123 ShaMan123 deleted the refactor-controls branch February 6, 2023 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants