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

[Feature]: Will Fabric v6 support user-defined Object properties? #9845

Open
4 tasks done
wangrongding opened this issue May 3, 2024 · 4 comments
Open
4 tasks done

Comments

@wangrongding
Copy link

CheckList

  • I agree to follow this project's Code of Conduct
  • I have read and followed the Contributing Guide
  • I have searched and referenced existing issues, feature requests and discussions
  • I am filing a FEATURE request.

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

image

Additional Context

No response

@asturur
Copy link
Member

asturur commented May 3, 2024

fabric v6 sort of supports that but the definition of types are hard to do.
This should definitely be explained in some doc.

@ouyoungs
Copy link

ouyoungs commented May 7, 2024

mean this?
https://juejin.cn/post/7153068432303325220

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']))
}

@wangrongding
Copy link
Author

I know this, I'm talking about the official api and support for Typescript type.

@asturur
Copy link
Member

asturur commented May 8, 2024

i think today you can do:

const newText = new FabricText<{ id: string } & Partial<TextProps>>('myText', {
  id: 'hello',
  fontFamily: 'Arial',
});

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants