ceremcem
ceremcem

Reputation: 4360

How to make LiveScript scripts immediately .go() on seen?

(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:

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?

Upvotes: 2

Views: 107

Answers (1)

Sphvn
Sphvn

Reputation: 5353

You are better off compiling the .ls files to .js and referencing the JavaScript files in your .html page.

The lsc livescript compiler has options to assist with this such as the watch(w) argument combined with the compile(c) argument, running lsc -wc . will watch all .ls files in the current directory and below and compile them whenever you make a change.

For example an src/index.ls will compile to src/index.js.

I don't think the feature to use LiveScript inline will be supported any time soon.

Upvotes: 0

Related Questions