-
Notifications
You must be signed in to change notification settings - Fork 857
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(Vectorizer): add option to support camel case attributes #2339
feat(Vectorizer): add option to support camel case attributes #2339
Conversation
Why not enabled it by default? 🤔 Maybe perf concerns? |
Would not that be a breaking change? e.g. if someone used the camel case attributes on purpose. vel.attr('myAttribute', 5);
vel.node.getAttribute('myAttribute') // => null The plan is to release it as an experimental feature as part of the upcoming patch release. |
But that change will be merged into v4, which will introduce breaking changes anyways, right? Or maybe I assumed (wrongly) that it will do so just because it's a major version? |
No. It will be included in |
@@ -1378,6 +1381,83 @@ const V = (function() { | |||
return xml; | |||
}; | |||
|
|||
const _attributeNames = Object.create(null); |
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.
Do we need to use a null-prototype object here? It can apparently lead to unexpected behavior, which may be problematic (e.g. if a customer tries to modify the list of attributes for which not to split camel-case).
I think we should be able to use a normal object here, since we are then using a Proxy object anyways to specify the custom getter (line 1444).
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 problems specifically?
This:
V('rect', { toString: true }).node
Should produce:
<rect to-string="true"/>
And it would not if we define _attributeNames
as {}
.
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'm not questioning that part, but my point is that the {}
which would be used as a replacement would be a normal Object (i.e. with an Object prototype) - so if using that is okay, then it should be okay to say const _attributes = {}
on this line by default, as well.
Examples of potential problems of using null-prototype objects according to the MDN link:
- An object with a null prototype can behave in unexpected ways, because it doesn't inherit any object methods from Object.prototype. This is especially true when debugging, since common object-property converting/detecting utility functions may generate errors, or lose information (especially if using silent error-traps that ignore errors).
- The main problem problem is with missing
toString
,valueOf
,hasOwnProperty
functions and theconstructor
property
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.
Added a comment explaining why we use an object without prototype.
Note It's a private variable and can not be accessed from outside.
PR allows to use of both kebab-case and camel-case attribute names when setting/reading/removing attributes to/from SVGNodes.
The feature needs to be enabled with
V.supportCamelCaseAttributes = true;
.