This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Rohan K
Posted Aug 18 - Read on Facebook

I'm at my wits end, I need help.... I need to observe changes to the ".custom" property of a layer. Ideally, I would like to be able create a completely custom property on a layer (just the one layer, not the entire layer class) and observe that for changes. Any ideas?


Eelco Lempsink

Hey Rohan, this is indeed tricky. The reason is a bit complex, but I’ll try to explain. I expect you’re using the “custom” property as an object that has properties itself. You can modify this object, *without* having to set it again on the layer. For example, you can do:

layer.custom = {}
layer.custom.a = 10
layer.custom.b = 20

Setting a and b, will *not* change custom on layer, it will only change the *contents* of custom. That’s why you won’t get a call to change handlers (for example `layer.on "change:custom", ->`)

Now, to solve your problem: it’s not as elegant, but a pragmatic way to do it is to create a helper function that does the check and updates the value. For example, for custom.a, this could be:

updateCustomA = (layer, value) ->
oldValue = layer.custom.a
layer.custom.a = value
layer.emit "change:custom.a" if oldValue != value

This means you can still listen to the changes for the layers it’s relevant for. And if you need multiple custom values, you could definitely also generalize the function above a bit more to also handle the key of the custom property.

I hope this helps! :)

Rohan K

hmmm, that makes a lot of sense. I found a workaround for now by approaching the problem from another angle, which actually worked out to be better for me. i am still using the custom property though, but not as an object. that's actually a really good tip that i might still incorporate for better readability. Thanks for the tip Eelco Lempsink!!

Read the entire post on Facebook