-
-
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
[Feature]: Will Fabric v6 support user-defined Object properties? #9845
Comments
fabric v6 sort of supports that but the definition of types are hard to do. |
mean this? let canvas = new Canvas('c')
let rect = new Rect({
width: 30,
height: 30,
top: 10,
left: 10,
my_id: 'rect01'
})
canvas.add(rect)
function handleToJSON() {
console.log(canvas.toJSON(['my_id']))
} |
I know this, I'm talking about the official api and support for Typescript type. |
i think today you can do:
But i m sure there will be some kind of hiccups here and there, is not as smooth as we want, is also hard to do because of mixins and everything. Slowly mixin will go away and hopefully will be simple |
I ended up using this so far (I'm using v 6.0.0-rc2): interface ICustomData {
entry: ...; // my custom prop
isDirty: ...; // my custom prop
}
// custom PathProps
interface IMyPathProps extends TOptions<PathProps> {
customData: ICustomData;
}
// custom Path with custom data based on fabric Path
export class MyPath extends Path<IMyPathProps> {
customData!: ICustomData;
}
// using:
fabricCanvas.add(
new MyPath("M 0,0 ..." , {
fill: 'transparent',
customData: { // TS does type checking here
entry: ...
isDirty: ...,
},
}),
);
// or:
const path = fabricCanvas.getActiveObject() as MyPath;
console.log(path?.customData); |
#10071 |
I am having issues with properly typing classes that are extending from Group. |
I forgot about that mixin there. I think we should make it Generic |
I played a bit with it and while Props and SProps can still be made generic, i don't think eventSpec can. |
I guess at least passing Props and SProps is better than nothing |
hm, it is still not really working |
Yes is not fixable as it is today. I'll probably try to resort to the older method in which the methods were copied over the class at runtime and i will duplicate the declarations only. But is time consuming. For now the best thing you can do is just use the extend on the actual group and use declare and the constructor to add all of your props. I checked your examples, where is that you are having issues with those? What is not working? |
CheckList
Description
Will Fabric v6 support user-defined Object properties?
For example, when I want to create an element, I can embed an Id in the object for convenient future use. Currently, Fabric v5 does not support this due to ts type restrictions, so I am currently using Object.assign to merge the ID with the target object.
Current State
Additional Context
No response
The text was updated successfully, but these errors were encountered: