Ability to override default isComponentOfType implementation (#1164)
parent
eff4b841b8
commit
49d660534e
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue