Sha256: 389ff1c916e4aa1e560cf4b18081f271fba4c4b89da794dd441975a7d60926e8

Contents?: true

Size: 1.34 KB

Versions: 69

Compression:

Stored size: 1.34 KB

Contents

const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';

let loggedTypeFailures = {};

/**
 * Reset the history of which prop type warnings have been logged.
 */
export function resetPropWarnings() {
	loggedTypeFailures = {};
}

/**
 * Assert that the values match with the type specs.
 * Error messages are memorized and will only be shown once.
 *
 * Adapted from https://github.com/facebook/prop-types/blob/master/checkPropTypes.js
 *
 * @param {object} typeSpecs Map of name to a ReactPropType
 * @param {object} values Runtime values that need to be type-checked
 * @param {string} location e.g. "prop", "context", "child context"
 * @param {string} componentName Name of the component for error messages.
 * @param {?Function} getStack Returns the component stack.
 */
export function checkPropTypes(
	typeSpecs,
	values,
	location,
	componentName,
	getStack
) {
	Object.keys(typeSpecs).forEach(typeSpecName => {
		let error;
		try {
			error = typeSpecs[typeSpecName](
				values,
				typeSpecName,
				componentName,
				location,
				null,
				ReactPropTypesSecret
			);
		} catch (e) {
			error = e;
		}
		if (error && !(error.message in loggedTypeFailures)) {
			loggedTypeFailures[error.message] = true;
			console.error(
				`Failed ${location} type: ${error.message}${(getStack &&
					`\n${getStack()}`) ||
					''}`
			);
		}
	});
}

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
isomorfeus-preact-10.6.30 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.29 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.28 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.27 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.26 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.25 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.24 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.23 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.22 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.21 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.20 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.19 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.18 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.17 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.16 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.15 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.2 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.1 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.6.0 node_modules/preact/debug/src/check-props.js
isomorfeus-preact-10.5.11 node_modules/preact/debug/src/check-props.js