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

What is Framer? Join the Community
Return to index
Fran Pérez
Posted Jan 09 - Read on Facebook

Hi all!

Do you know if it's possible to reference a layer created in app.coffee from a Class in a .module?

20 Comments

Rohan K

Johannes Eckert sorry to dig up old skeletons, I'm running into a similar problem, did you ever find a solution to your problem? I would really like to get my module to have the same scope as app.coffee

Johannes Eckert

Rohan K woha, really old skeletons. No idea to this. However, it's more or less basic JavaScript scoping, but I am not particularly more clever now than last time. However, I tend to attach everything to window just to make things easier. Don't tell a software engineer, though

Rohan K

haha, fair enough...i am doing the same thing.. let's keep this under wraps :P

Jordan Robert Dobson

It's possible... Are you getting errors?

Should a module really know / care about things outside the module though?

Zoltan Ray

Maybe this isn't best practice, but attach your layers or variables to the window object?

Fran Pérez

It's throwing the error: [framer.modules.js] ReferenceError: Can't find variable: myLayer

Example: http://share.framerjs.com/r1b5fx55oh0h/

Zoltan Ray

Instantiated your class in a function and attached the layer to the window object: http://share.framerjs.com/t9gsmfuvgv2c/

Fran Pérez

Thanks Zoltan :)

Do you think there is a cleaner way?

Zoltan Ray

Maybe could replace the module with js via Utils.domLoadScriptSync and lose the function

Jordan Robert Dobson

Why don't you just pass that layer to your module so its scope knows about it?

Fran Pérez

Jordan, how?

Jordan Robert Dobson

How do you currently use your module?

Nir Benita

There are a number of ways to do this, one of which would be to extract that variable into it's own module, and then require it in both app.coffee and your module

Koen Bok

Or set it in window (make it a global). Then you module can just access it.

Fran Pérez

Thanks. I'll try both :)

Jordan Robert Dobson

Does your module have a class? Or is it more code with similar structure to app.coffee?

Fran Pérez

Jordan, yes. It has a class. I posted yesterday this example: http://share.framerjs.com/r1b5fx55oh0h/

Jordan Robert Dobson

Oh! I missed that.

Okay well you would call a method from that class and pass in your layer to it so it's aware of it and store it in the scope of the module.

I can take a look in about 2 hours. :)

Johannes Eckert

I have to work on a macbook air currently, and at around 500 lines of code in app.coffee, saving and rendering takes between 1 and 3 seconds and is really painful. I am looking for a way to just separate my code out into single chunks that should compile quicker. For that, these "modules" should act as they were part of app.coffee. I would like not to worry about scope.

Jordan Robert Dobson

That makes sense Johannes Eckert. Completely. I've been there.

Read the entire post on Facebook