Skip to content

Instantly share code, notes, and snippets.

@thenormalsquid
Created December 8, 2016 18:40
Show Gist options
  • Save thenormalsquid/7bb4db13feac96638bf2d8b688b7ffdd to your computer and use it in GitHub Desktop.
Save thenormalsquid/7bb4db13feac96638bf2d8b688b7ffdd to your computer and use it in GitHub Desktop.
example usage of reselect
import React, { PropTypes } from 'react';
import { compose } from 'recompose';
import { withStyles, onMount, connect } from '_util/HOCs';
import { FlexBox } from '@madmobilenpm/mmui';
import AppView from 'view';
import { getGroupedFulfillments, getFulfillmentById } from '_redux/selectors';
import * as actions from 'actions/fulfillment';
import FulfillmentList from 'components/fulfillment/FulfillmentList';
import FulfillmentOrderHeader from 'components/fulfillment/FulfillmentOrderHeader';
import ProductList from 'components/fulfillment/ProductList';
type Props = {
props?: void,
groupedFulfillments: { [key: string]: FulfillmentMethod },
unfulfilledCount: number
};
type WrappedProps = {
styles: Styles
} & Props;
const componentStyles = ({ theme: { colors } }) => ({
container: {}
});
export const FulfillmentContainer: Component<WrappedProps> = ({ styles, groupedFulfillments, unfulfilledCount, setSelected, selectedFulfillment }) =>
<AppView title="Fulfillment">
<FlexBox align="stretch" flex="1 1 auto">
{selectedFulfillment.orderDetails ?
<FlexBox column align="stretch" flex>
<FulfillmentOrderHeader orderDetails={selectedFulfillment.orderDetails} />
<ProductList products={selectedFulfillment.orderDetails.products} />
</FlexBox> :
<FlexBox column align="center" justify="center" flex>
It looks like you haven't selected a fulfillment method
</FlexBox>
}
<FulfillmentList
setSelected={setSelected}
groupedFulfillments={groupedFulfillments}
unfulfilledCount={unfulfilledCount}
selectedId={selectedFulfillment.id} />
</FlexBox>
</AppView>;
export const enhancer = compose(
connect(state => ({
groupedFulfillments: getGroupedFulfillments(state).toJS(),
unfulfilledCount: state.app.config.modules.fulfillment.badgeCount,
selectedFulfillment: getFulfillmentById(state, state.fulfillment.selectedId).toJS()
}),
actions),
onMount(props => {
props.loadFulfillmentCount();
props.getFulfillmentList();
}),
withStyles(componentStyles)
);
const WrappedComponent: Component<Props> = enhancer(FulfillmentContainer);
export default WrappedComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment