aretherecookies-mobile/js/streams/QuantityStream.js

28 lines
738 B
JavaScript
Raw Normal View History

//@flow
import { ReplaySubject } from 'rxjs';
import type { QuantityResponse, QuantityFragment } from '../constants/QuantityConstants';
import { Map } from 'immutable';
const observable: ReplaySubject<QuantityResponse> = new ReplaySubject();
export function emit(val: ?QuantityResponse) {
observable.next(val);
}
// force our observable to emit an initial empty map so that food items will load
emit(null);
2020-04-17 22:50:23 -05:00
export default observable.scan(
(quantitiesByProductId: Map<string, QuantityFragment>, quantity?: QuantityResponse) => {
if (!quantity) {
return quantitiesByProductId;
}
2020-04-17 22:50:23 -05:00
return quantitiesByProductId.set(quantity.food_item_id, {
quantity: quantity.quantity,
lastupdated: quantity.date,
});
},
new Map()
);