From fa27ef44235515916185f1ed4d5ec9915b342919 Mon Sep 17 00:00:00 2001 From: Nikita Sviridenko Date: Sat, 23 Sep 2017 10:27:53 +0200 Subject: [PATCH] Made all functional props nullable --- src/components/Element.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/Element.js b/src/components/Element.js index 722f921..17740fb 100644 --- a/src/components/Element.js +++ b/src/components/Element.js @@ -6,15 +6,13 @@ import type {ElementContext} from './Elements'; type Props = { className: string, - elementRef: Function, - onChange: Function, - onBlur: Function, - onFocus: Function, - onReady: Function, + elementRef: ?Function, + onChange: ?Function, + onBlur: ?Function, + onFocus: ?Function, + onReady: ?Function, }; -const noop = () => {}; - const _extractOptions = (props: Props): Object => { const { className, @@ -40,11 +38,11 @@ const Element = (type: string, hocOptions: {sourceType?: string} = {}) => }; static defaultProps = { className: '', - elementRef: noop, - onChange: noop, - onBlur: noop, - onFocus: noop, - onReady: noop, + elementRef: undefined, + onChange: undefined, + onBlur: undefined, + onFocus: undefined, + onReady: undefined, }; static contextTypes = { @@ -90,16 +88,22 @@ const Element = (type: string, hocOptions: {sourceType?: string} = {}) => _setupEventListeners() { this._element.on('ready', () => { - this.props.elementRef(this._element); - this.props.onReady(); + this.props.elementRef && this.props.elementRef(this._element); + this.props.onReady && this.props.onReady(); }); this._element.on('change', change => { - this.props.onChange(change); + this.props.onChange && this.props.onChange(change); }); - this._element.on('blur', (...args) => this.props.onBlur(...args)); - this._element.on('focus', (...args) => this.props.onFocus(...args)); + this._element.on( + 'blur', + (...args) => this.props.onBlur && this.props.onBlur(...args) + ); + this._element.on( + 'focus', + (...args) => this.props.onFocus && this.props.onFocus(...args) + ); } handleRef = (ref: ?HTMLElement) => {