;(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)
;
let yw=(place='tokyo')=>{
let f=encodeURIComponent
,o={format: 'json',env: 'store://datatables.org/alltableswithkeys'
,q: `select astronomy.sunset from weather.forecast where woeid in (select woeid from geo.places(1) where text="${place}")`
}
,q=Object.keys(o).map(d=>`${d}=${f(o[d])}`).join('&')
,b='https://query.yahooapis.com/v1/public/yql'
,url=`${b}?${q}`
;
return fetch(url).then(d=>d.json())
}
bell.add('sunset',yw) //add api
;
riot.tag(
`app`
,`<input onkeyup={input} value='tokyo' style={style0}></input><pre>{result}</pre>`
,function(opts){
let self=this
,f=(d=>JSON.stringify(d,null,2))
,f1=(d)=>{bell.call('sunset',d).then(d=>{ self.result=f(d)})}
this.style0='outline:none'
this.input=function(ev){ f1(ev.target.value) }
})
riot.mount('app',{})
;