UNPKG

fluorine-orchestra

Version:
36 lines (27 loc) 801 B
/* eslint prefer-rest-params: 0 */ import invariant from 'invariant' import { Observable } from 'rxjs' import isObservable from 'fluorine-lib/lib/util/isObservable' export default function combineStores(stores) { invariant( typeof stores === 'object', 'combineStores: `stores` is expected to be an object containing Observables.') const keys = Object.keys(stores) return Observable.combineLatest( ...keys.map(key => { const store = stores[key] invariant( isObservable(store), 'combineStores: `stores` is expected to contain Observables only.') return store }), (...args) => { const state = {} args.forEach((arg, index) => { const key = keys[index] state[key] = arg }) return state } ) }