Comments (4)
Coming at this from the perspective of working on a parser for this spec (and have built parsers for OpenAPI previously), IMO this doesn’t make parsing any easier on its own. So if this were pursued it should be for other benefits.
The reason this doesn’t help parsing is that value
isn’t unique to groups; it’s also found on all tokens. Further, it’s impossible to infer the type from any value
, as composite types will have object values.
If we wanted to make parsing groups easier, I’d expect taking the JSON Schema approach of enforcing a unique type
on every node (in this case, type: "group"
). I think that’s been proposed before and it was decided against (unless I’m mistaken)? The value
would help in tandem with type
, but again, type: "group"
would be doing the heavy lifting being the unique identifier that says “this node is a group and could not be anything else.”
It’s worth pointing out adding value
would open up namespacing to allow more names, so in that regard this seems like an alternate proposal to #72.
from community-group.
I'm dabbling with building a DTCG file parser myself (written in TypeScript) and I'm also not convinced this change would make parsing easier.
In my case, the goal is to construct a tree of Group
and DesignToken
objects that represents the file's contents and can then be inspected and/or manipulated via an API that those objects expose. It's analogous to how an HTML or XML file is parsed into a DOM. I'm building a TOM (Token Object Model), if you will 😜
My naïve parsing algorthim is like so:
- read the file contents
- pass the contents to
JSON.parse()
- starting at the outermost object returned by the previous step (i.e. the root group), do the following:
- Check if the current object has a
$value
property. If it does, instantiate aToken
instance from the data. - Otherwise, pluck out the relevant
$...
props and instantiate aGroup
instance from those. Then iterate over the remaining properties of that object and for each one:- recursively do step 3. (i.e. instantiate a
Group
orDesignToken
from that property's data as needed) - append the new item as child of the current group
- recursively do step 3. (i.e. instantiate a
- Return the newly created
Group
orDesignToken
.
- Check if the current object has a
So, in my case, having "$type": "group"
be the thing that differentiates a group from a token (and having the child items under $value
) wouldn't really make much difference. I'd still be looping over all the child items regardless.
I'm sure other tools/parsers might use different approaches, so if someone has a case where the syntax being proposed in the OP is beneficial, I'd love to hear about it.
In the absence of that, I'm inclined to agree with @drwpow though: If we were to adopt this, it should be for other reasons.
With the recent decision to use $
as a prefix for "special" format properties, I feel we've got a good solution for future spec versions to add new properties without clashing with people's group and token names. So while this proposal could have been an alternative to that, I think that ship has sailed.
Could there be other benefits to this?
I suppose it makes the syntax for groups and tokens similar, which some may find nice. Then again it also makes the files more verbose. Either way, it's quite subjective though. Maybe we need to have a vote?
from community-group.
Style Dictionary-format token files also just consider anything with value
a token and everything else a group, and that convention has worked fine for me so far in everything I've done with tokens. I don't see a reason why checking for node.$type == "group"
is any easier than "value" in node
when writing a parser. So since the "$type": "group"
option is more verbose, my vote goes to leaving it out.
(Plus, requiring "$type": "group"
seems like it would completely block off the possibility of having tokens and groups with the same name as in #97, though having a special token name that's ignored when exporting would still work.)
from community-group.
Reviewed by the format editors on 2022-2-22
The format editors discussed this issue and feel that adding value
to a group would complicate the spec and make it harder to read and write. We don't believe there would be performance gains for parsers or translators.
Decision
We’re closing this issue for now, but may reopen it in the future if needed.
from community-group.
Related Issues (20)
- Provide "outline" token category HOT 4
- Consider using type: "$alias" for explicity
- Define how far design tokens are expected to be interoperable. HOT 1
- Remove REM/EM from specification? HOT 25
- Error in Font Weight example in spec?
- Standardizing the Handoff - Conceptual HOT 10
- Extensible Types HOT 2
- grid type HOT 6
- Specification / recommendation for custom types HOT 4
- Token Operations
- The $ property name prefix should be unnecessary with a well-structured schema HOT 10
- [Discussion]: How to transform composite tokens HOT 5
- Transition token documentation issue HOT 1
- Suggestion: colorList type for DataViz HOT 6
- Most recent edition (07/2023) missing from main page on w3c community group HOT 1
- A comment about history of design tokens HOT 2
- Type: Text alignment HOT 8
- Custom Types / Interpritations
- Is there a way to still include boolean and string type functionality? HOT 1
- Be explicit about whether or not empty groups are allowed HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from community-group.