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

What is Framer? Join the Community
Return to index
John Marstall
Posted Jun 20 - Read on Facebook

How can I store a variable in a module such that app.coffee can reference it?

@options.myVar ?= true

will be available within the module and can be overwritten during initialization, but I can't see how to query it from app.coffee afterward.

8 Comments

Brent Riddell

if you look in any new framer studio project in the modules folder there is an example module called myModule with some instructions. So for just a variable it says: exports.myVar = "myVariable" ... just remember to include your module in your main code: myModule = require "myModule" ... then you can reference it as myModule.myVar = "whatever" ... hope that helps! it's all in the example module :)

Marc Krenn

exports.myVar = true

?

Chris Camargo

Why [email protected]`? Is this part of a constructor in a class? If so, you should be able to reference it with dot notation from it's parent if you do `super @options`. Ex: `myClass.myVar`

Chris Camargo

Also, post example code if you can. Context would be helpful here.

John Marstall

Example code here. This isn't quite like myModule.coffee, as I'm using the variable within a class which extends Layer.

http://pastebin.com/VczhJFTf

Blaine Billingsley

Hey John Marstall, You can't get the value because you haven't set the "getters" and "setters" for that option to retrieve and re-write the value past initialization. Check out this example: http://share.framerjs.com/p5phnkyf8rfq/

Blaine Billingsley

I am a color-by-numbers coffeescript dude, but my lizard brain understanding is that you have to explain what to do when you ask for that option's value and what to do when you try to overwrite that option's value. Hope that helps!

Jonas Treub

Layers have a special property called "custom" where you can save whatever you want, also during construction. If you extend the Layer class you get this "custom" property for free. Else you could create your own custom data property.

Read the entire post on Facebook