mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 09:44:55 -06:00
make POST requests to /quantity to update the quantity of an existing food item - then mixin the new quantity with the existing food items observable
24 lines
729 B
JavaScript
24 lines
729 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((quantitiesByFoodItemId: Map<string, QuantityFragment>, quantity?: QuantityResponse) => {
|
|
if (!quantity) {
|
|
return quantitiesByFoodItemId;
|
|
}
|
|
|
|
return quantitiesByFoodItemId.set(quantity.food_item_id, {
|
|
quantity: quantity.quantity,
|
|
lastupdated: quantity.date,
|
|
});
|
|
}, new Map());
|