0

Is there a way to traverse through masterComponents without having an instance in the document first?

Also, will a component's UUID change when the component is updated, and will that UUID be the same across all consumers of that component?

  • Did you manage to find an answer? It looks like componentId doesn't match id of the master component in the file where this component from. I believe component key stored in components collection should be used somehow but I didn't find a way how to use it. – Andrew Sep 03 '20 at 00:23
  • Obviously it's key from /v1/teams/{teamId}/components, just realized that I missed part of documentation – Andrew Sep 03 '20 at 00:40
  • @Andrew see below: https://stackoverflow.com/a/65187150/2907961 – thenoobinator Dec 07 '20 at 18:15

1 Answers1

0

Figured it out. Wrote a utility function for it

export function traverse(node: any) {
    if ("children" in node) {
        if (node.type !== "INSTANCE") {
            for (const child of node.children) {
                traverse(child)
                if (child.mainComponent) {
                    console.log(`name: ${child.mainComponent.name}`)
                    console.log(`key: ${child.mainComponent.key}`)
                }
            }
        }
    }
}
  • Good idea, but it looks like a call to the API endpoint `/v1/teams/{teamId}/components` do pretty the same, so you don't need to traverse the whole document. – Andrew Dec 07 '20 at 19:57
  • @Andrew for sure. I found the above code extremely useful when building the plugin based on components already in the design files, especially when we have a large design library. The API endpoint would be just as verbose and take as long as traversing the whole document. – thenoobinator Dec 09 '20 at 12:54