riot.js tagの存在タイミング


on or one('mount',...) で図る。

codeMirrorのようなdocument.bodyに存在していなければフォーマットが崩れる場合、dom生成のタイミングは重要。

<script src="//gnjo.github.io/riot.js"></script>
<h1>dom exist check</h1>
<test></test>
<script type="text/plain" name="cheat-sheet">
this.one this.on this.off this.trigger:
update updated before-mount mount
before-unmount unmount
</script>

riot.tag(
 'test'
 ,`<h3 id={x} onclick={click}>{message}</h3>`
 , function(opts){
   message='click me'
   x='xxx'

   console.log('constructer',document.querySelector('#xxx')) // not join body
   this.one('mount',()=>{
    console.log('mount-ed',document.querySelector('#xxx')) //slave the body
   })
   click=function(ev){
    message = (document.querySelector('#xxx'))?'is':'not'
   }
});

//finally one;
riot.mount('test');