Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
refactor(omit): use destructuring replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed May 16, 2019
1 parent 896e174 commit 21f7cb3
Showing 1 changed file with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { omit } from 'lodash';
import algoliasearchHelper from 'algoliasearch-helper';
import createWidgetsManager from './createWidgetsManager';
import createStore from './createStore';
Expand Down Expand Up @@ -214,18 +213,15 @@ export default function createInstantSearchManager({
nextIsSearchStalled = false;
}

const nextState = omit(
{
...currentState,
results,
isSearchStalled: nextIsSearchStalled,
searching: false,
error: null,
},
'resultsFacetValues'
);
const { resultsFacetValues, ...partialState } = currentState;

store.setState(nextState);
store.setState({
...partialState,
results,
isSearchStalled: nextIsSearchStalled,
searching: false,
error: null,
});
};
}

Expand All @@ -238,31 +234,25 @@ export default function createInstantSearchManager({
nextIsSearchStalled = false;
}

const nextState = omit(
{
...currentState,
isSearchStalled: nextIsSearchStalled,
error,
searching: false,
},
'resultsFacetValues'
);
const { resultsFacetValues, ...partialState } = currentState;

store.setState(nextState);
store.setState({
...partialState,
isSearchStalled: nextIsSearchStalled,
error,
searching: false,
});
}

function handleNewSearch() {
if (!stalledSearchTimer) {
stalledSearchTimer = setTimeout(() => {
const nextState = omit(
{
...store.getState(),
isSearchStalled: true,
},
'resultsFacetValues'
);
const { resultsFacetValues, ...partialState } = store.getState();

store.setState(nextState);
store.setState({
...partialState,
isSearchStalled: true,
});
}, stalledSearchDelay);
}
}
Expand Down

0 comments on commit 21f7cb3

Please sign in to comment.