Eslint prefer-object-spread (#9466)

* The rule.

* The result
This commit is contained in:
Evan Rusackas 2020-04-03 17:05:16 -07:00 committed by GitHub
parent 265a2feb29
commit 1cdfb829d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 211 additions and 266 deletions

View File

@ -146,6 +146,7 @@ module.exports = {
'no-unused-vars': 0,
'padded-blocks': 0,
'prefer-arrow-callback': 0,
'prefer-object-spread': 1,
'prefer-template': 0,
'react/forbid-prop-types': 0,
'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }],

View File

@ -116,7 +116,7 @@ describe('AlteredSliceTag', () => {
let props;
beforeEach(() => {
props = Object.assign({}, defaultProps);
props = { ...defaultProps };
wrapper = shallow(<AlteredSliceTag {...props} />);
});
@ -140,8 +140,8 @@ describe('AlteredSliceTag', () => {
it('sets new diffs when receiving new props', () => {
const newProps = {
currentFormData: Object.assign({}, props.currentFormData),
origFormData: Object.assign({}, props.origFormData),
currentFormData: { ...props.currentFormData },
origFormData: { ...props.origFormData },
};
newProps.currentFormData.beta = 10;
wrapper = shallow(<AlteredSliceTag {...props} />);

View File

@ -30,7 +30,7 @@ describe('Checkbox', () => {
let wrapper;
const factory = o => {
const props = Object.assign({}, defaultProps, o);
const props = { ...defaultProps, ...o };
return shallow(<Checkbox {...props} />);
};
beforeEach(() => {

View File

@ -39,7 +39,7 @@ describe('ColumnOption', () => {
const factory = o => <ColumnOption {...o} />;
beforeEach(() => {
wrapper = shallow(factory(defaultProps));
props = Object.assign({}, defaultProps);
props = { ...defaultProps };
});
it('is a valid element', () => {
expect(React.isValidElement(<ColumnOption {...defaultProps} />)).toBe(true);

View File

@ -40,7 +40,7 @@ describe('MetricOption', () => {
const factory = o => <MetricOption {...o} />;
beforeEach(() => {
wrapper = shallow(factory(defaultProps));
props = Object.assign({}, defaultProps);
props = { ...defaultProps };
});
it('is a valid element', () => {
expect(React.isValidElement(<MetricOption {...defaultProps} />)).toBe(true);

View File

@ -54,9 +54,9 @@ describe('OnPasteSelect', () => {
let evt;
let expected;
beforeEach(() => {
props = Object.assign({}, defaultProps);
props = { ...defaultProps };
wrapper = shallow(<OnPasteSelect {...props} />);
evt = Object.assign({}, defaultEvt);
evt = { ...defaultEvt };
});
it('renders the supplied selectWrap component', () => {

View File

@ -34,7 +34,7 @@ describe('OptionDescription', () => {
let props;
beforeEach(() => {
props = { option: Object.assign({}, defaultProps.option) };
props = { option: { ...defaultProps.option } };
wrapper = shallow(<OptionDescription {...props} />);
});

View File

@ -32,7 +32,7 @@ describe('PopoverSection', () => {
let wrapper;
const factory = overrideProps => {
const props = Object.assign({}, defaultProps, overrideProps || {});
const props = { ...defaultProps, ...(overrideProps || {}) };
return shallow(<PopoverSection {...props} />);
};
beforeEach(() => {

View File

@ -48,7 +48,7 @@ describe('VirtualizedRendererWrap', () => {
let props;
beforeEach(() => {
wrapper = shallow(<RendererWrap {...defaultProps} />);
props = Object.assign({}, defaultProps);
props = { ...defaultProps };
});
it('uses the provided renderer', () => {

View File

@ -48,7 +48,7 @@ describe('SelectControl', () => {
});
it('renders a AceEditor when language is specified', () => {
const props = Object.assign({}, defaultProps);
const props = { ...defaultProps };
props.language = 'markdown';
wrapper = shallow(<TextAreaControl {...props} />);
expect(wrapper.find(FormControl)).toHaveLength(0);

View File

@ -43,4 +43,4 @@ export const user = {
database_access: ['db1', 'db2', 'db3'],
},
};
export const userNoPerms = Object.assign({}, user, { permissions: {} });
export const userNoPerms = { ...user, permissions: {} };

View File

@ -38,15 +38,9 @@ describe('ResultSet', () => {
query: queries[0],
height: 0,
};
const stoppedQueryProps = Object.assign({}, mockedProps, {
query: stoppedQuery,
});
const runningQueryProps = Object.assign({}, mockedProps, {
query: runningQuery,
});
const cachedQueryProps = Object.assign({}, mockedProps, {
query: cachedQuery,
});
const stoppedQueryProps = { ...mockedProps, query: stoppedQuery };
const runningQueryProps = { ...mockedProps, query: runningQuery };
const cachedQueryProps = { ...mockedProps, query: cachedQuery };
const newProps = {
query: {
cached: false,
@ -94,11 +88,12 @@ describe('ResultSet', () => {
});
it('should render empty results', () => {
const wrapper = shallow(<ResultSet {...mockedProps} />);
const emptyResults = Object.assign({}, queries[0], {
const emptyResults = {
...queries[0],
results: {
data: [],
},
});
};
wrapper.setProps({ query: emptyResults });
expect(wrapper.find(FilterableTable)).toHaveLength(0);
expect(wrapper.find(Alert)).toHaveLength(1);

View File

@ -37,10 +37,7 @@ describe('TabbedSqlEditors', () => {
const tabHistory = ['dfsadfs', 'newEditorId'];
const tables = [
Object.assign({}, table, {
dataPreviewQueryId: 'B1-VQU1zW',
queryEditorId: 'newEditorId',
}),
{ ...table, dataPreviewQueryId: 'B1-VQU1zW', queryEditorId: 'newEditorId' },
];
const queryEditors = [

View File

@ -19,7 +19,7 @@
import sinon from 'sinon';
import * as actions from '../../../src/SqlLab/actions/sqlLab';
export const mockedActions = sinon.stub(Object.assign({}, actions));
export const mockedActions = sinon.stub({ ...actions });
export const alert = { bsStyle: 'danger', msg: 'Ooops', id: 'lksvmcx32' };
export const table = {
@ -388,7 +388,7 @@ export const runningQuery = {
state: 'running',
startDttm: Date.now() - 500,
};
export const cachedQuery = Object.assign({}, queries[0], { cached: true });
export const cachedQuery = { ...queries[0], cached: true };
export const initialState = {
sqlLab: {

View File

@ -141,7 +141,7 @@ describe('sqlLabReducer', () => {
let newState;
let newTable;
beforeEach(() => {
newTable = Object.assign({}, table);
newTable = { ...table };
const action = {
type: actions.MERGE_TABLE,
table: newTable,

View File

@ -94,7 +94,7 @@ class QueryTable extends React.PureComponent {
render() {
const data = this.props.queries
.map(query => {
const q = Object.assign({}, query);
const q = { ...query };
if (q.endDttm) {
q.duration = fDuration(q.startDttm, q.endDttm);
}

View File

@ -36,7 +36,7 @@ export default function sqlLabReducer(state = {}, action) {
[actions.ADD_QUERY_EDITOR]() {
const tabHistory = state.tabHistory.slice();
tabHistory.push(action.queryEditor.id);
const newState = Object.assign({}, state, { tabHistory });
const newState = { ...state, tabHistory };
return addToArr(newState, 'queryEditors', action.queryEditor);
},
[actions.QUERY_EDITOR_SAVED]() {
@ -102,19 +102,19 @@ export default function sqlLabReducer(state = {}, action) {
table => table.queryEditorId !== action.queryEditor.id,
);
newState = Object.assign({}, newState, { tabHistory, tables, queries });
newState = { ...newState, tabHistory, tables, queries };
return newState;
},
[actions.REMOVE_QUERY]() {
const newQueries = Object.assign({}, state.queries);
const newQueries = { ...state.queries };
delete newQueries[action.query.id];
return Object.assign({}, state, { queries: newQueries });
return { ...state, queries: newQueries };
},
[actions.RESET_STATE]() {
return Object.assign({}, getInitialState());
return { ...getInitialState() };
},
[actions.MERGE_TABLE]() {
const at = Object.assign({}, action.table);
const at = { ...action.table };
let existingTable;
state.tables.forEach(xt => {
if (
@ -146,32 +146,31 @@ export default function sqlLabReducer(state = {}, action) {
return alterInArr(state, 'tables', action.table, { expanded: true });
},
[actions.REMOVE_DATA_PREVIEW]() {
const queries = Object.assign({}, state.queries);
const queries = { ...state.queries };
delete queries[action.table.dataPreviewQueryId];
const newState = alterInArr(state, 'tables', action.table, {
dataPreviewQueryId: null,
});
return Object.assign({}, newState, { queries });
return { ...newState, queries };
},
[actions.CHANGE_DATA_PREVIEW_ID]() {
const queries = Object.assign({}, state.queries);
const queries = { ...state.queries };
delete queries[action.oldQueryId];
const newTables = [];
state.tables.forEach(xt => {
if (xt.dataPreviewQueryId === action.oldQueryId) {
newTables.push(
Object.assign({}, xt, { dataPreviewQueryId: action.newQuery.id }),
);
newTables.push({ ...xt, dataPreviewQueryId: action.newQuery.id });
} else {
newTables.push(xt);
}
});
return Object.assign({}, state, {
return {
...state,
queries,
tables: newTables,
activeSouthPaneTab: action.newQuery.id,
});
};
},
[actions.COLLAPSE_TABLE]() {
return alterInArr(state, 'tables', action.table, { expanded: false });
@ -180,7 +179,7 @@ export default function sqlLabReducer(state = {}, action) {
return removeFromArr(state, 'tables', action.table);
},
[actions.START_QUERY_VALIDATION]() {
let newState = Object.assign({}, state);
let newState = { ...state };
const sqlEditor = { id: action.query.sqlEditorId };
newState = alterInArr(newState, 'queryEditors', sqlEditor, {
validationResult: {
@ -204,7 +203,7 @@ export default function sqlLabReducer(state = {}, action) {
return state;
}
// Otherwise, persist the results on the queryEditor state
let newState = Object.assign({}, state);
let newState = { ...state };
const sqlEditor = { id: action.query.sqlEditorId };
newState = alterInArr(newState, 'queryEditors', sqlEditor, {
validationResult: {
@ -228,7 +227,7 @@ export default function sqlLabReducer(state = {}, action) {
return state;
}
// Otherwise, persist the results on the queryEditor state
let newState = Object.assign({}, state);
let newState = { ...state };
const sqlEditor = { id: action.query.sqlEditorId };
newState = alterInArr(newState, 'queryEditors', sqlEditor, {
validationResult: {
@ -247,7 +246,7 @@ export default function sqlLabReducer(state = {}, action) {
return newState;
},
[actions.COST_ESTIMATE_STARTED]() {
let newState = Object.assign({}, state);
let newState = { ...state };
const sqlEditor = { id: action.query.sqlEditorId };
newState = alterInArr(newState, 'queryEditors', sqlEditor, {
queryCostEstimate: {
@ -259,7 +258,7 @@ export default function sqlLabReducer(state = {}, action) {
return newState;
},
[actions.COST_ESTIMATE_RETURNED]() {
let newState = Object.assign({}, state);
let newState = { ...state };
const sqlEditor = { id: action.query.sqlEditorId };
newState = alterInArr(newState, 'queryEditors', sqlEditor, {
queryCostEstimate: {
@ -271,7 +270,7 @@ export default function sqlLabReducer(state = {}, action) {
return newState;
},
[actions.COST_ESTIMATE_FAILED]() {
let newState = Object.assign({}, state);
let newState = { ...state };
const sqlEditor = { id: action.query.sqlEditorId };
newState = alterInArr(newState, 'queryEditors', sqlEditor, {
queryCostEstimate: {
@ -283,23 +282,18 @@ export default function sqlLabReducer(state = {}, action) {
return newState;
},
[actions.START_QUERY]() {
let newState = Object.assign({}, state);
let newState = { ...state };
if (action.query.sqlEditorId) {
const qe = getFromArr(state.queryEditors, action.query.sqlEditorId);
if (qe.latestQueryId && state.queries[qe.latestQueryId]) {
const newResults = Object.assign(
{},
state.queries[qe.latestQueryId].results,
{
data: [],
query: null,
},
);
const q = Object.assign({}, state.queries[qe.latestQueryId], {
results: newResults,
});
const queries = Object.assign({}, state.queries, { [q.id]: q });
newState = Object.assign({}, state, { queries });
const newResults = {
...state.queries[qe.latestQueryId].results,
data: [],
query: null,
};
const q = { ...state.queries[qe.latestQueryId], results: newResults };
const queries = { ...state.queries, [q.id]: q };
newState = { ...state, queries };
}
} else {
newState.activeSouthPaneTab = action.query.id;
@ -317,7 +311,7 @@ export default function sqlLabReducer(state = {}, action) {
});
},
[actions.CLEAR_QUERY_RESULTS]() {
const newResults = Object.assign({}, action.query.results);
const newResults = { ...action.query.results };
newResults.data = [];
return alterInObject(state, 'queries', action.query, {
results: newResults,
@ -365,7 +359,7 @@ export default function sqlLabReducer(state = {}, action) {
) {
const tabHistory = state.tabHistory.slice();
tabHistory.push(action.queryEditor.id);
return Object.assign({}, state, { tabHistory });
return { ...state, tabHistory };
}
return state;
},
@ -378,7 +372,7 @@ export default function sqlLabReducer(state = {}, action) {
return extendArr(state, 'tables', action.tables);
},
[actions.SET_ACTIVE_SOUTHPANE_TAB]() {
return Object.assign({}, state, { activeSouthPaneTab: action.tabId });
return { ...state, activeSouthPaneTab: action.tabId };
},
[actions.MIGRATE_QUERY_EDITOR]() {
// remove migrated query editor from localStorage
@ -421,7 +415,7 @@ export default function sqlLabReducer(state = {}, action) {
tabId => tabId !== action.oldId,
);
tabHistory.push(action.newId);
return Object.assign({}, state, { tabHistory });
return { ...state, tabHistory };
},
[actions.MIGRATE_QUERY]() {
const query = {
@ -429,8 +423,8 @@ export default function sqlLabReducer(state = {}, action) {
// point query to migrated query editor
sqlEditorId: action.queryEditorId,
};
const queries = Object.assign({}, state.queries, { [query.id]: query });
return Object.assign({}, state, { queries });
const queries = { ...state.queries, [query.id]: query };
return { ...state, queries };
},
[actions.QUERY_EDITOR_SETDB]() {
return alterInArr(state, 'queryEditors', action.queryEditor, {
@ -493,10 +487,10 @@ export default function sqlLabReducer(state = {}, action) {
action.databases.forEach(db => {
databases[db.id] = db;
});
return Object.assign({}, state, { databases });
return { ...state, databases };
},
[actions.REFRESH_QUERIES]() {
let newQueries = Object.assign({}, state.queries);
let newQueries = { ...state.queries };
// Fetch the updates to the queries present in the store.
let change = false;
let queriesLastUpdate = state.queriesLastUpdate;
@ -510,39 +504,31 @@ export default function sqlLabReducer(state = {}, action) {
if (changedQuery.changedOn > queriesLastUpdate) {
queriesLastUpdate = changedQuery.changedOn;
}
newQueries[id] = Object.assign({}, state.queries[id], changedQuery);
newQueries[id] = { ...state.queries[id], ...changedQuery };
change = true;
}
}
if (!change) {
newQueries = state.queries;
}
return Object.assign({}, state, {
queries: newQueries,
queriesLastUpdate,
});
return { ...state, queries: newQueries, queriesLastUpdate };
},
[actions.SET_USER_OFFLINE]() {
return Object.assign({}, state, { offline: action.offline });
return { ...state, offline: action.offline };
},
[actions.CREATE_DATASOURCE_STARTED]() {
return Object.assign({}, state, {
isDatasourceLoading: true,
errorMessage: null,
});
return { ...state, isDatasourceLoading: true, errorMessage: null };
},
[actions.CREATE_DATASOURCE_SUCCESS]() {
return Object.assign({}, state, {
return {
...state,
isDatasourceLoading: false,
errorMessage: null,
datasource: action.datasource,
});
};
},
[actions.CREATE_DATASOURCE_FAILED]() {
return Object.assign({}, state, {
isDatasourceLoading: false,
errorMessage: action.err,
});
return { ...state, isDatasourceLoading: false, errorMessage: action.err };
},
};
if (action.type in actionHandlers) {

View File

@ -42,7 +42,7 @@ const defaultProps = {
const BUTTON_WRAPPER_STYLE = { display: 'inline-block', cursor: 'not-allowed' };
export default function Button(props) {
const buttonProps = Object.assign({}, props);
const buttonProps = { ...props };
const tooltip = props.tooltip;
const placement = props.placement;
delete buttonProps.tooltip;

View File

@ -65,116 +65,93 @@ const strokeLinejoin = 'round';
// Create the theme
const theme = {
area: assign(
{
style: {
data: {
fill: charcoal,
},
labels: baseLabelStyles,
area: {
style: {
data: {
fill: charcoal,
},
labels: baseLabelStyles,
},
baseProps,
),
axis: assign(
{
style: {
axis: {
fill: 'none',
stroke: AXIS_LINE_GRAY,
strokeWidth: 1,
strokeLinecap,
strokeLinejoin,
},
axisLabel: assign({}, baseLabelStyles, {
padding: 25,
}),
grid: {
fill: 'none',
stroke: 'transparent',
},
ticks: {
fill: 'none',
padding: 10,
size: 1,
stroke: 'transparent',
},
tickLabels: baseLabelStyles,
...baseProps,
},
axis: {
style: {
axis: {
fill: 'none',
stroke: AXIS_LINE_GRAY,
strokeWidth: 1,
strokeLinecap,
strokeLinejoin,
},
axisLabel: { ...baseLabelStyles, padding: 25 },
grid: {
fill: 'none',
stroke: 'transparent',
},
ticks: {
fill: 'none',
padding: 10,
size: 1,
stroke: 'transparent',
},
tickLabels: baseLabelStyles,
},
baseProps,
),
bar: assign(
{
style: {
data: {
fill: A11Y_BABU,
padding: 10,
stroke: 'transparent',
strokeWidth: 0,
width: 8,
},
labels: baseLabelStyles,
...baseProps,
},
bar: {
style: {
data: {
fill: A11Y_BABU,
padding: 10,
stroke: 'transparent',
strokeWidth: 0,
width: 8,
},
labels: baseLabelStyles,
},
baseProps,
),
candlestick: assign(
{
style: {
data: {
stroke: A11Y_BABU,
strokeWidth: 1,
},
labels: assign({}, baseLabelStyles, {
padding: 25,
textAnchor: 'end',
}),
},
candleColors: {
positive: '#ffffff',
negative: charcoal,
...baseProps,
},
candlestick: {
style: {
data: {
stroke: A11Y_BABU,
strokeWidth: 1,
},
labels: { ...baseLabelStyles, padding: 25, textAnchor: 'end' },
},
baseProps,
),
candleColors: {
positive: '#ffffff',
negative: charcoal,
},
...baseProps,
},
chart: baseProps,
errorbar: assign(
{
style: {
data: {
fill: 'none',
stroke: charcoal,
strokeWidth: 2,
},
labels: assign({}, baseLabelStyles, {
textAnchor: 'start',
}),
errorbar: {
style: {
data: {
fill: 'none',
stroke: charcoal,
strokeWidth: 2,
},
labels: { ...baseLabelStyles, textAnchor: 'start' },
},
baseProps,
),
group: assign(
{
colorScale: colors,
},
baseProps,
),
line: assign(
{
style: {
data: {
fill: 'none',
stroke: A11Y_BABU,
strokeWidth: 2,
},
labels: assign({}, baseLabelStyles, {
textAnchor: 'start',
}),
...baseProps,
},
group: {
colorScale: colors,
...baseProps,
},
line: {
style: {
data: {
fill: 'none',
stroke: A11Y_BABU,
strokeWidth: 2,
},
labels: { ...baseLabelStyles, textAnchor: 'start' },
},
baseProps,
),
...baseProps,
},
pie: {
style: {
data: {
@ -182,37 +159,28 @@ const theme = {
stroke: 'none',
strokeWidth: 1,
},
labels: assign({}, baseLabelStyles, {
padding: 200,
textAnchor: 'middle',
}),
labels: { ...baseLabelStyles, padding: 200, textAnchor: 'middle' },
},
colorScale: colors,
width: 400,
height: 400,
padding: 50,
},
scatter: assign(
{
style: {
data: {
fill: charcoal,
stroke: 'transparent',
strokeWidth: 0,
},
labels: assign({}, baseLabelStyles, {
textAnchor: 'middle',
}),
scatter: {
style: {
data: {
fill: charcoal,
stroke: 'transparent',
strokeWidth: 0,
},
labels: { ...baseLabelStyles, textAnchor: 'middle' },
},
baseProps,
),
stack: assign(
{
colorScale: colors,
},
baseProps,
),
...baseProps,
},
stack: {
colorScale: colors,
...baseProps,
},
};
export default theme;

View File

@ -75,11 +75,10 @@ class ControlPanelsContainer extends React.Component {
}
// Applying mapStateToProps if needed
if (mapF) {
return Object.assign(
{},
control,
mapF(this.props.exploreState, control, this.props.actions),
);
return {
...control,
...mapF(this.props.exploreState, control, this.props.actions),
};
}
return control;
}

View File

@ -418,13 +418,12 @@ function mapStateToProps(state) {
}
function mapDispatchToProps(dispatch) {
const actions = Object.assign(
{},
exploreActions,
saveModalActions,
chartActions,
logActions,
);
const actions = {
...exploreActions,
...saveModalActions,
...chartActions,
...logActions,
};
return {
actions: bindActionCreators(actions, dispatch),
};

View File

@ -88,9 +88,10 @@ export default class ColorPickerControl extends React.Component {
}
render() {
const c = this.props.value || { r: 0, g: 0, b: 0, a: 0 };
const colStyle = Object.assign({}, styles.color, {
const colStyle = {
...styles.color,
background: `rgba(${c.r}, ${c.g}, ${c.b}, ${c.a})`,
});
};
return (
<div>
<ControlHeader {...this.props} />

View File

@ -513,10 +513,11 @@ export const controls = {
default: null,
},
columns: Object.assign({}, groupByControl, {
columns: {
...groupByControl,
label: t('Columns'),
description: t('One or many controls to pivot as columns'),
}),
},
all_columns: {
type: 'SelectControl',

View File

@ -131,9 +131,7 @@ export default function exploreReducer(state = {}, action) {
};
},
[actions.UPDATE_CHART_TITLE]() {
const updatedSlice = Object.assign({}, state.slice, {
slice_name: action.slice_name,
});
const updatedSlice = { ...state.slice, slice_name: action.slice_name };
return {
...state,
slice: updatedSlice,

View File

@ -22,23 +22,22 @@ import * as actions from '../actions/saveModalActions';
export default function saveModalReducer(state = {}, action) {
const actionHandlers = {
[actions.FETCH_DASHBOARDS_SUCCEEDED]() {
return Object.assign({}, state, { dashboards: action.choices });
return { ...state, dashboards: action.choices };
},
[actions.FETCH_DASHBOARDS_FAILED]() {
return Object.assign({}, state, {
return {
...state,
saveModalAlert: `fetching dashboards failed for ${action.userId}`,
});
};
},
[actions.SAVE_SLICE_FAILED]() {
return Object.assign({}, state, {
saveModalAlert: 'Failed to save slice',
});
return { ...state, saveModalAlert: 'Failed to save slice' };
},
[actions.SAVE_SLICE_SUCCESS](data) {
return Object.assign({}, state, { data });
return { ...state, data };
},
[actions.REMOVE_SAVE_MODAL_ALERT]() {
return Object.assign({}, state, { saveModalAlert: null });
return { ...state, saveModalAlert: null };
},
};

View File

@ -41,7 +41,7 @@ export function getControlsState(state, inputFormData) {
* */
// Getting a list of active control names for the current viz
const formData = Object.assign({}, inputFormData);
const formData = { ...inputFormData };
const vizType = formData.viz_type || 'table';
handleDeprecatedControls(formData);
@ -80,7 +80,7 @@ export function applyDefaultFormData(inputFormData) {
return formData;
}
const defaultControls = Object.assign({}, controls);
const defaultControls = { ...controls };
Object.keys(controls).forEach(f => {
defaultControls[f].value = controls[f].default;
});

View File

@ -22,20 +22,20 @@ import persistState from 'redux-localstorage';
import { isEqual } from 'lodash';
export function addToObject(state, arrKey, obj) {
const newObject = Object.assign({}, state[arrKey]);
const copiedObject = Object.assign({}, obj);
const newObject = { ...state[arrKey] };
const copiedObject = { ...obj };
if (!copiedObject.id) {
copiedObject.id = shortid.generate();
}
newObject[copiedObject.id] = copiedObject;
return Object.assign({}, state, { [arrKey]: newObject });
return { ...state, [arrKey]: newObject };
}
export function alterInObject(state, arrKey, obj, alterations) {
const newObject = Object.assign({}, state[arrKey]);
newObject[obj.id] = Object.assign({}, newObject[obj.id], alterations);
return Object.assign({}, state, { [arrKey]: newObject });
const newObject = { ...state[arrKey] };
newObject[obj.id] = { ...newObject[obj.id], ...alterations };
return { ...state, [arrKey]: newObject };
}
export function alterInArr(state, arrKey, obj, alterations, idKey = 'id') {
@ -44,12 +44,12 @@ export function alterInArr(state, arrKey, obj, alterations, idKey = 'id') {
const newArr = [];
state[arrKey].forEach(arrItem => {
if (obj[idKey] === arrItem[idKey]) {
newArr.push(Object.assign({}, arrItem, alterations));
newArr.push({ ...arrItem, ...alterations });
} else {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
return { ...state, [arrKey]: newArr };
}
export function removeFromArr(state, arrKey, obj, idKey = 'id') {
@ -59,7 +59,7 @@ export function removeFromArr(state, arrKey, obj, idKey = 'id') {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
return { ...state, [arrKey]: newArr };
}
export function getFromArr(arr, id) {
@ -73,7 +73,7 @@ export function getFromArr(arr, id) {
}
export function addToArr(state, arrKey, obj, prepend = false) {
const newObj = Object.assign({}, obj);
const newObj = { ...obj };
if (!newObj.id) {
newObj.id = shortid.generate();
}
@ -83,7 +83,7 @@ export function addToArr(state, arrKey, obj, prepend = false) {
} else {
newState[arrKey] = [...state[arrKey], newObj];
}
return Object.assign({}, state, newState);
return { ...state, ...newState };
}
export function extendArr(state, arrKey, obj, prepend = false) {
@ -100,7 +100,7 @@ export function extendArr(state, arrKey, obj, prepend = false) {
} else {
newState[arrKey] = [...state[arrKey], ...newObj];
}
return Object.assign({}, state, newState);
return { ...state, ...newState };
}
export function initEnhancer(persist = true, persistConfig = {}) {

View File

@ -19,20 +19,20 @@
import shortid from 'shortid';
export function addToObject(state, arrKey, obj) {
const newObject = Object.assign({}, state[arrKey]);
const copiedObject = Object.assign({}, obj);
const newObject = { ...state[arrKey] };
const copiedObject = { ...obj };
if (!copiedObject.id) {
copiedObject.id = shortid.generate();
}
newObject[copiedObject.id] = copiedObject;
return Object.assign({}, state, { [arrKey]: newObject });
return { ...state, [arrKey]: newObject };
}
export function alterInObject(state, arrKey, obj, alterations) {
const newObject = Object.assign({}, state[arrKey]);
newObject[obj.id] = Object.assign({}, newObject[obj.id], alterations);
return Object.assign({}, state, { [arrKey]: newObject });
const newObject = { ...state[arrKey] };
newObject[obj.id] = { ...newObject[obj.id], ...alterations };
return { ...state, [arrKey]: newObject };
}
export function alterInArr(state, arrKey, obj, alterations) {
@ -42,12 +42,12 @@ export function alterInArr(state, arrKey, obj, alterations) {
const newArr = [];
state[arrKey].forEach(arrItem => {
if (obj[idKey] === arrItem[idKey]) {
newArr.push(Object.assign({}, arrItem, alterations));
newArr.push({ ...arrItem, ...alterations });
} else {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
return { ...state, [arrKey]: newArr };
}
export function removeFromArr(state, arrKey, obj, idKey = 'id') {
@ -57,15 +57,15 @@ export function removeFromArr(state, arrKey, obj, idKey = 'id') {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
return { ...state, [arrKey]: newArr };
}
export function addToArr(state, arrKey, obj) {
const newObj = Object.assign({}, obj);
const newObj = { ...obj };
if (!newObj.id) {
newObj.id = shortid.generate();
}
const newState = {};
newState[arrKey] = [...state[arrKey], newObj];
return Object.assign({}, state, newState);
return { ...state, ...newState };
}

View File

@ -120,14 +120,15 @@ class FilterBox extends React.Component {
getControlData(controlName) {
const { selectedValues } = this.state;
const control = Object.assign({}, controls[controlName], {
const control = {
...controls[controlName],
name: controlName,
key: `control-${controlName}`,
value: selectedValues[TIME_FILTER_MAP[controlName]],
actions: { setControlValue: this.changeFilter },
});
};
const mapFunc = control.mapStateToProps;
return mapFunc ? Object.assign({}, control, mapFunc(this.props)) : control;
return mapFunc ? { ...control, ...mapFunc(this.props) } : control;
}
clickApply() {