All files / src/store createMSAStore.js

100% Statements 8/8
33.33% Branches 1/3
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                6x 12x 12x 12x 12x       12x 12x 12x        
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
import PropTypes from 'prop-types';
 
import { createStore } from 'redux'
 
import {
  merge,
} from 'lodash-es';
 
import { MSAPropTypes, msaDefaultProps } from '../PropTypes';
 
import positionReducers from '../store/reducers';
import {
  updateProps,
  updateSequences,
} from '../store/actions';
 
import debug from '../debug';
 
/**
Initializes a new MSAViewer store-like structure.
For performance reasons, the frequently changing position information
has its own redux store.
The default properties from MSAViewer.defaultProps are used.
*/
export const createMSAStore = (props) => {
  PropTypes.checkPropTypes(MSAPropTypes, props, 'prop', 'MSAViewer');
  const propsWithDefaultValues = merge({}, msaDefaultProps, props);
  const {sequences, position, ...otherProps} = propsWithDefaultValues;
  const store = createStore(positionReducers,
    // https://github.com/zalmoxisus/redux-devtools-extension
    debug && window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
  );
  store.dispatch(updateProps(otherProps));
  store.dispatch(updateSequences(sequences));
  return store;
}
 
export default createMSAStore;