How to use shallow-equal - 10 common examples

To help you get started, we’ve selected a few shallow-equal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github otakustay / react-diff-view / src / hooks / useTokenizeWorker.js View on Github external
const defaultShouldTokenize = ({hunks: currentHunks, ...currentPayload}, {hunks: prevHunks, ...prevPayload}) => {
    if (currentPayload.oldSource !== prevPayload.oldSource) {
        return true;
    }

    // When `oldSource` is provided, we can get the new source by applying diff,
    // so when hunks keep identical, the tokenize result will always remain the same.
    if (currentPayload.oldSource) {
        return !shallowEquals(currentPayload, prevPayload) || !areHunksEqual(currentHunks, prevHunks);
    }

    return currentHunks !== prevHunks || !shallowEquals(currentPayload, prevPayload);
};
github iuap-design / bee.tinper.org / tinper-bee / bee-cascader / src / rc / index.jsx View on Github external
static getDerivedStateFromProps(nextProps, prevState) {
    const { prevProps = {} } = prevState;
    const newState = {
      prevProps: nextProps,
    };

    if ('value' in nextProps && !shallowEqualArrays(prevProps.value, nextProps.value)) {
      newState.value = nextProps.value || [];

      // allow activeValue diff from value
      if (!('loadData' in nextProps)) {
        newState.activeValue = nextProps.value || [];
      }
      newState.inputValue = self.convertStringToObject(self.props.options,nextProps,[],0,).map(o =>o.label).join('/ ') || ''
    }
    if ('popupVisible' in nextProps) {
      newState.popupVisible = nextProps.popupVisible;
    }
    if ('options' in nextProps) {
			newState.options = nextProps.options || [];
    }
    if ('inputValue' in nextProps) {
      newState.inputValue = nextProps.inputValue;
github unihooks / unihooks / src / useMedia.js View on Github external
useEffect(() => {
    const newDevice = getDevice()
    if (!areObjectsEqual(device, newDevice)) {
      setDevice(newDevice)
    }
  }, [deviceFromProps, deviceFromContext])
github digidem / react-mapfilter / src / containers / MapFilter.js View on Github external
componentWillReceiveProps (nextProps) {
    if (shallowEqual(this.props, nextProps)) return
    const stateOverride = pick(nextProps, controllableProps)
    this.store.controlledUpdate(stateOverride)
  }
github nkbt / component-router / src / reducer.js View on Github external
export const isActive = (state, {pathname, query}) => {
  const {
    pathname: prevPathname,
    cleanQuery: prevCleanQuery
  } = state;
  const {
    pathname: nextPathname,
    cleanQuery: nextCleanQuery
  } = changeParams(state, {pathname, query});

  return shallowEqual(nextCleanQuery, prevCleanQuery) && nextPathname === prevPathname;
};
github arackaf / booklist / react / modules / books / booksSearchState.ts View on Github external
export function bookSearchReducer(state = initialState, action): BookSearchState {
  switch (action.type) {
    case SET_BASIC_LIST_VIEW:
      localStorage.set("book-ui", BASIC_LIST_VIEW);
      return { ...state, view: BASIC_LIST_VIEW };
    case SET_GRID_VIEW:
      localStorage.set("book-ui", GRID_VIEW);
      return { ...state, view: GRID_VIEW };
    case SET_COVERS_LIST_VIEW:
      localStorage.set("book-ui", COVERS_LIST);
      return { ...state, view: COVERS_LIST };
    case HASH_CHANGED:
      let { filters } = action;
      if (!shallowEqual(filters, state.hashFilters)) {
        return { ...state, hashFilters: filters };
      }
      return { ...state };
  }
  return state;
}
github aduth / dones / src / components / query-dones / index.js View on Github external
componentDidUpdate( prevProps ) {
		if ( shallowEqual( this.props.query, prevProps.query ) ) {
			return;
		}

		this.props.requestDones( this.props.query );
	}
github LearningLocker / learninglocker / ui / src / containers / FullActivitiesList / index.js View on Github external
shouldUpdate((
    { objectIds, ...props },
    { objectIds: nextObjectIds, ...nextProps }
  ) => {
    const out = !(
      objectIds.equals(nextObjectIds)
      && shallowEqualObjects(
        props,
        nextProps, ['shouldFetch', 'isLoading']
      )
    );
    return out;
  }),
)(fullActivitiesList);
github arackaf / booklist / react-redux / modules / books / reducers / bookSearch / reducer.ts View on Github external
export function bookSearchReducer(state = initialState, action): BookSearchType {
  switch (action.type) {
    case SET_BASIC_LIST_VIEW:
      return { ...state, view: BASIC_LIST_VIEW };
    case SET_GRID_VIEW:
      return { ...state, view: GRID_VIEW };
    case HASH_CHANGED:
      let { filters } = action;
      if (!shallowEqual(filters, state.hashFilters)) {
        return { ...state, hashFilters: filters };
      }
      return { ...state };
  }
  return state;
}
github nkbt / component-router / src / reducer.js View on Github external
export const componentRouter = (state = initialState, {type, ...payload}) => {
  const newState = reduce(state, {type, ...payload});

  return shallowEqual(state, newState) ? state : newState;
};

shallow-equal

Typescript-compatible minimalistic shallow equality check for arrays/objects

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis