Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to separate the javascript code from the tag file in Riot Js?

I would like to know if it is possible to do something like:

<todo>
    <div class="greetings">Hello, world!</div>

    <script src="/path/to/my/file.js"></script>
</todo>

The tag would keep the view (html) while the js code stays in a different file:

  • todo.tag (html/css)
  • todo.js
like image 355
Fernando Gabrieli Avatar asked Mar 14 '23 15:03

Fernando Gabrieli


1 Answers

To give an alternative to the mixin solution, here is another way of splitting up your markup from your logic.

Take a look at this Plunker (a colleague of mine wrote this). The key part is the way you reference the tag function. <script>todoTag.call(this, this.opts);</script>. In this case, the todoTag is a global function. But nothing stops you from name spacing that function or use some form of module loading.

From the plunker:

todo.tag.html:

<todo>
    <!-- your markup -->
    <script>todoTag.call(this, this.opts);</script>
</todo>

todo.tag.js:

function todoTag(opts) {
    // your logic
}
like image 147
Peter Goes Avatar answered Apr 26 '23 02:04

Peter Goes