mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 09:44:55 -06:00
26 lines
872 B
JavaScript
26 lines
872 B
JavaScript
// @flow
|
|
import { buildPlaceRecord } from '../records/PlaceRecord';
|
|
import { Map } from 'immutable';
|
|
import { foodItemsRaw$ } from './FoodItemsStream';
|
|
import { getPlaceDetails } from '../apis/PlaceDetailsApi';
|
|
import { memoize } from 'ramda';
|
|
|
|
/**
|
|
* return a promise of a place details object
|
|
* if already requested return existing promise
|
|
* swallow exceptions so as not to break the stream
|
|
*/
|
|
const safeGetPlaceDetails = memoize(placeId => {
|
|
return getPlaceDetails(placeId).catch(error => {
|
|
console.log(error); // eslint-disable-line no-console
|
|
return {};
|
|
});
|
|
});
|
|
|
|
const uniquePlaceIds$ = foodItemsRaw$.map(foodItem => foodItem.placeId).distinct();
|
|
|
|
const placeRecords$ = uniquePlaceIds$.mergeMap(safeGetPlaceDetails).map(buildPlaceRecord).distinct();
|
|
|
|
export default placeRecords$.scan((accMap, place) => {
|
|
return accMap.set(place.id, place);
|
|
}, new Map());
|