Coding style: utilize default values

Since they are a language feature, they make the source code more easily
comprehensible than `if (typeof XXX === 'undefined') { XXX = ...; }`.
This commit is contained in:
Lyubo Marinov 2018-09-07 12:40:10 -05:00 committed by Любомир Маринов
parent ee9f304345
commit 1d128e027a
4 changed files with 8 additions and 15 deletions

View File

@ -86,10 +86,9 @@ export default class AbstractDialog<P : Props, S : State>
* @returns {void} * @returns {void}
*/ */
_onCancel() { _onCancel() {
const { cancelDisabled, onCancel } = this.props; const { cancelDisabled = false, onCancel } = this.props;
if ((typeof cancelDisabled === 'undefined' || !cancelDisabled) if (!cancelDisabled && (!onCancel || onCancel())) {
&& (!onCancel || onCancel())) {
this._hide(); this._hide();
} }
} }
@ -109,9 +108,9 @@ export default class AbstractDialog<P : Props, S : State>
* @returns {void} * @returns {void}
*/ */
_onSubmit(value: ?string) { _onSubmit(value: ?string) {
const { okDisabled, onSubmit } = this.props; const { okDisabled = false, onSubmit } = this.props;
if (typeof okDisabled === 'undefined' || !okDisabled) { if (!okDisabled) {
this.setState({ submitting: true }); this.setState({ submitting: true });
// Invoke the React Compnent prop onSubmit if any. // Invoke the React Compnent prop onSubmit if any.

View File

@ -22,11 +22,8 @@ export default class Container extends AbstractContainer {
* @returns {ReactElement} * @returns {ReactElement}
*/ */
render() { render() {
const { visible } = this.props; const { visible = true } = this.props;
return ( return visible ? super._render('div') : null;
typeof visible === 'undefined' || visible
? super._render('div')
: null);
} }
} }

View File

@ -19,9 +19,9 @@ const logger = require('jitsi-meet-logger').getLogger(__filename);
* otherwise, {@code false}. * otherwise, {@code false}.
*/ */
export function isCalendarEnabled() { export function isCalendarEnabled() {
const { calendarEnabled } = NativeModules.AppInfo; const { calendarEnabled = true } = NativeModules.AppInfo;
return typeof calendarEnabled === 'undefined' ? true : calendarEnabled; return calendarEnabled;
} }
/** /**

View File

@ -85,9 +85,6 @@ export class AbstractClosedCaptionButton
export function _abstractMapStateToProps(state: Object, ownProps: Object) { export function _abstractMapStateToProps(state: Object, ownProps: Object) {
const { _requestingSubtitles } = state['features/subtitles']; const { _requestingSubtitles } = state['features/subtitles'];
const { transcribingEnabled } = state['features/base/config']; const { transcribingEnabled } = state['features/base/config'];
// Default 'visible' to 'transcribingEnabled' if not explicitly specified
// in the component's properties.
const { visible = transcribingEnabled } = ownProps; const { visible = transcribingEnabled } = ownProps;
return { return {