amzn / amzn/sketch-constructor

new Layer() with existing definition results in sublayer id's being identical

Open
#35 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
543
Forks
44
PR merge metrics
No merged PRs in 30d

Description

when i create a new artboard from an existing artboard:

` const artboard = new Artboard(source_artboard);
`

only the outer layer ID is created anew; all sublayers are identical, resulting in interesting behavior within Sketch: I select a sublayer, and both that sublayer and the duplicated object's sublayer are selected.

My current workaround is creating a newObject function that will create new object Ids for each sublayer:

```
let newObject = source_obj => {
Object.keys(source_obj).forEach(key => {
if (key === "do_objectID") {
source_obj[key] = uuidv1().toUpperCase();
return source_obj;
}
if (typeof source_obj[key] === "object") {
newObject(source_obj[key]);
}
});
return source_obj;
};
```

and instead call it

` const artboard = newObject(source_artboard);
`

It'd be nice if new Artboard(source_json) would do the same. Any reason not to?

Contributor guide

Open the contributing guide

Research direction

Start by tracing the Artboard constructor with an existing artboard definition and inspect how nested objects retain their do_objectID values. Compare the resulting object tree with the recursive workaround shown in the issue; done means duplicated artboards and all sublayers have distinct IDs without requiring callers to rewrite the object.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.