Last active
May 21, 2018 08:45
-
-
Save swilgosz/a8c0fe0481ffddf2c370d750d91622ae to your computer and use it in GitHub Desktop.
This is the approach we have in our legacy JS/Coffee files. We are going to use webpacker in one of our projects and we do want to know which solution is best to achieve the same effect.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/assets/javascripts/application.js | |
#=require 'foo' | |
# app/assets/javascripts/foo.coffee | |
init: -> | |
console.log('this is function defined in foo') | |
@Foo = { foo_func } | |
# app/views/partials/foo_partial.slim | |
# some code that needs foo script to work. | |
javascript: | |
Foo.init() | |
#Reason: Load one precompiled JS file (application) on the first page load. | |
#Then call proper functions, trigger events and DOM listeners ONLY when visiting the proper view. | |
#Question: What is current best approach to achieve the same thing? (ideally using webpacker, keen to see code snippets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment