How to use the @wordpress/is-shallow-equal.isShallowEqualObjects function in @wordpress/is-shallow-equal

To help you get started, we’ve selected a few @wordpress/is-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 WordPress / gutenberg / packages / data / src / components / with-select / index.js View on Github external
onStoreChange() {
			if ( ! this.canRunSelection ) {
				this.hasQueuedSelection = true;
				return;
			}

			const nextMergeProps = getNextMergeProps( this.props );
			if ( isShallowEqualObjects( this.mergeProps, nextMergeProps ) ) {
				return;
			}

			this.mergeProps = nextMergeProps;

			// Schedule an update. Merge props are not assigned to state since
			// derivation of merge props from incoming props occurs within
			// shouldComponentUpdate, where setState is not allowed. setState
			// is used here instead of forceUpdate because forceUpdate bypasses
			// shouldComponentUpdate altogether, which isn't desireable if both
			// state and props change within the same render. Unfortunately,
			// this requires that next merge props are generated twice.
			this.setState( {} );
		}
github WordPress / gutenberg / packages / data / src / components / with-select / index.js View on Github external
const hasSyncRenderingChanged = nextProps.isAsync !== this.props.isAsync;

			if ( hasRegistryChanged ) {
				this.unsubscribe();
				this.subscribe( nextProps.registry );
			}

			if ( hasSyncRenderingChanged ) {
				renderQueue.flush( this );
			}

			// Treat a registry change as equivalent to `ownProps`, to reflect
			// `mergeProps` to rendered component if and only if updated.
			const hasPropsChanged = (
				hasRegistryChanged ||
				! isShallowEqualObjects( this.props.ownProps, nextProps.ownProps )
			);

			// Only render if props have changed or merge props have been updated
			// from the store subscriber.
			if ( this.state === nextState && ! hasPropsChanged && ! hasSyncRenderingChanged ) {
				return false;
			}

			if ( hasPropsChanged || hasSyncRenderingChanged ) {
				const nextMergeProps = getNextMergeProps( nextProps );
				if ( ! isShallowEqualObjects( this.mergeProps, nextMergeProps ) ) {
					// If merge props change as a result of the incoming props,
					// they should be reflected as such in the upcoming render.
					// While side effects are discouraged in lifecycle methods,
					// this component is used heavily, and prior efforts to use
					// `getDerivedStateFromProps` had demonstrated miserable
github WordPress / gutenberg / packages / data / src / components / with-select / index.js View on Github external
// Treat a registry change as equivalent to `ownProps`, to reflect
			// `mergeProps` to rendered component if and only if updated.
			const hasPropsChanged = (
				hasRegistryChanged ||
				! isShallowEqualObjects( this.props.ownProps, nextProps.ownProps )
			);

			// Only render if props have changed or merge props have been updated
			// from the store subscriber.
			if ( this.state === nextState && ! hasPropsChanged && ! hasSyncRenderingChanged ) {
				return false;
			}

			if ( hasPropsChanged || hasSyncRenderingChanged ) {
				const nextMergeProps = getNextMergeProps( nextProps );
				if ( ! isShallowEqualObjects( this.mergeProps, nextMergeProps ) ) {
					// If merge props change as a result of the incoming props,
					// they should be reflected as such in the upcoming render.
					// While side effects are discouraged in lifecycle methods,
					// this component is used heavily, and prior efforts to use
					// `getDerivedStateFromProps` had demonstrated miserable
					// performance.
					this.mergeProps = nextMergeProps;
				}

				// Regardless whether merge props are changing, fall through to
				// incur the render since the component will need to receive
				// the changed `ownProps`.
			}

			return true;
		}

@wordpress/is-shallow-equal

Test for shallow equality between two objects or arrays.

GPL-2.0-or-later
Latest version published 6 days ago

Package Health Score

95 / 100
Full package analysis