This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "id": "F5UQ", | |
| "name": "Projets Rencontre - salle du Clous Brest", | |
| "stocks": [ | |
| { "available": 5, "id": "K3EQ" }, | |
| { "available": 5, "id": "KYSA" }, | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { applyMiddleware, combineReducers, createStore } from "redux"; | |
| import thunk from "redux-thunk"; | |
| import { createDataReducer } from "redux-thunk-data"; | |
| const storeEnhancer = applyMiddleware(thunk.withExtraArgument({ rootUrl: "https://foo.com" })); | |
| const rootReducer = combineReducers({ data: createDataReducer() }); | |
| const store = createStore(rootReducer, storeEnhancer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { applyMiddleware, combineReducers, createStore } from "redux"; | |
| import createSagaMiddleware from "redux-saga"; | |
| import { all } from "redux-saga/effects"; | |
| import { createDataReducer, watchDataActions } from "redux-saga-data"; | |
| const sagaMiddleware = createSagaMiddleware(); | |
| const storeEnhancer = applyMiddleware(sagaMiddleware); | |
| function* rootSaga() { | |
| yield all([ | |
| watchDataActions({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| dispatch( | |
| requestData({ | |
| apiPath: `/offers/${offerId}`, | |
| normalizer: { | |
| stocks: "stocks" | |
| } | |
| }) | |
| ); | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { mergeData, requestData } from "redux-saga-data"; | |
| function mapDispatchToProps(dispatch, ownProps) { | |
| return { | |
| requestGetOffer: () => { | |
| const { | |
| match: { | |
| params: { offerId } | |
| } | |
| } = ownProps; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mapStateToProps(state, ownProps) { | |
| const { | |
| match: { | |
| params: { offerId } | |
| } | |
| } = ownProps; | |
| return { | |
| offer: selectOfferById(state, offerId), | |
| stocks: selectStocksByOfferId(state, offerId) | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const selectStocksByOfferId = createSelector( | |
| state => state.data.stocks, | |
| state, offerId => offerId, | |
| (stocks, offerId) => stocks && stocks.filter(stock => stock.offerId === offerId) | |
| ) | |
| function mapStateToProps(state, ownProps) { | |
| const { match: { params: { offerId } } } = ownProps | |
| return { | |
| offer: selectOfferById(state, offerId), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| class Offer extends Component { | |
| componentDidMount () { | |
| const { dispatch, match: { params: { offerId } } } = this.props | |
| dispatch(requestData({ | |
| apiPath: `/offers/${offerId}`, | |
| normalizer: { | |
| stocks: 'stocks' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createSelector } from 'reselect' | |
| const selectOfferById = createSelector( | |
| state => state.data.offers, | |
| (state, offerId) => offerId, | |
| (offers, offerId) => (offers || []).find(offer => offer.id === offerId) | |
| ) | |
| export default selectOfferById |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const OfferContainer = compose( | |
| withRouter, | |
| connect( | |
| mapStateToProps, | |
| mapDispatchToProps | |
| ) | |
| )(Offer); |
NewerOlder