-
-
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
feat(): Replacement for getKlass utility #8500
Conversation
Build Stats
|
Ok i have some issues with Pattern that i didn't account for ( not understand why not for Gradient then... ) i ll fix it asap. |
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 see a real difference between #8282 to this PR.
Over there I had more freedom to solve things like Gradient not having a type and I did more work to adapt fabric not to import classes, but instead call the registry (such as in enlivenObjectEnlivables
and in the elements_parser
)
} from './typedefs'; | ||
import { isWebGLPipelineState } from './typedefs'; |
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.
You can do:
import {
type TWebGLPipelineState,
type T2DPipelineState,
type TWebGLUniformLocationMap,
isWebGLPipelineState,
} from './typedefs';
@@ -220,4 +221,7 @@ export const circleDefaultValues: Partial<TClassProperties<Circle>> = { | |||
|
|||
Object.assign(Circle.prototype, circleDefaultValues); | |||
|
|||
classRegistry.setClass(Circle); | |||
classRegistry.setSVGClass(Circle); |
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.
Why 2 calls?
Why not setClass(Circle, { svg?: boolean, key?: string })
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.
Or better, why not check if fromElement
exists...
#8282
@@ -220,4 +221,7 @@ export const circleDefaultValues: Partial<TClassProperties<Circle>> = { | |||
|
|||
Object.assign(Circle.prototype, circleDefaultValues); | |||
|
|||
classRegistry.setClass(Circle); | |||
classRegistry.setSVGClass(Circle); | |||
|
|||
fabric.Circle = Circle; |
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.
Shouldn't we remove fabric assignments?
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.
yes but now would make all tests fail, no?
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.
not if we adjust the index file to use export, then rollup should build the fabric object by itself if I am not mistaken.
src/shapes/object.class.ts
Outdated
@@ -934,7 +935,7 @@ export class FabricObject< | |||
* @param {Object} object | |||
*/ | |||
_removeDefaultValues(object: Record<string, any>) { | |||
const prototype = fabric.util.getKlass(object.type).prototype; | |||
const prototype = classRegistry.getClass(object.type).prototype; |
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.
What about registering a class and it's default values in the registry?
I understand you don't want it in this PR.
i remember #8282 was huge. Let me look again |
Is hard to re-understand #8282 since now is showing diffs from an old situation, but i remember that the registry was resolving fromObject and fromElement instead that resolving the class and ther were changes to how we do fromObject and fromSVG to accomodate that. I just want to do only leaner/necessary changes now |
#8282 had a large diff for the same reason this PR does, because each file must be registered. That is it. |
take a look at I would remove the assert methods and throw in the getters. |
Motivation
fabric.util.getKlass required all the objects to be imported in a fabric global variable in order to be restored from json.
This made impossible to split the code you are not using with imports.
This small system of registering class when imported allow for building apps that require just some parts of fabricJS without importing the whole bundle.
The feature is written just with this in mind and can be extended later with more nuances ( as @ShaMan123 custom resolvers for some classes #8282 )
Description
Changes
Gist
In Action