Ability to override default isComponentOfType implementation (#1164)

old
Valery Bugakov 2017-01-22 19:50:33 +03:00 committed by Javi Velasco
parent eff4b841b8
commit 49d660534e
2 changed files with 26 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import './utils/polyfills'; // Import polyfills for IE11
export { overrideComponentTypeChecker } from './utils/is-component-of-type';
export AppBar from './app_bar';
export Autocomplete from './autocomplete';
export Avatar from './avatar';

View File

@ -1,9 +1,33 @@
let customChecker;
/**
* Sets customChecker which will be used for all components.
*
* @param providedChecker {Function} - Checker function
*/
export function overrideComponentTypeChecker (providedChecker) {
customChecker = providedChecker;
}
/**
* Returns true if the provided element is a component of the provided type.
*
* @param classType {ReactElement class} - the class of a React Element
* @param reactElement {ReactElement} - any React Element (not a real DOM node)
*/
export default function isComponentOfType (classType, reactElement) {
export function defaultChecker (classType, reactElement) {
return reactElement && reactElement.type === classType;
}
/**
* Executes customChecker if it's set or defaultChecker.
*
* @param classType {ReactElement class} - the class of a React Element
* @param reactElement {ReactElement} - any React Element (not a real DOM node)
*/
export default function isComponentOfType (classType, reactElement) {
return customChecker
? customChecker(classType, reactElement)
: defaultChecker(classType, reactElement);
}