mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Remove redux-saga and all unused actions in marketplaceData.duck
This commit is contained in:
parent
20f263a7d7
commit
e2955bfa13
7 changed files with 7 additions and 188 deletions
|
|
@ -29,7 +29,6 @@
|
|||
"react-sortable-hoc": "^0.6.1",
|
||||
"redux": "^3.6.0",
|
||||
"redux-form": "^6.6.1",
|
||||
"redux-saga": "^0.14.4",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"sanitize.css": "^5.0.0",
|
||||
"sharetribe-scripts": "0.9.2",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import React from 'react';
|
||||
import { renderShallow } from '../../util/test-helpers';
|
||||
import { fakeIntl } from '../../util/test-data';
|
||||
import { call, put, fork, takeEvery } from 'redux-saga/effects';
|
||||
import { types } from '../../util/sdkLoader';
|
||||
import { SearchPageComponent } from './SearchPage';
|
||||
import reducer, {
|
||||
|
|
|
|||
|
|
@ -1,49 +1,17 @@
|
|||
/* eslint-disable no-constant-condition */
|
||||
import { call, put, take, fork } from 'redux-saga/effects';
|
||||
import { updatedEntities, denormalisedEntities } from '../util/data';
|
||||
|
||||
const requestAction = actionType => params => ({ type: actionType, payload: { params } });
|
||||
|
||||
const successAction = actionType => data => ({ type: actionType, payload: data });
|
||||
|
||||
const errorAction = actionType => error => ({ type: actionType, payload: error, error: true });
|
||||
|
||||
// ================ Action types ================ //
|
||||
|
||||
export const SHOW_LISTINGS_REQUEST = 'app/sdk/SHOW_LISTINGS_REQUEST';
|
||||
export const SHOW_LISTINGS_SUCCESS = 'app/sdk/SHOW_LISTINGS_SUCCESS';
|
||||
export const SHOW_LISTINGS_ERROR = 'app/sdk/SHOW_LISTINGS_ERROR';
|
||||
|
||||
export const QUERY_LISTINGS_REQUEST = 'app/sdk/QUERY_LISTINGS_REQUEST';
|
||||
export const QUERY_LISTINGS_SUCCESS = 'app/sdk/QUERY_LISTINGS_SUCCESS';
|
||||
export const QUERY_LISTINGS_ERROR = 'app/sdk/QUERY_LISTINGS_ERROR';
|
||||
|
||||
export const SEARCH_LISTINGS_REQUEST = 'app/sdk/SEARCH_LISTINGS_REQUEST';
|
||||
export const SEARCH_LISTINGS_SUCCESS = 'app/sdk/SEARCH_LISTINGS_SUCCESS';
|
||||
export const SEARCH_LISTINGS_ERROR = 'app/sdk/SEARCH_LISTINGS_ERROR';
|
||||
|
||||
export const SHOW_MARKETPLACE_REQUEST = 'app/sdk/SHOW_MARKETPLACE_REQUEST';
|
||||
export const SHOW_MARKETPLACE_SUCCESS = 'app/sdk/SHOW_MARKETPLACE_SUCCESS';
|
||||
export const SHOW_MARKETPLACE_ERROR = 'app/sdk/SHOW_MARKETPLACE_ERROR';
|
||||
|
||||
export const SHOW_USERS_REQUEST = 'app/sdk/SHOW_USERS_REQUEST';
|
||||
export const SHOW_USERS_SUCCESS = 'app/sdk/SHOW_USERS_SUCCESS';
|
||||
export const SHOW_USERS_ERROR = 'app/sdk/SHOW_USERS_ERROR';
|
||||
|
||||
export const ADD_ENTITIES = 'app/sdk/ADD_ENTITIES';
|
||||
const SHOW_LISTINGS_SUCCESS = 'app/sdk/SHOW_LISTINGS_SUCCESS';
|
||||
const ADD_ENTITIES = 'app/sdk/ADD_ENTITIES';
|
||||
|
||||
// ================ Reducer ================ //
|
||||
|
||||
const initialState = {
|
||||
// Error instance placeholders for each endpoint
|
||||
showListingsError: null,
|
||||
queryListingsError: null,
|
||||
searchListingsError: null,
|
||||
showMarketplaceError: null,
|
||||
showUsersError: null,
|
||||
// Database of all the fetched entities.
|
||||
entities: {},
|
||||
searchPageResults: [],
|
||||
};
|
||||
|
||||
const merge = (state, apiResponse) => {
|
||||
|
|
@ -53,50 +21,11 @@ const merge = (state, apiResponse) => {
|
|||
};
|
||||
};
|
||||
|
||||
const searchResults = payload => payload.data.data.map(listing => listing.id);
|
||||
|
||||
export default function marketplaceDataReducer(state = initialState, action = {}) {
|
||||
const { type, payload } = action;
|
||||
switch (type) {
|
||||
case SHOW_LISTINGS_REQUEST:
|
||||
return { ...state, showListingsError: null };
|
||||
case SHOW_LISTINGS_SUCCESS:
|
||||
return merge(state, payload);
|
||||
case SHOW_LISTINGS_ERROR:
|
||||
console.error(payload); // eslint-disable-line
|
||||
return { ...state, showListingsError: payload };
|
||||
|
||||
case QUERY_LISTINGS_REQUEST:
|
||||
return { ...state, queryListingsError: null };
|
||||
case QUERY_LISTINGS_SUCCESS:
|
||||
return merge(state, payload);
|
||||
case QUERY_LISTINGS_ERROR:
|
||||
console.error(payload); // eslint-disable-line
|
||||
return { ...state, queryListingsError: payload };
|
||||
|
||||
case SEARCH_LISTINGS_REQUEST:
|
||||
return { ...state, searchListingsError: null };
|
||||
case SEARCH_LISTINGS_SUCCESS:
|
||||
return { ...merge(state, payload), searchPageResults: searchResults(payload) };
|
||||
case SEARCH_LISTINGS_ERROR:
|
||||
console.error(payload); // eslint-disable-line
|
||||
return { ...state, searchListingsError: payload };
|
||||
|
||||
case SHOW_MARKETPLACE_REQUEST:
|
||||
return { ...state, showMarketplaceError: null };
|
||||
case SHOW_MARKETPLACE_SUCCESS:
|
||||
return merge(state, payload);
|
||||
case SHOW_MARKETPLACE_ERROR:
|
||||
console.error(payload); // eslint-disable-line
|
||||
return { ...state, showMarketplaceError: payload };
|
||||
|
||||
case SHOW_USERS_REQUEST:
|
||||
return { ...state, showUsersError: null };
|
||||
case SHOW_USERS_SUCCESS:
|
||||
return merge(state, payload);
|
||||
case SHOW_USERS_ERROR:
|
||||
console.error(payload); // eslint-disable-line
|
||||
return { ...state, showUsersError: payload };
|
||||
|
||||
case ADD_ENTITIES:
|
||||
return merge(state, payload);
|
||||
|
|
@ -146,89 +75,10 @@ export const getEntities = (marketplaceData, entityRefs) => {
|
|||
|
||||
// ================ Action creators ================ //
|
||||
|
||||
// All the action creators that don't have the {Success, Error} suffix
|
||||
// take the params object that the corresponding SDK endpoint method
|
||||
// expects.
|
||||
|
||||
// SDK method: listings.show
|
||||
export const showListings = requestAction(SHOW_LISTINGS_REQUEST);
|
||||
export const showListingsSuccess = successAction(SHOW_LISTINGS_SUCCESS);
|
||||
export const showListingsError = errorAction(SHOW_LISTINGS_ERROR);
|
||||
|
||||
// SDK method: listings.query
|
||||
export const queryListings = requestAction(QUERY_LISTINGS_REQUEST);
|
||||
export const queryListingsSuccess = successAction(QUERY_LISTINGS_SUCCESS);
|
||||
export const queryListingsError = errorAction(QUERY_LISTINGS_ERROR);
|
||||
|
||||
// SDK method: listings.search
|
||||
export const searchListings = requestAction(SEARCH_LISTINGS_REQUEST);
|
||||
export const searchListingsSuccess = successAction(SEARCH_LISTINGS_SUCCESS);
|
||||
export const searchListingsError = errorAction(SEARCH_LISTINGS_ERROR);
|
||||
|
||||
// SDK method: marketplace.show
|
||||
export const showMarketplace = requestAction(SHOW_MARKETPLACE_REQUEST);
|
||||
export const showMarketplaceSuccess = successAction(SHOW_MARKETPLACE_SUCCESS);
|
||||
export const showMarketplaceError = errorAction(SHOW_MARKETPLACE_ERROR);
|
||||
|
||||
// SDK method: users.show
|
||||
export const showUsers = requestAction(SHOW_USERS_REQUEST);
|
||||
export const showUsersSuccess = successAction(SHOW_USERS_SUCCESS);
|
||||
export const showUsersError = errorAction(SHOW_USERS_ERROR);
|
||||
|
||||
export const addEntities = apiResponse => ({
|
||||
type: ADD_ENTITIES,
|
||||
payload: apiResponse,
|
||||
});
|
||||
|
||||
// ================ Worker sagas ================ //
|
||||
|
||||
function* callEndpoint(sdkMethod, success, error, action) {
|
||||
const params = action.payload.params;
|
||||
try {
|
||||
const response = yield call(sdkMethod, params);
|
||||
yield put(success(response));
|
||||
} catch (e) {
|
||||
yield put(error(e));
|
||||
}
|
||||
}
|
||||
|
||||
// ================ Watcher sagas ================ //
|
||||
|
||||
// TODO: Think about structuring this file to avoid repetition without
|
||||
// too much metaprogramming that makes the code harder to understand.
|
||||
const endpoints = {
|
||||
[SHOW_LISTINGS_REQUEST]: {
|
||||
method: sdk => sdk.listings.show,
|
||||
success: showListingsSuccess,
|
||||
error: showListingsError,
|
||||
},
|
||||
[QUERY_LISTINGS_REQUEST]: {
|
||||
method: sdk => sdk.listings.query,
|
||||
success: queryListingsSuccess,
|
||||
error: queryListingsError,
|
||||
},
|
||||
[SEARCH_LISTINGS_REQUEST]: {
|
||||
method: sdk => sdk.listings.search,
|
||||
success: searchListingsSuccess,
|
||||
error: searchListingsError,
|
||||
},
|
||||
[SHOW_MARKETPLACE_REQUEST]: {
|
||||
method: sdk => sdk.marketplace.show,
|
||||
success: showMarketplaceSuccess,
|
||||
error: showMarketplaceError,
|
||||
},
|
||||
[SHOW_USERS_REQUEST]: {
|
||||
method: sdk => sdk.users.show,
|
||||
success: showUsersSuccess,
|
||||
error: showUsersError,
|
||||
},
|
||||
};
|
||||
|
||||
export function* watchSdk(sdk) {
|
||||
const requestTypes = Object.keys(endpoints);
|
||||
while (true) {
|
||||
const action = yield take(requestTypes);
|
||||
const { method, success, error } = endpoints[action.type];
|
||||
yield fork(callEndpoint, method(sdk), success, error, action);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
20
src/index.js
20
src/index.js
|
|
@ -13,22 +13,13 @@
|
|||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { createInstance, types } from './util/sdkLoader';
|
||||
import { ClientApp, renderApp } from './app';
|
||||
import configureStore from './store';
|
||||
import { matchPathname } from './util/routes';
|
||||
import * as sample from './util/sample';
|
||||
import createRootSaga from './sagas';
|
||||
import config from './config';
|
||||
import { authInfo } from './ducks/Auth.duck';
|
||||
import {
|
||||
showListings,
|
||||
queryListings,
|
||||
searchListings,
|
||||
showMarketplace,
|
||||
showUsers,
|
||||
} from './ducks/marketplaceData.duck';
|
||||
import { fetchCurrentUser } from './ducks/user.duck';
|
||||
import routeConfiguration from './routesConfiguration';
|
||||
|
||||
|
|
@ -66,16 +57,13 @@ if (typeof window !== 'undefined') {
|
|||
const sdk = createInstance({ clientId: config.sdk.clientId, baseUrl: config.sdk.baseUrl });
|
||||
const store = configureStore(sdk, initialState);
|
||||
|
||||
store.runSaga(createRootSaga(sdk));
|
||||
setupStripe();
|
||||
render(store);
|
||||
|
||||
// Expose stuff for the browser REPL
|
||||
const actions = bindActionCreators(
|
||||
{ showListings, queryListings, searchListings, showMarketplace, showUsers },
|
||||
store.dispatch
|
||||
);
|
||||
window.app = { config, sdk, sdkTypes: types, actions, store, sample, routeConfiguration };
|
||||
if (config.dev) {
|
||||
// Expose stuff for the browser REPL
|
||||
window.app = { config, sdk, sdkTypes: types, store, sample, routeConfiguration };
|
||||
}
|
||||
}
|
||||
|
||||
// Export the function for server side rendering.
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
import { watchSdk } from './ducks/marketplaceData.duck';
|
||||
|
||||
const createRootSaga = sdk =>
|
||||
function* rootSaga() {
|
||||
yield [watchSdk(sdk)];
|
||||
};
|
||||
|
||||
export default createRootSaga;
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
/* eslint-disable no-underscore-dangle */
|
||||
import { createStore, applyMiddleware, compose } from 'redux';
|
||||
import createSagaMiddleware, { END } from 'redux-saga';
|
||||
import thunk from 'redux-thunk';
|
||||
import createReducer from './reducers';
|
||||
|
||||
|
|
@ -9,9 +8,7 @@ import createReducer from './reducers';
|
|||
* middleware and enhancers.
|
||||
*/
|
||||
export default function configureStore(sdk, initialState = {}) {
|
||||
const sagaMiddleware = createSagaMiddleware();
|
||||
|
||||
const middlewares = [thunk.withExtraArgument(sdk), sagaMiddleware];
|
||||
const middlewares = [thunk.withExtraArgument(sdk)];
|
||||
|
||||
// Enable Redux Devtools in client side dev mode.
|
||||
const composeEnhancers = process.env.NODE_ENV !== 'production' &&
|
||||
|
|
@ -23,8 +20,6 @@ export default function configureStore(sdk, initialState = {}) {
|
|||
const enhancer = composeEnhancers(applyMiddleware(...middlewares));
|
||||
|
||||
const store = createStore(createReducer(), initialState, enhancer);
|
||||
store.runSaga = sagaMiddleware.run;
|
||||
store.closeSagaMiddleware = () => store.dispatch(END);
|
||||
|
||||
return store;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5638,10 +5638,6 @@ redux-form@^6.6.1:
|
|||
lodash "^4.17.3"
|
||||
lodash-es "^4.17.3"
|
||||
|
||||
redux-saga@^0.14.4:
|
||||
version "0.14.4"
|
||||
resolved "https://registry.yarnpkg.com/redux-saga/-/redux-saga-0.14.4.tgz#a09acf294ef8387a0f23043e5c6d2f9f3fd25b54"
|
||||
|
||||
redux-thunk@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.2.0.tgz#e615a16e16b47a19a515766133d1e3e99b7852e5"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue