Is there a cleaner way to do this? To have one state, and assign layers to it?
Something like this...
layers = 
for i in [0..3] layer = new Layer width: 200 height: 200 backgroundColor: Utils.randomColor() y: 200 * i
layer.states.add hide: opacity: 0
for layer, i in layers layer.onClick -> @.stateCycle("hide", "default")
Here the project: https://framer.cloud/SfiNv
Array with a loop perhaps or a map :)
for the elements you want to share the state, group them up in sketch without anything else. Then you can loop over the groups children directly.
for child in sketch.groupName.children child.states = hide: opacity: 1
Or this, but I'd also go with grouping as Mike said.
you can just make your own array, no need to do all this complicated stuff with grouping...
layersToHide = [sketch.$1, sketch.$2, etc]for layer in layersToHide..layer.states.hide =....opacity: 1