2017-04-15 15:11:22 -05:00
|
|
|
// @flow
|
|
|
|
|
import withProps from 'recompose/withProps';
|
|
|
|
|
import mapPropsStream from 'recompose/mapPropsStream';
|
2017-07-02 17:55:00 -05:00
|
|
|
import compose from 'recompose/compose';
|
2017-04-15 15:11:22 -05:00
|
|
|
import Places$ from '../streams/PlacesStream';
|
|
|
|
|
import { path } from 'ramda';
|
|
|
|
|
|
|
|
|
|
export const withPlaces = mapPropsStream(props$ =>
|
2017-04-26 22:06:31 -05:00
|
|
|
props$.combineLatest(Places$, (props, places) => {
|
|
|
|
|
return {
|
|
|
|
|
...props,
|
|
|
|
|
places,
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|
2017-04-15 15:11:22 -05:00
|
|
|
|
|
|
|
|
export const withPlaceIdFromRoute = withProps((props: { match: { params: { id: string } } }) => {
|
2017-04-26 22:06:31 -05:00
|
|
|
const placeId = path(['match', 'params', 'id'], props);
|
|
|
|
|
return { placeId };
|
2017-04-15 15:11:22 -05:00
|
|
|
});
|
|
|
|
|
|
2017-07-02 17:55:00 -05:00
|
|
|
export const withPlace = compose(
|
|
|
|
|
withPlaces,
|
|
|
|
|
withProps(props => {
|
|
|
|
|
const { placeId, places } = props;
|
|
|
|
|
const place = places.get(placeId);
|
|
|
|
|
return {
|
|
|
|
|
...props,
|
|
|
|
|
place,
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|
2017-04-26 22:06:31 -05:00
|
|
|
|
|
|
|
|
export const withPlaceForFoodItem = mapPropsStream(props$ =>
|
|
|
|
|
props$.combineLatest(Places$, (props, places) => {
|
|
|
|
|
const placeId = props.foodItem && props.foodItem.placeId;
|
|
|
|
|
return {
|
|
|
|
|
...props,
|
2017-07-02 17:55:00 -05:00
|
|
|
place: places.get(placeId),
|
2017-04-26 22:06:31 -05:00
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|