New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make livescript scripts immediately .go() on seen? #731
Comments
The only way I could find is:
|
Maybe you should consider moving your inline scripts to files and precompiling them. I don't think it would be possible at all to intercept the loading of script tags. the |
If your browser supports MutationObservers, you can include the mutation-summary library and add this (untested) code before any LiveScript scripts: # Obviously this needs transpiled
# Get the dependency (we need it synchronously)
elem = document.createElement 'script'
elem.src = '//raw.githubusercontent.com/rafaelw/mutation-summary/master/src/mutation-summary.js'
elem.async = false
document.currentScript.parentNode.insertBefore elem, document.currentScript
# Create the observer
new MutationSummary do
queries: [element: 'script[type="text/ls"]']
callback: (.0.added.forEach !-> LiveScript.run it.text) Don't add And FWIW, @chisui has a point in that it is probably better to precompile them. (Edit: fix to not add to |
I'm going to close this because I accepted the precompilation method is the appropriate way to go. Thanks. |
When I use LiveScript in an html file directly, I have no way to run livescript code immediately on seen. For example;
The LiveScript codes both will run, but the LiveScript code that interacts with
div.my_target
will interact with it AFTER the javascript code does, not BEFOREIf I define
part everytime right after a LiveScript code defined, then all LiveScript codes till this definition would run more than one time.
When this code is executed:
livescript code 1
will run 3 times, first will run immediately after definitionlivescript code 2
will run 2 times, first will run immediately after definitionlivescript code 3
will run 1 time, this will runimmediately after definitionIf it would be this way, LiveScript would be used in html more easily and would be used like a native language of web development
Is there anyway to do that?
The text was updated successfully, but these errors were encountered: