mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 07:14:55 -06:00
27 lines
738 B
JavaScript
27 lines
738 B
JavaScript
//@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);
|
|
|
|
export default observable.scan(
|
|
(quantitiesByProductId: Map<string, QuantityFragment>, quantity?: QuantityResponse) => {
|
|
if (!quantity) {
|
|
return quantitiesByProductId;
|
|
}
|
|
|
|
return quantitiesByProductId.set(quantity.food_item_id, {
|
|
quantity: quantity.quantity,
|
|
lastupdated: quantity.date,
|
|
});
|
|
},
|
|
new Map()
|
|
);
|