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

Force users to use FabricObject instead of Object、FabricImage instead of Image、FabricText instead of Text #9172

Merged
merged 18 commits into from
Sep 26, 2023

Conversation

zhe-he
Copy link
Contributor

@zhe-he zhe-he commented Aug 23, 2023

Object is a keyword. Force users to use FabricObject instead of Object

@ShaMan123
Copy link
Contributor

we have discussed this.
Image and Text are the same
you should do what you did when you import fabric
But I am not against renaming

fabric.ts Outdated
export { FabricObject as Object } from './src/shapes/Object/FabricObject';
import { FabricObject } from './src/shapes/Object/FabricObject';
/** @deprecated Object is a keyword. Please use FabricObject instead */
class Object extends FabricObject { };
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be const Object = FabricObject otherwise this adds a runtime class level in the hierarchy

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also?

export { FabricObject, FabricObject as Object }

@zhe-he zhe-he changed the title Force users to use fabricObject instead of object Force users to use FabricObject instead of Object、FabricImage instead of Image、FabricText instead of Text Aug 24, 2023
@ShaMan123
Copy link
Contributor

ShaMan123 commented Aug 24, 2023

I suggest we hear from @asturur
The problem might be inconsistency.
Now we have FabricText and IText - weird
After that you should make tests pass

npm run lint -- --fix
npm run test:jest -- -u
npm test -- -a

@asturur
Copy link
Member

asturur commented Aug 24, 2023

I'm fine with the double export as long as it appears as deprecated in IDEs that support JSDOCS, if to have them appear deprecated visually we need to create a new class, go for it.

Initially i though people could just do import as, but then after doing it myself a couple of weeks i have seen this coming.
I understand the naming inconsistency, if you come up with better names for Text and Image go for it, i don't have strong opinions.

Image => Picture ?
Text => Paragrap ?

Text and Image are stronger for me, so i see them better even with the Fabric prefix in front

classRegistry.setClass(FabricImage);
classRegistry.setSVGClass(FabricImage);

/** @deprecated Image is a keyword. Please use FabricImage instead */
Copy link
Member

Choose a reason for hiding this comment

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

i would extend this:

WARNING the old fabric.Image class can't be imported as Image because of a reserved word clash.
For this reason it has been renamed to FabricImage. Please use FabricImage in place of Image.

classRegistry.setClass(Image);
classRegistry.setSVGClass(Image);
classRegistry.setClass(FabricImage);
classRegistry.setSVGClass(FabricImage);
Copy link
Member

Choose a reason for hiding this comment

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

What happens to JSON exports old and new? <--- this is important.

@zhe-he
Copy link
Contributor Author

zhe-he commented Aug 25, 2023

There are not many names left for us. If for brevity, can we just add F in front?
Image -> FImage ?
Text -> FText ?
Because we still have Itext TextBox, if the text is renamed a lot, how can the two be compatible?
I don't have any great ideas, if you decide which name to use that can accommodate Itext, textbox at the same time, please let me know and I will submit

@ShaMan123
Copy link
Contributor

I do not like it but we can rename to StaticText like StaticCanvas
Object can become BaseObject
Image... Img
All very ugly

@asturur
Copy link
Member

asturur commented Aug 25, 2023

if we don't have ideas FabricText and FabricImage are all ok.
But still i don't know, what happens to FabricImage.type ? what happens to exports and registry?
in case we have to change the getter and fix the registration

@ShaMan123
Copy link
Contributor

We moved away from type being the class name because of minifying, right?
So it shouldn't be a problem, should it?
It has the same static type = 'type' so it should be fine.
But tests are failing

@asturur
Copy link
Member

asturur commented Aug 26, 2023

anyway as soon as test passes we are good to go since we don't have groundbreaking names

@asturur
Copy link
Member

asturur commented Aug 26, 2023

Gave a stab at fixing tests, i can't run test locally because of M1pro, including the browser, so i did by gut feeling

@asturur
Copy link
Member

asturur commented Aug 26, 2023

If you are ok with class names this is fine for me.
I extended the deprecation notice to be as clear as possible.

asturur
asturur previously approved these changes Aug 26, 2023
asturur
asturur previously approved these changes Aug 28, 2023
asturur
asturur previously approved these changes Aug 28, 2023
Copy link
Contributor

@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.

Do we want to rename the files as well?

* For this reason it has been renamed to FabricImage.
* Please use `import { FabricImage }` in place of `import { Image as FabricImage }`
*/
export class Image extends FabricImage {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these 3 should reside in the main fabric.ts file and not in the def files

@asturur
Copy link
Member

asturur commented Aug 30, 2023

Do we want to rename the files as well?

for me no, i just learned the order of the new files in the tree

asturur
asturur previously approved these changes Aug 30, 2023
@asturur
Copy link
Member

asturur commented Aug 30, 2023

ok do not know how to fix jest now

@zhe-he
Copy link
Contributor Author

zhe-he commented Sep 1, 2023

it's OK now for jest.

asturur
asturur previously approved these changes Sep 10, 2023
asturur
asturur previously approved these changes Sep 10, 2023
@asturur
Copy link
Member

asturur commented Sep 10, 2023

Leaving this to you guys, you had some open topic on those names.

@asturur
Copy link
Member

asturur commented Sep 18, 2023

Is there any other decision to make on this PR? or is good as it is?

asturur
asturur previously approved these changes Sep 26, 2023
@asturur
Copy link
Member

asturur commented Sep 26, 2023

@zhe-he @ShaMan123 i don't understand if you still have some internal discussion here or if we are done

@ShaMan123
Copy link
Contributor

Nope

@asturur asturur merged commit 23430b1 into fabricjs:master Sep 26, 2023
22 of 24 checks passed
@fabricjs fabricjs deleted a comment from ragul0417 Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants