riot.js tag間の連携
callerを登録して解決する。
reactは双方向だが、vueやriotは片方向なので、全体を横通しにするモジュールが必要。
bell.add('xyz',(obj)=>{this.obj=obj; this.update()})
bell.call('xyz',obj);
;(function(root){
var o={bells:{}}
o.add=async function(name,caller){return o.bells[name]=caller}
o.call=async function(name,obj){return (o.bells[name])?o.bells[name](obj):null}
root.bell=o
})(this)
;
全部
<script src="https://gnjo.github.io/riot.js"></script>
<count></count>
<loop></loop>
;(function(root){
var o={bells:{}}
o.add=async function(name,caller){return o.bells[name]=caller}
o.call=async function(name,obj){return (o.bells[name])?o.bells[name](obj):null}
root.bell=o
})(this)
;
riot.tag(`count`
,'<progress max={max} value={value} title={value}></progress>'
,'progress{position:fixed;top:0;left:0;width:50rem}'
,function(opt){
let self=this; max=30;value=0;
//self mean... escape the strong bind
bell.add('countnew',function(d){ value=d; self.update()})
})
riot.mount('count')
;
riot.tag(`loop`
,`<ul>
<li onclick={click}>+</li>
<li each="{item in items}">{item}</li>
<li onclick={del}>-</li>
</ul>`
,function(opt){
items=[0]
click=function(ev){
items.splice(items.length,0,items.length)
bell.call('countnew',items.length)
}
del=function(ev){
items.splice(-1,1)
bell.call('countnew',items.length)
}
})
riot.mount('loop')
;
Author And Source
この問題について(riot.js tag間の連携), 我々は、より多くの情報をここで見つけました https://qiita.com/HadaGunjyo/items/7c1f584e7752f87ffbe8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .