(Note: I asked this question on https://github.com/gkz/LiveScript/issues/731 as well)
When I use LiveScript in an html file directly, I have no way to run livescript code immediately on seen. For example;
...
<script src="livescript.js"></script>
<div class="my_target"></div>
<script type="text/ls">
# my livescript code will interact with div.my_target
</script>
<script>
/* a javascript code that will interact with div.my_target
</script>
<script type="text/ls">
# my livescript code does something else
</script>
<script>
var LiveScript = require("LiveScript");
LiveScript.go();
</script>
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 BEFORE
If I define
<script>
var LiveScript = require("LiveScript");
LiveScript.go();
</script>
part everytime right after a LiveScript code defined, then all LiveScript codes till this definition would run more than one time.
### livescript code 1
### LiveScript.go()
...
### livescript code 2
### LiveScript.go()
...
### livescript code 3
### LiveScript.go()
...
When this code is executed:
livescript code 1will run 3 times, first will run immediately after definitionlivescript code 2will run 2 times, first will run immediately after definitionlivescript code 3will run 1 time, this will runimmediately after definition
If it would be this way, LiveScript would be used in html more easily and would be used like a native language of web development
...
<script src="livescript.js"></script>
<script>
var LiveScript = require("LiveScript");
LiveScript.doSomeMagic_Kaboooommm();
</script>
...
<script type="text/ls">
# my livescript code
</script>
... more html
<script type="text/ls">
# my livescript code
</script>
...
<script type="text/ls">
# my livescript code
</script>
...
Is there anyway to do that?
You are better off compiling the
.lsfiles to.jsand referencing the JavaScript files in your.htmlpage.The
lsclivescript compiler has options to assist with this such as thewatch(w)argument combined with thecompile(c)argument, runninglsc -wc .will watch all.lsfiles in the current directory and below and compile them whenever you make a change.For example an
src/index.lswill compile tosrc/index.js.I don't think the feature to use LiveScript inline will be supported any time soon.