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): WIP - Convert utils #8123

Merged
merged 21 commits into from
Aug 14, 2022
Merged

chore(ts): WIP - Convert utils #8123

merged 21 commits into from
Aug 14, 2022

Conversation

asturur
Copy link
Member

@asturur asturur commented Aug 4, 2022

This will be a partial conversion of utils, i will stop at the misc file and review/merge.
All together is a mess, but luckily we can also swap the imports at that point.

* @param {TRadian} radians value in radians
* @return {TDegree} value in degrees
*/
export const radiansToDegrees = (radians: TRadian): TDegree => (radians / PiBy180) as TDegree;
Copy link
Contributor

Choose a reason for hiding this comment

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

beautiful

let value = 1;
if (angle < 0) {
// sin(-a) = -sin(a)
value = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

make a const?

Suggested change
value = -1;
value = Math.sign(angle);

Copy link
Member Author

Choose a reason for hiding this comment

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

i always forget about Math.sign

@asturur asturur changed the title chore(ts): Convert utils chore(ts): WIP - Convert utils Aug 5, 2022
@asturur
Copy link
Member Author

asturur commented Aug 8, 2022

i know what i broke, i ll try to fix it today.
I messed up the imports/exports

@asturur
Copy link
Member Author

asturur commented Aug 10, 2022

@ShaMan123 i had to revert a couple of imports.
The color class importing some util and the animate color util importing the color class was creating a circular dependency.

* @param {*} value
* @return {Array} original array
*/
export const removeFromArray = (array: any[], value: any): any[] => {
Copy link
Member Author

Choose a reason for hiding this comment

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

i m sure there is a way to tell Typescript that the returned array is the same type of the input array

Copy link
Contributor

Choose a reason for hiding this comment

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

Generic types

Suggested change
export const removeFromArray = (array: any[], value: any): any[] => {
export function removeFromArray<T>(array: T[], value: T): T[] {

Copy link
Member Author

Choose a reason for hiding this comment

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

and of course T can be a mix of types. ( even if in our case often isn't )

Copy link
Member Author

Choose a reason for hiding this comment

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

fat arrows aren't good for TS as functions?

@asturur
Copy link
Member Author

asturur commented Aug 10, 2022

Ok something broke with the import system and i had to patch it. I have no idea why.

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.

Regarding the circular import
I have seen it as well and managed to fix it in a different way without reverting
Try importing utils directly and not from the util index OR make animate_color or whatever a module (even as a hack).
That should fix it.
rollup seems to be a decent tool

@@ -1,6 +1,7 @@
//@ts-nocheck
(function(global) {
var fabric = global.fabric;
console.log(fabric)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi!

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah i was investigating why fabric was undefined

@github-actions
Copy link
Contributor

github-actions bot commented Aug 10, 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.06 |    74.54 |   84.42 |   80.66 |                                               
 fabric.js |   82.06 |    74.54 |   84.42 |   80.66 | ...,27459,27517,27527-27571,27679,27766,27970 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123
Copy link
Contributor

ShaMan123 commented Aug 10, 2022 via email

* @param {Point} to
* @returns {Point} vector
*/
export const createVector = (from: IPoint, to: IPoint): Point => new Point(to).subtract(from);
Copy link
Member Author

Choose a reason for hiding this comment

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

i don't get this. if the type was Point , way we changed it to interface? we expect devs to use points or objects with x/y?

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right
I committed it and felt the same
Reverr this
And safeguard createVector instead

@asturur
Copy link
Member Author

asturur commented Aug 11, 2022

note for later self: const foo = <T,>(x: T) => x;

@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 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.06 |    74.54 |   84.42 |   80.66 |                                               
 fabric.js |   82.06 |    74.54 |   84.42 |   80.66 | ...,27459,27517,27527-27571,27679,27766,27970 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 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.51 |   84.42 |   80.64 |                                               
 fabric.js |   82.05 |    74.51 |   84.42 |   80.64 | ...,27458,27516,27526-27570,27678,27765,27969 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 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.11 |    74.57 |   84.42 |   80.71 |                                               
 fabric.js |   82.11 |    74.57 |   84.42 |   80.71 | ...,27458,27516,27526-27570,27678,27765,27969 
-----------|---------|----------|---------|---------|-----------------------------------------------

@asturur asturur merged commit 93a7847 into master Aug 14, 2022
@asturur asturur deleted the convert-utils-to-es6 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: ShaMan123 <shacharnen@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.

2 participants