aretherecookies-mobile/js/enhancers/placeEnhancers.js

43 lines
990 B
JavaScript
Raw Normal View History

// @flow
import withProps from 'recompose/withProps';
import mapPropsStream from 'recompose/mapPropsStream';
2017-07-02 17:55:00 -05:00
import compose from 'recompose/compose';
import Places$ from '../streams/PlacesStream';
import { path } from 'ramda';
export const withPlaces = mapPropsStream(props$ =>
props$.combineLatest(Places$, (props, places) => {
return {
...props,
places,
};
})
);
export const withPlaceIdFromRoute = withProps((props: { match: { params: { id: string } } }) => {
const placeId = path(['match', 'params', 'id'], props);
return { placeId };
});
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,
};
})
);
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),
};
})
);