git ssb

1+

Matt McKegg / mutant



Tree: ba938d4692fe73ad9200093bf9c44381ab8373e1

Files: ba938d4692fe73ad9200093bf9c44381ab8373e1 / watch-all.js

636 bytesRaw
1var resolve = require('./resolve')
2var isObservable = require('./is-observable')
3
4module.exports = watchAll
5
6function watchAll (observables, listener) {
7 if (!Array.isArray(observables)) {
8 observables = [ observables ]
9 }
10
11 var releases = observables.map(bind, broadcast)
12 broadcast()
13
14 return function () {
15 releases.forEach(tryInvoke)
16 releases.length = 0
17 }
18
19 function broadcast () {
20 listener.apply(this, observables.map(resolve))
21 }
22}
23
24function bind (value) {
25 if (isObservable(value)) {
26 return value(this)
27 }
28}
29
30function tryInvoke (value) {
31 if (typeof value === 'function') {
32 return value()
33 }
34}
35

Built with git-ssb-web