Passing data thru RxJs operators -
while learning rxjs came problem. start operator chain object , use ooe of it's properties ajax request using flatmap need other object's properties passed along ajax result. came following solution, i'm sure there must way more elegant or efficient solution it. idea on how improve code?
function fbinfo(ezfb){ const fbitems$ = rx.observable.from(lista) .map(item => object.assign( {}, item, {query: `/${item.page}/feed?limit=1`})) .do(x=>console.log(x)) .flatmap(item => { return rx.observable.frompromise(ezfb.getloginstatus().then((res)=>{return ezfb.api(item.query)})) .withlatestfrom(rx.observable.from([item]),(res, it)=> object.assign({}, res, it)) }).map(item => { return { mensaje: item.data[0].message, id: item.data[0].id, created: item.data[0].created_time, nombre: item.nombre } }) return fbitems$ }
thanks in advance :)
in terms of general patterns, know of no cleaner way carrying want keep through each step (as have). in terms of specific syntax, yes, there shorter ways express want. awkward => { return { ... } }
syntax can replaced => ({ ... })
. unless need properties on root of same object, away object.assign
. flow of data same.
Comments
Post a Comment