Flow, coding style

This commit is contained in:
Lyubo Marinov
2017-10-04 17:36:09 -05:00
parent 4c00d39bf2
commit f53c79ab24
18 changed files with 266 additions and 178 deletions

View File

@@ -1,3 +1,5 @@
// @flow
import PropTypes from 'prop-types';
import { Component } from 'react';
@@ -28,18 +30,21 @@ export default class AbstractDialog extends Component {
dispatch: PropTypes.func
};
_mounted: boolean;
state = {
};
/**
* Initializes a new {@code AbstractDialog} instance.
*
* @param {Object} props - The read-only React {@code Component} props with
* which the new instance is to be initialized.
*/
constructor(props) {
constructor(props: Object) {
super(props);
this.state = {
};
// Bind event handlers so they are only bound once per instance.
this._onCancel = this._onCancel.bind(this);
this._onSubmit = this._onSubmit.bind(this);
this._onSubmitFulfilled = this._onSubmitFulfilled.bind(this);
@@ -66,6 +71,8 @@ export default class AbstractDialog extends Component {
this._mounted = false;
}
_onCancel: () => void;
/**
* Dispatches a redux action to hide this dialog when it's canceled.
*
@@ -81,19 +88,21 @@ export default class AbstractDialog extends Component {
}
}
_onSubmit: (?string) => void;
/**
* Submits this dialog. If the React {@code Component} prop
* Submits this {@code Dialog}. If the React {@code Component} prop
* {@code onSubmit} is defined, the function that is the value of the prop
* is invoked. If the function returns a {@code thenable}, then the
* resolution of the {@code thenable} is awaited. If the submission
* completes successfully, a redux action will be dispatched to hide this
* dialog.
*
* @private
* @param {string} value - The submitted value if any.
* @protected
* @param {string} [value] - The submitted value if any.
* @returns {void}
*/
_onSubmit(value) {
_onSubmit(value: ?string) {
const { okDisabled, onSubmit } = this.props;
if (typeof okDisabled === 'undefined' || !okDisabled) {
@@ -125,6 +134,8 @@ export default class AbstractDialog extends Component {
}
}
_onSubmitFulfilled: () => void;
/**
* Notifies this {@code AbstractDialog} that it has been submitted
* successfully. Dispatches a redux action to hide this dialog after it has
@@ -139,6 +150,8 @@ export default class AbstractDialog extends Component {
this.props.dispatch(hideDialog());
}
_onSubmitRejected: () => void;
/**
* Notifies this {@code AbstractDialog} that its submission has failed.
*

View File

@@ -108,14 +108,9 @@ class Dialog extends AbstractDialog {
// Secondly, we cannot get Prompt's default behavior anyway
// because we've removed Prompt and we're preserving whatever
// it's rendered only.
return (
React.cloneElement(
element,
/* props */ {
onRequestClose: this._onCancel
},
...React.Children.toArray(element.props.children))
);
return this._cloneElement(element, /* props */ {
onRequestClose: this._onCancel
});
}
if (type === TextInput) {
@@ -146,14 +141,9 @@ class Dialog extends AbstractDialog {
break;
}
return (
React.cloneElement(
element,
/* props */ {
style: set(style, _TAG_KEY, undefined)
},
...React.Children.toArray(element.props.children))
);
return this._cloneElement(element, /* props */ {
style: set(style, _TAG_KEY, undefined)
});
}
}
@@ -163,6 +153,23 @@ class Dialog extends AbstractDialog {
return element;
}
/**
* Clones a specific {@code ReactElement} and adds/merges specific props
* into the clone.
*
* @param {ReactElement} element - The {@code ReactElement} to clone.
* @param {Object} props - The props to add/merge into the clone.
* @returns {ReactElement} The close of the specified {@code element} with
* the specified {@code props} added/merged.
*/
_cloneElement(element, props) {
return (
React.cloneElement(
element,
props,
...React.Children.toArray(element.props.children)));
}
/**
* Creates a deep clone of a specific {@code ReactElement} with the results
* of calling a specific function on every node of a specific