@wildberries/redux-core-modules
core redux modules
Last updated 3 days ago by mihanizm56 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @wildberries/redux-core-modules 
SYNC missed versions from official npm registry.

@wildberries/redux-core-modules

Sollution for redux and redux-saga common cases

What does it provide:

  • Store initialization
  • Core redux-modules for common usage
  • Utils for redux code-splitting

installation

npm install @wildberries/redux-core-modules

Features:

Store initialization:

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { configureRouter } from '@wildberries/service-router';
import { createAppStore } from '@wildberries/redux-core-modules';
import {
  notificationsState,
  NOTIFICATIONS_REDUCER_NAME,
  setModalAction,
} from '@wildberries/notifications';
import {
  confirmModalModuleReducer,
  confirmModalWatcherSaga,
  CONFIRM_MODALS_REDUCER_NAME,
  CONFIRM_MODAL_SAGA_NAME,
} from '@wildberries/confirm-modal-portal';

const ROOT_ELEMENT = document.getElementById('root');

const router = configureRouter({ defaultRoute: 'wb-eu-registration' });

const store = createAppStore({
  router,
  rootReducers: {
    [NOTIFICATIONS_REDUCER_NAME]: notificationsState,
    [CONFIRM_MODALS_REDUCER_NAME]: confirmModalModuleReducer,
  },
  rootSagas: {
    [CONFIRM_MODAL_SAGA_NAME]: confirmModalWatcherSaga,
  },
  dependencies: { setModalAction },
});

router.start(() => {
  ReactDOM.render(
    <Provider store={store}>
      <App />
    </Provider>,
    ROOT_ELEMENT,
  );
});

Core redux-modules for common usage:

  • Form-manager-module - helps to work with the form submission
  • Init-load-manager-module - helps to get data when page is rendering
  • Redirect-manager-module - helps to navigate in redux-saga worker saga
  • Request-extra-data-handler-module - helps to make different actions from response data
  • UI-module - helps with working in the whole app ui-data

Form-manager-module - gets options and make request and handle different operations:

  • re-save form data (necessary for react-final-form) before call the request and set new data
  • format form data before to insert to the request
  • start and stops form loading state
  • call error action (of array of actions)
  • call success action (of array of actions)
  • trigger notifications actions on success and error
  • send data (formatted of not) to the Request-extra-data-handler-module to make some operations with splitted data from response
  • trigger success or error router redirections

Example:

import { fetchFormManagerSagaAction } from '@wildberries/redux-core-modules';

const formManagerSubmitOptions: FormManagerType = {
    formValues: { foo:'bar' },
    loadingStartAction: ()=>({ type:'loading start' }),
    loadingStopAction: ()=>({ type:'loading stop' }),
    formValuesFormatter: (data) => ({ 'baz':data.foo }),
    formRequest: fetch('http://example.com'),
    formSuccessAction: (payload)=>({ type:'some example success action', payload }),
    setErrorAction: (payload)=>({ type:'some example error action', payload }),
    resetInitialDataAction: (payload)=>({ type:'action to re-save form data', payload }),
    showNotification: true,
    redirectSuccessActionParams: {
        pathName: 'some.path',
    },
};

store.dispatch(formManagerSubmitOptions);

Init-load-manager-module - has the separate config for each request and makes operations:

  • start and stop form loading state (not in each request but in the whole action)
  • format request data before and after the request
  • get the options (or not) and calls the request
  • trigger notifications actions on success and error
  • call error action (of array of actions)
  • call success action (of array of actions)
  • send data (formatted of not) to the Request-extra-data-handler-module to make some operations with splitted data from response
  • trigger success or error router redirections
  • ability to use batching (in JSON-RPC protocol)
  • cancelling the request if not responded

Example:

import { initLoadManagerActionSaga, InitLoadManagerActionPayloadType } from '@wildberries/redux-core-modules';
import { getWarehousesListRequest } from '@/services/api/requests/get-warehouses-list';
import { getCountriesListRequest } from '@/services/api/requests/get-countries-list';
import { setRegionsAction } from '../_redux/regions-module';
import { setWarehousesAction } from '../_redux/warehouses-module';
import { warehousesListFormatter } from '../_utils/warehouses-list-formatter';

const loadDataConfig: InitLoadManagerActionPayloadType = {
  requestConfigList: [
    {
      request: getWarehousesListRequest,
      requestOptions: { foo:'bar' },
      isDataCritical: true,
      showErrorNotification: true,
      showSuccessNotification: false,
      requestDataFormatter: warehousesListFormatter,
      actionSuccess: setWarehousesAction,
      isBatchRequest: true
    },
    {
      request: getCountriesListRequest,
      isDataCritical: true,
      showErrorNotification: true,
      showSuccessNotification: false,
      requestExtraDataHandlerOptions: [
        {
          fieldName: 'countries',
          action: setRegionsAction,
        },
      ],
    },
  ],
};

store.dispatch(initLoadManagerActionSaga(loadDataConfig));

Download-files-manager-module - manager to download base64 and blob type files:

  • start and stop form loading state
  • format request data before to get file to be downloaded
  • get the options (or not) and calls the request
  • trigger notifications actions on success and error
  • call error action (of array of actions)
  • call success action (of array of actions)

Example:

import { downloadFilesManagerSagaAction, DownloadFilesManagerType } from '@wildberries/redux-core-modules';
import { someDownloadRequest } from '@/services/api/requests/some-request';
import { getCountriesListRequest } from '@/services/api/requests/get-countries-list';
import { setRegionsAction } from '../_redux/regions-module';
import { setWarehousesAction } from '../_redux/warehouses-module';

const config: DownloadFilesManagerType = {
  downloadFileRequest: someDownloadRequest,
  requestParams: {foo: 'bar'};
  loadingStartAction: () => ({ type:"LOADING_START" });
  loadingStopAction: () => ({ type:"LOADING_STOP" });
  formSuccessAction: () => ({ type:"SOME_SUCCESS_ACTION" });
  formSuccessActionsArray: [
    () => ({ type:"SOME_SUCCESS_ACTION_1" }),
    () => ({ type:"SOME_SUCCESS_ACTION_2" })
  ]
  setErrorAction: () => ({ type:"SOME_ERROR_ACTION" });
  setErrorActionsArray: [
    () => ({ type:"SOME_ERROR_ACTION_1" }),
    () => ({ type:"SOME_ERROR_ACTION_2" })
  ]
  showNotificationError: true;
  showNotificationSuccess: true;
  notificationSuccessMessage: 'some success notification message';
  fileType: 'base64';
  responseDataFormatter?: (response) => ({
    file:response.foo,
    contentType:response.bar,
    name:response.baz
  })
};

store.dispatch(downloadFilesManagerSagaAction(config));

Redirect-manager-module - simple options-provider to the router.navigate method from router5:

  • redirects to internal routes
  • redirects to external routes (for example if you are using microservice architecture and you stream-app doesn't know about external routes)

provides actions:

import { redirectManagerSagaAction, redirectToPlatformRouteManagerSagaAction } from '@wildberries/redux-core-modules';

store.dispatch(redirectManagerSagaAction({
  pathName: 'route.path.name';
  params: { foo:'bar' };
  actionAfterRedirect: (payload) => ({ type:'action that will be called after redirect', payload })
  actionAfterRedirectParams: { id: 'test_id' };
}));

'there is no differences between action signatures - they are actually go to the one watcher-saga'
'but to show exactly where do you want to redirect - we provide this method'

store.dispatch(redirectToPlatformRouteManagerSagaAction({
  pathName: 'route.path.name';
  params: { foo:'bar' };
  actionAfterRedirect: (payload) => ({ type:'action that will be called after redirect', payload })
  actionAfterRedirectParams: { id: 'test_id' };
}));

Request-extra-data-handler-module:

  • gets the data and array of options to process this data with redux-actions

provides actions:

import { requestExtraDataHandlerActionSaga, RequestExtraDataHandlerActionSagaType } from '@wildberries/redux-core-modules';

store.dispatch(requestExtraDataHandlerActionSaga({
  data: {
      field1: {
          foo: 'bar'
      },
      field2: {
          someOption: [
              { foo:'bar' }
          ]
      }
  },
  options: [
      {
        fieldName: 'field1';
        action: (payload) => ({ type:'action that will be called with the field1 data', payload })
      },
      {
        fieldName: 'field2';
        action: (payload) => ({ type:'action that will be called with the field2 data', payload })
      },
  ]
}));

requestErrorHandlerProcess util:

  • gets the request
  • provide the validation for the request
  • dispatches an action or an array of actions if the response is invalid
  • options for that feature exist in Form-manager-module and in Init-load-manager-module
import { requestErrorHandlerProcess } from '@wildberries/redux-core-modules';

// inside the saga
const validatedData = yield* requestErrorHandlerProcess({
  request: () =>
    updateReportRequest({
      id,
      status: STATUS_APPROVED,
    }),
  requestValidator: () => false,
  errorAction: () => ({ type: 'test error action' }),
});

Utils for redux code-splitting:

inject reducers:

import { injectAsyncReducer } from '@wildberries/redux-core-modules';

injectAsyncReducer({
    store,                            '-- pure store object'
    name: 'registrationFormStorage',  '-- reducer name'
    reducer: registrationFormStorage, '-- reducer instance'
});

inject sagas:

import { injectAsyncSaga } from '@wildberries/redux-core-modules';

injectAsyncSaga({
    store,                                    '-- pure store object'
    name: 'downloadContractOfferWatcherSaga', '-- saga name'
    saga: downloadContractOfferWatcherSaga,   '-- saga instance'
});

remove sagas:

import { removeAsyncSaga } from '@wildberries/redux-core-modules';

removeAsyncSaga({
    store,                                    '-- pure store object'
    name: 'downloadContractOfferWatcherSaga', '-- saga name'
});

remove reducers:

Warning - please be accurate with this. You can lose your necessary data !

import { removeAsyncReducer } from '@wildberries/redux-core-modules';

removeAsyncReducer({
    store,                                    '-- pure store object'
    name: 'registrationFormStorage',          '-- saga name'
});

Current Tags

  • 0.1.1-beta.1                                ...           beta (4 days ago)
  • 0.1.2                                ...           latest (3 days ago)

197 Versions

  • 0.1.2                                ...           3 days ago
  • 0.1.1                                ...           4 days ago
  • 0.1.1-beta.1                                ...           4 days ago
  • 0.1.0                                ...           6 days ago
  • 0.1.0-beta.1                                ...           6 days ago
  • 0.0.43                                ...           6 days ago
  • 0.0.43-beta.2                                ...           11 days ago
  • 0.0.43-beta.1                                ...           11 days ago
  • 0.0.42                                ...           14 days ago
  • 1.0.0-beta.1                                ...           14 days ago
  • 0.0.41                                ...           14 days ago
  • 0.0.41-beta.1                                ...           16 days ago
  • 0.0.40                                ...           18 days ago
  • 0.0.40-beta.1                                ...           18 days ago
  • 0.0.39                                ...           19 days ago
  • 0.0.37                                ...           a month ago
  • 0.0.37-beta.1                                ...           a month ago
  • 0.0.36                                ...           a month ago
  • 0.0.36-beta.1                                ...           a month ago
  • 0.0.35                                ...           a month ago
  • 0.0.34                                ...           a month ago
  • 0.0.34-beta.2                                ...           a month ago
  • 0.0.34-beta.1                                ...           a month ago
  • 0.0.33                                ...           a month ago
  • 0.0.33-beta.11                                ...           2 months ago
  • 0.0.33-beta.10                                ...           2 months ago
  • 0.0.33-beta.9                                ...           2 months ago
  • 0.0.33-beta.8                                ...           2 months ago
  • 0.0.33-beta.7                                ...           2 months ago
  • 0.0.33-beta.6                                ...           2 months ago
  • 0.0.33-beta.5                                ...           2 months ago
  • 0.0.33-beta.4                                ...           2 months ago
  • 0.0.33-beta.3                                ...           2 months ago
  • 0.0.33-beta.2                                ...           2 months ago
  • 0.0.33-beta.1                                ...           2 months ago
  • 0.0.32                                ...           2 months ago
  • 0.0.31                                ...           2 months ago
  • 0.0.30                                ...           2 months ago
  • 0.0.29                                ...           2 months ago
  • 0.0.29-beta.20                                ...           2 months ago
  • 0.0.29-beta.19                                ...           2 months ago
  • 0.0.29-beta.17                                ...           2 months ago
  • 0.0.29-beta.16                                ...           2 months ago
  • 0.0.29-beta.15                                ...           2 months ago
  • 0.0.29-beta.14                                ...           2 months ago
  • 0.0.29-beta.13                                ...           2 months ago
  • 0.0.29-beta.12                                ...           2 months ago
  • 0.0.29-beta.11                                ...           2 months ago
  • 0.0.29-beta.10                                ...           2 months ago
  • 0.0.29-beta.9                                ...           2 months ago
  • 0.0.29-beta.8                                ...           2 months ago
  • 0.0.29-beta.6                                ...           3 months ago
  • 0.0.29-beta.5                                ...           3 months ago
  • 0.0.29-beta.4                                ...           3 months ago
  • 0.0.29-beta.3                                ...           3 months ago
  • 0.0.29-beta.2                                ...           3 months ago
  • 0.0.29-beta.1                                ...           3 months ago
  • 0.0.28                                ...           3 months ago
  • 0.0.28-beta.1                                ...           3 months ago
  • 0.0.27                                ...           3 months ago
  • 0.0.27-beta.5                                ...           3 months ago
  • 0.0.27-beta.4                                ...           3 months ago
  • 0.0.27-beta.3                                ...           3 months ago
  • 0.0.27-beta.2                                ...           3 months ago
  • 0.0.27-beta.1                                ...           3 months ago
  • 0.0.26                                ...           3 months ago
  • 0.0.26-beta.1                                ...           3 months ago
  • 0.0.25                                ...           3 months ago
  • 0.0.25-beta.1                                ...           3 months ago
  • 0.0.25-beta.0                                ...           3 months ago
  • 0.0.24                                ...           3 months ago
  • 0.0.24-beta.4                                ...           4 months ago
  • 0.0.24-beta.3                                ...           4 months ago
  • 0.0.24-beta.2                                ...           4 months ago
  • 0.0.24-beta.1                                ...           4 months ago
  • 0.0.24-beta.0                                ...           4 months ago
  • 0.0.23                                ...           4 months ago
  • 0.0.22                                ...           4 months ago
  • 0.0.22-beta.1                                ...           4 months ago
  • 0.0.20                                ...           4 months ago
  • 0.0.19                                ...           4 months ago
  • 0.0.19-beta.1                                ...           4 months ago
  • 0.0.18                                ...           4 months ago
  • 0.0.17                                ...           4 months ago
  • 0.0.17-beta.1                                ...           4 months ago
  • 0.0.16                                ...           5 months ago
  • 0.0.16-beta.13                                ...           5 months ago
  • 0.0.16-beta.12                                ...           5 months ago
  • 0.0.16-beta.11                                ...           5 months ago
  • 0.0.16-beta.10                                ...           5 months ago
  • 0.0.16-beta.9                                ...           5 months ago
  • 0.0.16-beta.8                                ...           5 months ago
  • 0.0.16-beta.7                                ...           5 months ago
  • 0.0.16-beta.6                                ...           5 months ago
  • 0.0.16-beta.5                                ...           5 months ago
  • 0.0.16-beta.4                                ...           5 months ago
  • 0.0.16-beta.3                                ...           5 months ago
  • 0.0.16-beta.2                                ...           5 months ago
  • 0.0.16-beta.1                                ...           5 months ago
  • 0.0.16-beta.0                                ...           5 months ago
  • 0.0.15                                ...           5 months ago
  • 0.0.15-beta.0                                ...           5 months ago
  • 0.0.14                                ...           6 months ago
  • 0.0.14-beta.26                                ...           6 months ago
  • 0.0.14-beta.25                                ...           6 months ago
  • 0.0.14-beta.24                                ...           6 months ago
  • 0.0.14-beta.23                                ...           6 months ago
  • 0.0.14-beta.22                                ...           6 months ago
  • 0.0.14-beta.21                                ...           6 months ago
  • 0.0.14-beta.20                                ...           6 months ago
  • 0.0.14-beta.19                                ...           6 months ago
  • 0.0.14-beta.18                                ...           6 months ago
  • 0.0.14-beta.17                                ...           6 months ago
  • 0.0.14-beta.15                                ...           6 months ago
  • 0.0.14-beta.14                                ...           6 months ago
  • 0.0.14-beta.13                                ...           6 months ago
  • 0.0.14-beta.12                                ...           6 months ago
  • 0.0.14-beta.11                                ...           6 months ago
  • 0.0.14-beta.10                                ...           6 months ago
  • 0.0.14-beta.9                                ...           6 months ago
  • 0.0.14-beta.8                                ...           6 months ago
  • 0.0.14-beta.7                                ...           6 months ago
  • 0.0.14-beta.6                                ...           6 months ago
  • 0.0.14-beta.5                                ...           6 months ago
  • 0.0.14-beta.4                                ...           6 months ago
  • 0.0.14-beta.3                                ...           6 months ago
  • 0.0.14-beta.2                                ...           6 months ago
  • 0.0.14-beta.1                                ...           6 months ago
  • 0.0.14-beta.0                                ...           6 months ago
  • 0.0.13                                ...           6 months ago
  • 0.0.12                                ...           6 months ago
  • 0.0.11                                ...           6 months ago
  • 0.0.11-beta.12                                ...           6 months ago
  • 0.0.11-beta.11                                ...           6 months ago
  • 0.0.11-beta.10                                ...           6 months ago
  • 0.0.11-beta.9                                ...           6 months ago
  • 0.0.11-beta.7                                ...           6 months ago
  • 0.0.11-beta.6                                ...           6 months ago
  • 0.0.11-beta.5                                ...           6 months ago
  • 0.0.11-beta.4                                ...           6 months ago
  • 0.0.11-beta.3                                ...           6 months ago
  • 0.0.11-beta.2                                ...           6 months ago
  • 0.0.11-beta.1                                ...           6 months ago
  • 0.0.10                                ...           6 months ago
  • 0.0.9                                ...           6 months ago
  • 0.0.9-beta.1                                ...           6 months ago
  • 0.0.9-beta.0                                ...           6 months ago
  • 0.0.0-beta.0                                ...           6 months ago
  • 0.0.8                                ...           6 months ago
  • 0.0.7                                ...           6 months ago
  • 0.0.6-beta.36                                ...           6 months ago
  • 0.0.6-beta.35                                ...           6 months ago
  • 0.0.6-beta.34                                ...           6 months ago
  • 0.0.6-beta.33                                ...           6 months ago
  • 0.0.6-beta.32                                ...           6 months ago
  • 0.0.6-beta.31                                ...           6 months ago
  • 0.0.6-beta.30                                ...           6 months ago
  • 0.0.6-beta.29                                ...           6 months ago
  • 0.0.6-beta.28                                ...           6 months ago
  • 0.0.6-beta.27                                ...           6 months ago
  • 0.0.6-beta.26                                ...           6 months ago
  • 0.0.6-beta.25                                ...           6 months ago
  • 0.0.6-beta.24                                ...           6 months ago
  • 0.0.6-beta.23                                ...           6 months ago
  • 0.0.6-beta.22                                ...           6 months ago
  • 0.0.6-beta.21                                ...           6 months ago
  • 0.0.6-beta.19                                ...           6 months ago
  • 0.0.6-beta.18                                ...           6 months ago
  • 0.0.6-beta.17                                ...           6 months ago
  • 0.0.6-beta.16                                ...           6 months ago
  • 0.0.6-beta.15                                ...           6 months ago
  • 0.0.6-beta.14                                ...           6 months ago
  • 0.0.6-beta.13                                ...           6 months ago
  • 0.0.6-beta.12                                ...           6 months ago
  • 0.0.6-beta.11                                ...           6 months ago
  • 0.0.6-beta.10                                ...           6 months ago
  • 0.0.6-beta.9                                ...           6 months ago
  • 0.0.6-beta.8                                ...           6 months ago
  • 0.0.6-beta.7                                ...           6 months ago
  • 0.0.6-beta.6                                ...           6 months ago
  • 0.0.6-beta.5                                ...           6 months ago
  • 0.0.6-beta.4                                ...           6 months ago
  • 0.0.6-beta.3                                ...           6 months ago
  • 0.0.6-beta.2                                ...           6 months ago
  • 0.0.6-beta.1                                ...           6 months ago
  • 0.0.6-beta.0                                ...           6 months ago
  • 0.0.5                                ...           6 months ago
  • 0.0.4                                ...           6 months ago
  • 0.0.3                                ...           6 months ago
  • 0.0.1-beta.8                                ...           6 months ago
  • 0.0.1-beta.7                                ...           6 months ago
  • 0.0.1-beta.6                                ...           6 months ago
  • 0.0.1-beta.5                                ...           6 months ago
  • 0.0.1-beta.4                                ...           6 months ago
  • 0.0.1-beta.2                                ...           6 months ago
  • 0.0.1-beta.1                                ...           6 months ago
  • 0.0.1-beta.0                                ...           7 months ago

Copyright 2014 - 2016 © taobao.org |