-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Replace BaseFabricObject with FabricObject #9016
Conversation
d2ec103
to
bd24528
Compare
Added minor fix so that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to fix this, but it should be made into a generic (one day at least)
For now it is good enough since there is no option to use the base object
This is ok till we don't have better code splitting and tree shaking, but i agree it should be a generic |
To answer the question |
You need to add a changelog line. |
We can try that now before merging |
I have tried making it generic but we are facing yet another TS limitation. |
@asturur a note not for now: |
That's a good use case, but yeah I don't have any idea other than maybe creating artificial different classes like: class Collection<T extends BaseFabricObject> {
getObjects(): T[];
}
class BaseGroup<T extends BaseFabricObject> extends Collection<T> {}
// the common interactive one
class Group extends BaseGroup<FabricObject> {} |
Since I know you are for less subclassing this is not good enough for you, nor for fabric. As I see it, this is no working around the fact that TS is not providing us what we need here. |
I haven't tried but maybe
If I understand correctly, in that case you should be fine having the type
As discussed together, it's definitely a tough spot the combo static analysis and dynamic behaviours. Anyway, if there are no alternatives, are you fine with this PR that at least makes TS work in the most common case of interactive objects? |
Yes sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asturur any objections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed onDeselect
since it is an interactive object always.
Updated collection events to reflect the changes made in the PR.
And tweaked TToCanvasElementOptions
for future use
Other usages that seem fine as is but might cause trouble as well:
src/util/misc/objectTransforms.ts
src/util/typeAssertions.ts
sendObjectToPlane
@@ -4,7 +4,7 @@ import type { | |||
TPointerEventInfo, | |||
} from '../../EventTypeDefs'; | |||
import { Point } from '../../Point'; | |||
import type { FabricObject } from '../Object/Object'; | |||
import type { FabricObject } from '../Object/FabricObject'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used only by onDeselect
@@ -44,6 +43,7 @@ import { | |||
} from '../util/typeAssertions'; | |||
import { StaticCanvasDOMManager } from './DOMManagers/StaticCanvasDOMManager'; | |||
import type { CSSDimensions } from './DOMManagers/util'; | |||
import type { FabricObject } from '../shapes/Object/FabricObject'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this actually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it will be solved when we manage to type Collection
Collection is a mixin, which means it is created statically.
Class generics are dynamic, bound to the instance.
Meaning that TS doesn't allow us to type a mixin with generics.
Hence, we can't pass a generic type (e.g. the object type) to the collection w/o a lot of ugly workarounds.
Since using BaseFabricObject is not possible for now we have removed it from Collection and other types to make our lives easier.