Skip to content

Commit

Permalink
fix custom keys with defaultValue, and remove hot reload from product…
Browse files Browse the repository at this point in the history
…ion bundle
  • Loading branch information
stratos-vetsos committed Oct 27, 2018
1 parent 4e2a52d commit e881529
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 33 deletions.
9 changes: 6 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"stage-2",
"react"
],
"plugins": [
"react-hot-loader/babel"
]
"env": {
"development": {
"plugins": [ "react-hot-loader/babel" ]
},
"production": {}
}
}
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/PlayGround.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ export default class PlayGround extends React.Component {

let options = [
{
key: 'a10',
value: 'a10',
label: 'Option A 10'
},
{
key: 'b10',
value: 'b10',
label: 'Option B'
},
{
key: 'c',
value: 'c',
label: 'Option C'
},
{
key: 'd',
value: 'd',
label: 'Option D'
},
{
key: 'e',
value: 'e',
label: 'Option E'
},
{
key: 'f',
value: 'f',
label: 'Option F'
}
];
Expand Down Expand Up @@ -93,7 +93,8 @@ export default class PlayGround extends React.Component {
checkBoxes={ false }
materialize={ true }
isDropDown={ false }
// customKeys={ { key: 'url', label: 'title' } }
// defaultValue={ [ 'b10', 'c', 'f' ] }
customKeys={ { key: 'value', label: 'label' } }
// ajax={{
// url: 'https://newsapi.org/v2/everything?apiKey=9342a9a707ca49c4b2da34e9ea238ea6',
// fetchOnSearch: true,
Expand Down
7 changes: 4 additions & 3 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export const setupInstance = ( props, update = false ) => {
return ( dispatch, getState ) => {

const state = getState();
let { selected, selectedIndex } = props.defaultValue
? normalizeSelected( props.defaultValue, [ ... props.options ] )
: { selected: state.selected, selectedIndex: state.selectedIndex };

let customKeys = {},
options = [ ... props.options ];
Expand Down Expand Up @@ -138,6 +135,10 @@ export const setupInstance = ( props, update = false ) => {
} ).filter( x => x );
}

let { selected, selectedIndex } = props.defaultValue
? normalizeSelected( props.defaultValue, [ ... options ] )
: { selected: state.selected, selectedIndex: state.selectedIndex };

if( props.ajax && props.ajax.hasOwnProperty( 'url' ) && props.ajax.url !== '' ) {

options = selected = selectedIndex = [];
Expand Down
2 changes: 1 addition & 1 deletion src/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';

import ReduxStore from 'store/';
import ReduxStore from 'store/devStore';
import configureStore from 'store/configureStore';

const elRoot = document.getElementById( 'root' );
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import ReduxStore from 'store/';
import ReduxStore from 'store/productionStore';
export default ReduxStore;
14 changes: 14 additions & 0 deletions src/store/devStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { Provider } from 'react-redux';
import PlayGround from 'PlayGround';

const ReduxStore = ownProps => {
const store = ownProps.store;
return(
<Provider store={ store }>
<PlayGround />
</Provider>
);
}

export default ReduxStore;
17 changes: 0 additions & 17 deletions src/store/index.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/store/productionStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Provider } from 'react-redux';
import App from 'components/';
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import reducer from 'reducers';

const ReduxStore = ownProps => {
const store = createStore( reducer, applyMiddleware( thunkMiddleware ) );
return(
<Provider store={ store }>
<App { ...ownProps } />
</Provider>
);
}

export default ReduxStore;

0 comments on commit e881529

Please sign in to comment.