Files: 5d3463a5a812931815b799819ca80c8f2119bda2 / src / plugins / source_observer.js
679 bytesRaw
1 | var SourceObserver = {}; |
2 | var pull = require('pull-stream') |
3 | import Rx from 'rxjs/RX' |
4 | import { Observable } from 'rxjs/Observable' |
5 | |
6 | // safe nul checking thing |
7 | const nn = require('nevernull'); |
8 | |
9 | |
10 | SourceObserver.install = function(Vue, options){ |
11 | var observers = { |
12 | accumulated_observable(source){ |
13 | return Rx.Observable.create(function (observer) { |
14 | pull( |
15 | source, |
16 | pull.drain(msg => observer.next(msg)) |
17 | ) |
18 | }).scan((accumulator, newMsg) => [nn(newMsg), ...accumulator], []) |
19 | }, |
20 | cb_obs(f, args){ |
21 | return Rx.Observable.bindCallback(f)(args) |
22 | } |
23 | } |
24 | |
25 | Vue.prototype.$observers = observers; |
26 | }; |
27 | |
28 | export default SourceObserver; |
29 |
Built with git-ssb-web