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

What is Framer? Join the Community
Return to index
Chad Lonberger
Posted Jan 31 - Read on Facebook

Question about precompiling coffeescript and including it in index.html... currently I've defined and precompiled classes into classes.js (via Koala). It is being loaded correctly (check the print statements in the screenshot) but I'm unable to instantiate classes from within app.coffee in studio (check ReferenceError in lower left). Any ideas? Thanks in advance everyone.

16 Comments

Jordan Robert Dobson

I'm very curious about this as well. I have a lot of classes I've created I no longer touch but I've been putting off moving them out of my code. :/

Mike Feldstein

take a look at the compiled coffeescript, often it scopes everything locally. If this is the problem you can get around it by compiling it with the -bare flag, or you can define it like `class @Test` to make it global

Mike Feldstein

*compiled javascript from the coffeescript

Jordan Robert Dobson

Utils.domLoadScriptSync(url string)

Isn't that supposed to load stuff in? I heard there were problems with it though.

Mike Feldstein

Regardless of how you load it, if the coffee script is compiled in a scope it won't be accessible to your main scripy

Jordan Robert Dobson

So you're saying define your classes like

Class @ClassNameGlobal

...if you want separate files to access each other?

Andy Jakubowski

Jordan, Mike is right, prefix your class name with "@" when defining it to have it available globally. Further explanation: http://justinreid.com/coffeescript-global-classes/

Jordan Robert Dobson

Makes sense. So @ClassName is just like window.ClassName nice.

Chad Lonberger

Worked like a charm, Mike Feldstein to the rescue from CR! Thanks

Jordan Robert Dobson

Thanks guys. Check that off the list to dig into.

Mike Feldstein

I'm not in costa rica anymore now im in pismo beach :)

Joey Lamelas

Silly question: Where would you put the .coffee file and do you have to use Utils.domLoadScriptSync?

Chad Lonberger

Hey Joey Lamelas, I dumped it into a separate classes folder in the framer project and have Koala watching that folder to automatically compile the classes.js as updates occur. Then you need to edit index.html to include the compiled classes.js (see line 20 from index.html in the screenshot).

Chad Lonberger

One thing to note, the latest studio doesn't reload index.html on refresh so you'll have to close and reopen the project after making the edits to index.html

Chad Lonberger

Since you guys were savvy on this one, you may know an answer to a similar question: https://www.facebook.com/groups/framerjs/632880596839015/

Chad Lonberger

Btw, thanks to Jordi Martinez Ortega for sharing Koala/this approach a few months back.

Read the entire post on Facebook