2017-01-10 65 views

回答

0

除了使用庫集成,另一種解決方案是從Gun實例構建自己的Observable。看到這個codeandbox例如:https://codesandbox.io/s/pYj4OM8m1

const user$ = name => // returns a new observable 
    Observable.create(o => 
    gun.get(name).on(v => { 
     o.next(v); // passes any new values to the observers 
     console.log(v); 
    }), 
); 

// now you can do rx stuff on the stream of values 
user$('something')) 
     .map(({ name }) => ({ name: name.toUpperCase() })) 
     .filter(({ name }) => name.length > 0) 
相關問題