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

chore(): Reorder defaults for fabric object + patch setRelativeXY #9474

Merged
merged 18 commits into from
Dec 29, 2023

Conversation

gloriousjob
Copy link
Contributor

@gloriousjob gloriousjob commented Nov 3, 2023

Motivation

Original idea was move fabric object constructor tests into jest. This revealed that the test was testing for a property that FabricObject doesn't even have and led to moving properties for that into InteractiveFabricObject, which did have them. Also created brief constructor test for InteractiveFabricObject for property in that class.

Description

Move InteractiveFabricObject defaults to its proper file so as not to have defaults not typed to FabricObject assigned. Re-arrange the remaining properties by class name and order in the class.

Changes

  • Move InteractiveObject defaults to its file
  • Reorder defaults for fabric object by the class name and how the class has the properties ordered
  • Move object constructor qunit tests to jest
  • Move FX_DURATION to straighten since that's the only thing using it and it's in the parking lot
  • Move colorProperties to static

- Move InteractiveObject defaults to its file
- Move constructor qunit tests to jest
- Move FX_DURATION to straighten since that's the only thing using it
@gloriousjob
Copy link
Contributor Author

gloriousjob commented Nov 3, 2023

I was curious what migrating some of the tests from qunit to jest might reveal because of my previous PR. Let me know if this makes sense or is a bit much (i.e., you don't want tests moved over or properties may not have a good order anyway).

@asturur
Copy link
Member

asturur commented Nov 3, 2023

This is not wrong imho, but since i don't want to scroll the page up and down and check properties one by one, before adding this i will add a test in master that checks that the end result will be the same.

In general there is an issue with reordering things:

  • useless diffs
  • tainted history ( when did we change this file last time? 3 days ago? oh no it was just an alphabetical sort... )

so in general i m against diffs in pr that are done for example to reorder imports.

@gloriousjob
Copy link
Contributor Author

gloriousjob commented Nov 3, 2023

This is not wrong imho, but since i don't want to scroll the page up and down and check properties one by one, before adding this i will add a test in master that checks that the end result will be the same.

In general there is an issue with reordering things:

  • useless diffs
  • tainted history ( when did we change this file last time? 3 days ago? oh no it was just an alphabetical sort... )

so in general i m against diffs in pr that are done for example to reorder imports.

I understand not wanting to reorder so you don't add history you don't want (and you have to go somewhere else anyway to find the default so may not matter that the order is different). What do you think about moving the defaults that aren't in fabric object?

Also about migrating tests?

The migration revealed that selectable isn't a part of fabric object but the test was passing because the default is being crammed into there, even though it's a property of a subclass. I can redo the branch and keep the original order but I think the owndefaults should represent what they are. Alternatively, I could have the interactive object's defaults in default values.ts to keep the defaults together but in separate objects so the owndefaults for interactive object is correct.

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.

I also understand the diff point
However if we keep it contained to a standalone PR is it so bad
The other side of this point is we don't want to keep the code nt tidy just because of the diff.
The import order for me is a pain. But I let go of it.
Reordering makes sense because:

  1. The migration was incremental so cleanup is needed, all development is actually
  2. For accessibility of the code. We know how it is built, but the community doesn't and it makes it harder to contribute

src/shapes/Object/defaultValues.ts Show resolved Hide resolved
src/shapes/Object/defaultValues.ts Outdated Show resolved Hide resolved
src/shapes/Object/InteractiveObject.ts Outdated Show resolved Hide resolved
src/shapes/Object/defaultValues.ts Outdated Show resolved Hide resolved
src/shapes/Object/defaultValues.ts Outdated Show resolved Hide resolved
@ShaMan123
Copy link
Contributor

migrating tests is welcome

@asturur
Copy link
Member

asturur commented Nov 12, 2023

i m adding the test in master so we can merge this if the test pass

@asturur
Copy link
Member

asturur commented Nov 12, 2023

@gloriousjob there is some nasty merge conflict. can you fix it?

@asturur
Copy link
Member

asturur commented Nov 12, 2023

ok maybe i solved the conflict

@asturur
Copy link
Member

asturur commented Nov 12, 2023

I added the test and merged master in, i let the discussion on the best ordering to you guys.
Choose one and don't touch it for long time after.

- also make colorProperties static
@gloriousjob
Copy link
Contributor Author

gloriousjob commented Nov 15, 2023

I added the test and merged master in, i let the discussion on the best ordering to you guys.
Choose one and don't touch it for long time after.

Thanks! I'll work with @ShaMan123 for now. Not saying we'll get to the perfect place but hopefully better. Also, I would've fixed the master merge but fine for now. Only thing was trying to change the name of the test suite to match the file.

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.

I pushed a few commits instead of explaining myself (that would take longer and would be less effiecient in all manners)
Hope you are OK with that
Should we export all these types to the consumer or just the final aggregated types?

src/shapes/Object/AnimatableObject.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

We can have a defaults in each file and export from here a spread of all

export const defualtValues = {
  ...fillDefaults,
  ...strokeDefaults,
 ...transformDefaults
}

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer it because it seems more orderly and easy to maintain/find/navigate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern there would be that the PR was opened so that we could separate the properties of the base Object from the InteractiveObject so that unit tests would work correctly because of correct class encapsulation. Should transformDefaults include the interactive defaults or just be the ones in the base Object?
Also, what about other properties (e.g., is paintFirst a fill or a stroke property? Does objectCaching fall into any of these categories)?

I also got the impression that @asturur liked everything together so orderly may depend on the beholder (although I lean towards your view, @ShaMan123).

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a matter a taste, let's try to wrap this up.
paintFirst belongs to rendering props if we have something like that.
Regarding transform props, good point.

Copy link
Contributor

Choose a reason for hiding this comment

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

paintFirst belongs to rendering props if we have something like that.

Maybe next to objectCaching

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I’ll leave this alone due to the separation, but you’re welcome to provide a commit as long as it keeps the separation (it kind of would make more sense being in their files since that’s supposed to be the pattern).

The only other thing I’d like in this PR would be to rename the FabricObject in object.ts to BaseObject. This would reduce some confusion on which class is being referenced (the base object versus the one people use from the library). I understand why it was renamed since it’s not good practice to name a class something that JavaScript has as a keyword but duplicating another name seems just as bad. I’ll let you guys decide how to resolve this comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

That should be done in a separate PR
I am merging
Good job, glorious ;)

src/shapes/Object/Object.spec.ts Outdated Show resolved Hide resolved
src/shapes/Object/ObjectGeometry.ts Show resolved Hide resolved
@ShaMan123
Copy link
Contributor

Can you rebase/update from master?

ShaMan123
ShaMan123 previously approved these changes Dec 29, 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.

This is already a lot better

@ShaMan123 ShaMan123 changed the title Reorder defaults for fabric object chore(): Reorder defaults for fabric object + patch setRelativeXY Dec 29, 2023
@ShaMan123
Copy link
Contributor

Can you add a changelog entry? Then I can merge.
I changed computer and I am not sure how to push to the PR anymore... previously I used GitHub desktop for that.

@gloriousjob
Copy link
Contributor Author

Not sure if I did it right but just checked in an additional line. I tried to make it match the lines around it.

@ShaMan123 ShaMan123 merged commit e9f5963 into fabricjs:master Dec 29, 2023
20 of 22 checks passed
@gloriousjob gloriousjob deleted the reorder-fabric-object-defaults branch August 10, 2024 17:55
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.

3 participants