How to use the shallow-equal/objects function in shallow-equal

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 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;
};
github nkbt / component-router / src / reducer.js View on Github external
export const changeParams = (state, params) => {
  const {defaultParams, query, pathname} = state;
  const newQuery = sortedObject({...defaultParams, ...query, ...safeQuery(params.query)});
  const newPathname = params.pathname || pathname;

  if (shallowEqual(newQuery, query) && newPathname === pathname) {
    return state;
  }

  const cleanQuery = cleanupQuery({query: newQuery, defaultParams});
  const currentRoute = matchRoute(state.routes)(newPathname);

  return {
    ...state,
    query: newQuery,
    pathname: newPathname,
    cleanQuery,
    currentRoute
  };
};

shallow-equal

Typescript-compatible minimalistic shallow equality check for arrays/objects

MIT
Latest version published 2 years ago

Package Health Score

71 / 100
Full package analysis