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

What is Framer? Join the Community
Return to index
Pete Schaffner
Posted Apr 24 - Read on Facebook

Is there a way to extend default `Layer` getters/setters? In other words, it would be nice to do something like:

@define "width",
get: ->
super
# custom shtuff

22 Comments

Jordan Robert Dobson

Actually there is.

Pete Schaffner

FB posts ate my indentation :(

Jordan Robert Dobson

Yes... I did this in a module once already. I'd have to dig up... But it's possible if you extend Layer.

Pete Schaffner

Cool! Yeah, I was trying to augment `Layer#width` in my label module (https://github.com/peteschaffner/framer-label), which does indeed extend `Layer`. If you find that example and don't mind sharing, it would be greatly appreciated!

Jordan Robert Dobson

Here is how I approached it: http://jrdn.io/bq1B

Pete Schaffner

Thanks for sharing man. Unfortunately I don't see what you mentioned, as the getter/setter shown in that screenshot didn't already exist on `Layer.prototype`. I was looking for a way to extend the behavior of an existing property (in my case, `width`).

Jordan Robert Dobson

So if yout extend the layer and then do the define getter and setter it doesn't work?

Pete Schaffner

It works but I loose the original getter/setter behavior because I am overriding it at that point. I would like to maintain the behavior of `width` but add a call to update my module in other ways. So in other words:

@define "width", set: (value) ->
super value
print "I've augmented `Layer#width`"

Jordan Robert Dobson

Well you need to set: (value) for one...

Jordan Robert Dobson

This question I'm not sure about...if you want to start with writing some pseudo code example that you could share I could try to help.

Pete Schaffner

Whoops, good catch. But yeah, still no cigar. I will whip up an example. Thanks for the help Jordan Robert Dobson and Rory Smyth.

Jordan Robert Dobson

Definitely I have a few days off in between work so I'm glad to help... I just need coffee...

Jordan Robert Dobson

Were you going to put up any code?

Pete Schaffner

Hey sorry, got hung up last night :( I will link to some code later this morning!

Jordan Robert Dobson

Sounds good!

Pete Schaffner

Ok, here is an example that illustrates how re-defining `width` on my extended `Layer` class just clobbers the original getter/setter. If I was trying to extend regular old instance methods (not getters/setters), this would be trivial, as I could `super` within the "new" implementation.

http://share.framerjs.com/knop3uz68vpi/

Pete Schaffner

BTW Jordan Robert Dobson, let me know how I can get you that coffee ;)

Pete Schaffner
Jordan Robert Dobson

Crap! Completely forgot about this!!! Sorry.

Jordan Robert Dobson

Taking a look today. Thanks Pete.

Pete Schaffner

Np!

Jordan Robert Dobson

Ah... yeah... but subclassing... I wish there was a way to Monkey Patch in Coffee Script.

Read the entire post on Facebook