Skip to content

Instantly share code, notes, and snippets.

View Ledoux's full-sized avatar

Erwan Ledoux Ledoux

View GitHub Profile
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),
function mapStateToProps(state, ownProps) {
const {
match: {
params: { offerId }
}
} = ownProps;
return {
offer: selectOfferById(state, offerId),
stocks: selectStocksByOfferId(state, offerId)
};
import { mergeData, requestData } from "redux-saga-data";
function mapDispatchToProps(dispatch, ownProps) {
return {
requestGetOffer: () => {
const {
match: {
params: { offerId }
}
} = ownProps;
...
dispatch(
requestData({
apiPath: `/offers/${offerId}`,
normalizer: {
stocks: "stocks"
}
})
);
...
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({
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);
{
"id": "F5UQ",
"name": "Projets Rencontre - salle du Clous Brest",
"stocks": [
{ "available": 5, "id": "K3EQ" },
{ "available": 5, "id": "KYSA" },
]
}