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(TS): migrate gradient #8154

Merged
merged 50 commits into from Aug 26, 2022
Merged

chore(TS): migrate gradient #8154

merged 50 commits into from Aug 26, 2022

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Aug 18, 2022

READY

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.

RESULTS on chrome
visual.txt
unit.txt

CI has gone mad saying everything fails

READY on my end

UPDATE
This seemed to be the problem a5c48f5
So useful that error logs point to nothing actionable

src/gradient/gradient.class.ts Show resolved Hide resolved
src/gradient/gradient.class.ts Show resolved Hide resolved
src/gradient/gradient.class.ts Outdated Show resolved Hide resolved
src/gradient/gradient.class.ts Show resolved Hide resolved
src/parser/percent.ts Outdated Show resolved Hide resolved
@ShaMan123 ShaMan123 requested a review from asturur August 18, 2022 16:21
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.04 |    74.65 |   84.52 |   80.64 |                                               
 fabric.js |   82.04 |    74.65 |   84.52 |   80.64 | ...,27409,27467,27477-27521,27629,27716,27920 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.03 |    74.62 |   84.52 |   80.63 |                                               
 fabric.js |   82.03 |    74.62 |   84.52 |   80.63 | ...,27409,27467,27477-27521,27629,27716,27920 
-----------|---------|----------|---------|---------|-----------------------------------------------

NaN || value === value
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.

  • renamed GradientValue => GradientCoordValue
  • offsetX/Y = 0 class default value
  • src/gradient/constants.ts - default coord values
  • 378ab72 - safegurad colorStops from mutation
  • removed ifNaN - I found out that (NaN || value) === value But that is not enough because of 0

@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.04 |    74.65 |   84.52 |   80.64 |                                               
 fabric.js |   82.04 |    74.65 |   84.52 |   80.64 | ...,27409,27467,27477-27521,27629,27716,27920 
-----------|---------|----------|---------|---------|-----------------------------------------------

// svg goes from internal to external radius. if radius are inverted, swap color stops.
colorStops.reverse(); // mutates array
colorStops.forEach(colorStop => {
colorStop.offset = 1 - colorStop.offset;
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 argue this is a mutation too.
As it was in the old code and i wonder how it does not break the code gradient after an svg export.
i will try to write a tests that make this fail, and then fix it.

i think the safest one would be:
colorStops = colorStops.map((colorStop) => ({ ...colorStop, offset: 1 -colorStop.offset }))

Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 25, 2022

Choose a reason for hiding this comment

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

As it was in the old code and i wonder how it does not break the code gradient after an svg export.

I agree.

i would argue this is a mutation too.

Disagree since colorStops is a local copy, see assignment with concat

Copy link
Member

Choose a reason for hiding this comment

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

is still mutation because colorStops is a local copy of the array, not of the object contained inside. Those are still references to the original objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh shit

Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 26, 2022

Choose a reason for hiding this comment

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

Why didn't you commit? OK #8196

Comment on lines +84 to +88
this.type = type;
this.gradientUnits = gradientUnits;
this.gradientTransform = gradientTransform || null;
this.offsetX = offsetX;
this.offsetY = offsetY;
Copy link
Member

Choose a reason for hiding this comment

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

ok so is there any reason why we want to specify those manually while before we weren't?

Coords and colorStops make sense, but the rest i would rather assign or take the default from class declaration.

constructor({
    coords,
    colorStops = [],
    id,
    ...restOfOptions,
  }: GradientOptions<T>) {

....
Object.assign(this, restOfOptions)

why going for the explicit way?

Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 25, 2022

Choose a reason for hiding this comment

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

I don't have a good reason

Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 25, 2022

Choose a reason for hiding this comment

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

accept that it keeps junk passed down in options out of the class

Copy link
Member

Choose a reason for hiding this comment

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

is exactly what we do with objects on the otherside.
We allow devs to pass id, name, and other things they may want to use.
For me it needs to be clarified, not blocked

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 disagree and TS will disagree as well.
This is the exact use case of a subclass.
Stricter js is part of modern js.
It's how I see it.

@asturur
Copy link
Member

asturur commented Aug 24, 2022

I have one outstanding comment, all the rest seems good to me.
The more restrictive percentage check for text and gradients does not seem to work well when running coverage

@ShaMan123
Copy link
Contributor Author

I have one outstanding comment, all the rest seems good to me. The more restrictive percentage check for text and gradients does not seem to work well when running coverage

Because the test actually fails, see #8168. Something weird is happening with text and gradients/patterns. Sometimes it renders perfectly and sometimes it renders nothing.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.05 |    74.69 |   84.43 |   80.67 |                                               
 fabric.js |   82.05 |    74.69 |   84.43 |   80.67 | ...-27584,27700-27701,27722-27763,27778-27937 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.04 |    74.66 |   84.43 |   80.66 |                                               
 fabric.js |   82.04 |    74.66 |   84.43 |   80.66 | ...-27584,27700-27701,27722-27763,27778-27937 
-----------|---------|----------|---------|---------|-----------------------------------------------

@asturur asturur merged commit 16f5bcb into master Aug 26, 2022
@asturur asturur deleted the ts-gradient2 branch September 11, 2022 23:03
frankrousseau pushed a commit to cgwire/fabric.js that referenced this pull request Jan 6, 2023
Co-authored-by: Andrea Bogazzi <andreabogazzi79@gmail.com>
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.

None yet

2 participants