Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Made all functional props nullable #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions src/components/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to include these in defaultProps anymore!

onChange: undefined,
onBlur: undefined,
onFocus: undefined,
onReady: undefined,
};

static contextTypes = {
Expand Down Expand Up @@ -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) => {
Expand Down