Skip to content

Instantly share code, notes, and snippets.

@isaacw
Last active March 5, 2018 20:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isaacw/9c643e7b3f77c34d56192b5784dc7cc2 to your computer and use it in GitHub Desktop.
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.
# 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)
@davo
Copy link

davo commented Mar 5, 2018

Hey Isaac, thanks, this is a super clever way to keep my code tidy.

I made a quick mod adding two things I needed:

  • Filter layers (using '_').
  • Camel case the layer name.

Layer.createChildrenRefs.coffee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment