Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Jan 5, 2023
1 parent 22c1b44 commit 5a81aba
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 84 deletions.
58 changes: 26 additions & 32 deletions searchlib/components/SearchApp/BasicSearchApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useDeepCompareEffect from 'use-deep-compare-effect';
import { AppConfigContext, SearchContext } from '@eeacms/search/lib/hocs';
import { bindOnAutocomplete, bindOnSearch } from '@eeacms/search/lib/request';
import useSearchApp from './useSearchApp';
import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';
// import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';

function applySearchWrappers(SearchViewComponent) {
function SearchWrapper(props) {
Expand All @@ -28,7 +28,7 @@ function applySearchWrappers(SearchViewComponent) {

const [payload, update] = React.useState(appConfigContext);

React.useEffect(() => () => console.log('unmount SearchWrappers'), []);
// React.useEffect(() => () => console.log('unmount SearchWrappers'), []);

return (
<AppConfigContext.Provider value={{ payload, update }}>
Expand Down Expand Up @@ -62,25 +62,19 @@ export default function BasicSearchApp(props) {
...rest
} = props;

const ref = React.useRef();

React.useEffect(() => {
return () => console.log('Unmount BasicSearchApp');
}, []);

React.useEffect(() => {
ref.current = registry;
});

if (!(registry === ref.current))
console.log('BasicSearchApp not isSame', {
current: ref.current,
new: registry,
});

const [stableRegistry] = React.useState(registry);

useWhyDidYouUpdate('BasicSearchApp registry', registry.searchui.minimal);
// const ref = React.useRef();
// React.useEffect(() => {
// return () => console.log('Unmount BasicSearchApp');
// }, []);
// React.useEffect(() => {
// ref.current = registry;
// });
// if (!(registry === ref.current))
// console.log('BasicSearchApp not isSame', {
// current: ref.current,
// new: registry,
// });
// useWhyDidYouUpdate('BasicSearchApp registry', registry.searchui.minimal);

const {
mapContextToProps,
Expand All @@ -90,7 +84,7 @@ export default function BasicSearchApp(props) {
facetOptions,
} = useSearchApp({
appName,
registry: stableRegistry,
registry,
paramOnSearch,
paramOnAutocomplete,
initialState,
Expand All @@ -104,23 +98,23 @@ export default function BasicSearchApp(props) {

const [stableContext, setStableContext] = React.useState({
appConfig,
registry: stableRegistry,
registry,
});

// useDeepCompareEffect(() => {
// setStableContext({ appConfig, registry });
// }, [appConfig, registry]);
useDeepCompareEffect(() => {
setStableContext({ appConfig, registry });
}, [appConfig, registry]);

const WrappedSearchView = React.useMemo(() => {
return mappedWithSearch(applySearchWrappers(searchViewComponent));
}, [mappedWithSearch, searchViewComponent]);

useWhyDidYouUpdate('BasicSearchApp', {
mapContextToProps,
searchViewComponent,
WrappedSearchView,
stableRegistry,
});
// useWhyDidYouUpdate('BasicSearchApp', {
// mapContextToProps,
// searchViewComponent,
// WrappedSearchView,
// registry,
// });

return driverInstance ? (
<SearchProvider config={elasticConfig} driver={driverInstance}>
Expand Down
16 changes: 8 additions & 8 deletions searchlib/components/SearchApp/FacetApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { isEqual } from 'lodash';
import useDeepCompareEffect from 'use-deep-compare-effect';

import { Facet as SUIFacet } from '@eeacms/search/components';
import { useSearchContext, useSearchDriver } from '@eeacms/search/lib/hocs';
import { useSearchContext } from '@eeacms/search/lib/hocs'; // , useSearchDriver

const sorter = (fa, fb) =>
fa.field === fb.field ? 0 : fa.field < fb.field ? -1 : 0;
// const sorter = (fa, fb) =>
// fa.field === fb.field ? 0 : fa.field < fb.field ? -1 : 0;

export default function FacetApp(props) {
const searchContext = useSearchContext();
const { appConfig, registry, field, onChange, value } = props;
// const { field, onChange, value } = props;
const driver = useSearchDriver();
// const driver = useSearchDriver();
// console.log({ searchContext, props, driver });
const { filters, setFilter, removeFilter, addFilter } = searchContext; // driver.state
const { filters, removeFilter, addFilter } = searchContext; // driver.state

const facet = appConfig.facets?.find((f) => f.field === field);
const FacetComponent = registry.resolve[facet.factory].component;
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function FacetApp(props) {

const activeValue = filters.find((f) => f.field === field);

const dirty = !isEqual(activeValue, value);
// const dirty = !isEqual(activeValue, value);
// console.log('redraw facet', { value, activeValue, dirty });

const timerRef = React.useRef();
Expand All @@ -67,7 +67,7 @@ export default function FacetApp(props) {
timerRef.current && clearTimeout(timerRef.current);
timerRef.current = setTimeout(() => {
if (!isEqual(activeValue, value)) {
console.log('onchange', { activeValue, value });
// console.log('onchange', { activeValue, value });
onChange(activeValue);
}
}, 200);
Expand All @@ -77,7 +77,7 @@ export default function FacetApp(props) {
() => () => {
removeFilter(field); // when the Facet is removed, we remove the filter
timerRef.current && clearTimeout(timerRef.current);
console.log('unmount', field);
// console.log('unmount', field);
},
[field, removeFilter],
);
Expand Down
23 changes: 10 additions & 13 deletions searchlib/components/SearchApp/SearchResultsApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,18 @@ export default function SearchResultsApp(props) {
: {}),
...(defaultSort ? { sortField, sortDirection } : {}),
}); // this makes the prop stable

React.useEffect(() => {
return () => console.log('unmount SearchResultsApp');
}, []);

const ref = React.useRef();
const { registry } = props;

React.useEffect(() => {
ref.current = registry;
});

if (!(registry === ref.current))
console.log('SearchResultsApp isSame', ref.current, registry);

// React.useEffect(() => {
// return () => console.log('unmount SearchResultsApp');
// }, []);
// const ref = React.useRef();
// React.useEffect(() => {
// ref.current = registry;
// });
//
// if (!(registry === ref.current))
// console.log('SearchResultsApp isSame', ref.current, registry);
// useWhyDidYouUpdate('SearchResultsApp', { registry });
// console.log('redraw SearchResultsApp');

Expand Down
38 changes: 19 additions & 19 deletions searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { resetFilters, resetSearch } from './request';
import useFacetsWithAllOptions from './useFacetsWithAllOptions';
import { loadingFamily } from './state';
import { SearchDriver } from '@elastic/search-ui';
import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';
// import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';

export function useStoredSearchDriver({ elasticConfig, appName, uniqueId }) {
const [driver, setDriver] = React.useState(null);
Expand All @@ -28,11 +28,11 @@ export function useStoredSearchDriver({ elasticConfig, appName, uniqueId }) {
setDriver(new SearchDriver(elasticConfig));
}, [elasticConfig, appName]);

useWhyDidYouUpdate('setStoredSearchDriver', { elasticConfig, appName });
// useWhyDidYouUpdate('setStoredSearchDriver', { elasticConfig, appName });

React.useEffect(() => {
return () => {
console.log('unmount useStoredSearchDriver');
// console.log('unmount useStoredSearchDriver');
driver && driver.tearDown();
};
}, [driver]);
Expand All @@ -48,10 +48,10 @@ export default function useSearchApp(props) {
paramOnAutocomplete,
initialState,
} = props;
useWhyDidYouUpdate('sss', props);
// useWhyDidYouUpdate('sss', props);

const appConfig = React.useMemo(() => {
console.log('redo appConfig');
// console.log('redo appConfig');
return {
...applyConfigurationSchema(rebind(registry.searchui[appName])),
appName,
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function useSearchApp(props) {
useDeepCompareEffectNoCheck(() => {
if (!driverInstance) {
const driver = new SearchDriver(elasticConfig);
console.log('set driver', driver);
// console.log('set driver', driver);
setDriver(driver);
}
}, [appName]);
Expand Down Expand Up @@ -148,26 +148,26 @@ export default function useSearchApp(props) {
[appConfig, driverInstance, facetOptions],
);

useWhyDidYouUpdate('useSearchApp', {
appConfig,
driverInstance,
facetOptions,
registry,
onAutocomplete,
onSearch,
locationSearchTerm,
initialState,
});
// useWhyDidYouUpdate('useSearchApp', {
// appConfig,
// driverInstance,
// facetOptions,
// registry,
// onAutocomplete,
// onSearch,
// locationSearchTerm,
// initialState,
// });

React.useEffect(() => {
return () => {
driverInstance && driverInstance.tearDown();
};
}, [driverInstance]);

React.useEffect(() => {
return () => console.log('unmount useSearchApp');
}, []);
// React.useEffect(() => {
// return () => console.log('unmount useSearchApp');
// }, []);

return {
facetOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/SearchBlock/SearchBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function SearchBlockView(props) {
const registry = React.useMemo(() => {
// TODO: this has the effect that the appConfig is never stable if the
// schema changes, even if it's unrelated.
console.log('redo registry');
// console.log('redo registry');
const reg = applyBlockSettings(
config.settings.searchlib,
appName,
Expand Down
19 changes: 8 additions & 11 deletions src/SearchBlock/templates/SearchResultsView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import { SearchResultsApp } from '@eeacms/search';
export default function SearchResultsView(props) {
const { appName, mode } = props;

const ref = React.useRef();
const { registry } = props;

React.useEffect(() => {
ref.current = registry;
});

if (!(registry === ref.current))
console.log('SearchResultsView not isSame', ref.current, registry);

React.useEffect(() => () => console.log('unmount SearchResultsView'), []);
// const ref = React.useRef();
// const { registry } = props;
// React.useEffect(() => {
// ref.current = registry;
// });
// if (!(registry === ref.current))
// console.log('SearchResultsView not isSame', ref.current, registry);
// React.useEffect(() => () => console.log('unmount SearchResultsView'), []);

return (
<BodyClass className={`${appName}-view searchlib-page`}>
Expand Down

0 comments on commit 5a81aba

Please sign in to comment.