2017-03-25 21:05:55 -05:00
|
|
|
//@flow
|
2017-08-05 20:38:29 -05:00
|
|
|
import { createFoodItem } from '../records/FoodItemRecord';
|
2017-04-15 15:11:22 -05:00
|
|
|
import { setById } from '../helpers/ImmutableHelpers';
|
|
|
|
|
import { Map } from 'immutable';
|
2017-08-27 14:29:37 -05:00
|
|
|
import location$ from './LocationStream';
|
2017-10-22 12:38:05 -05:00
|
|
|
import { getFoodItemsForLocation, type FoodItemsForLocation } from '../apis/FoodItemsApi';
|
2017-03-25 21:05:55 -05:00
|
|
|
|
2017-10-22 12:38:05 -05:00
|
|
|
export default location$
|
|
|
|
|
.mergeMap(pos => getFoodItemsForLocation({ pos }))
|
|
|
|
|
.map(({ fooditems = [] }: FoodItemsForLocation) => {
|
|
|
|
|
return fooditems.map(createFoodItem).reduce(setById, new Map());
|
|
|
|
|
});
|