Last active
March 5, 2018 20:20
-
-
Save isaacw/9c643e7b3f77c34d56192b5784dc7cc2 to your computer and use it in GitHub Desktop.
Creates convenience refs on targeted layers from the design tab so that we don't have to use Layer::childrenWithName.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Layer::createChildrenRefs | |
# Creates convenience refs on targetd layers from the design tab so that we don't have to use Layer::childrenWithName. | |
# Pass recursive=true to do this for all descendant layers while maintaining hierarchy. | |
Layer::createChildrenRefs = (recursive=false) -> | |
for layer in @children | |
# Get layer name for the key | |
key = layer.name | |
# Set reference | |
@[key] = layer | |
# Should we also do this for current layer's children? | |
if recursive and layer.children.length > 0 | |
layer.createChildrenRefs(recursive) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Isaac, thanks, this is a super clever way to keep my code tidy.
I made a quick mod adding two things I needed:
Layer.createChildrenRefs.coffee