Skip to content

Instantly share code, notes, and snippets.

@frank-weindel

frank-weindel/example.js

Last active Aug 29, 2015
Embed
What would you like to do?
import { iff } from './globalUtils';
function someRenderFunction() {
return (
<div className="otsPropertyForm">
{iff(showTeamList, () => (
<FormSection>
<FormHeading>Select a Team:</FormHeading>
<ListBox items={teamItems} value={teamId} onChange={this._onTeamListChange} />
</FormSection>
))}
{iff(showPlayList, () => (
<FormSection>
<FormHeading>Select a Play:</FormHeading>
<ListBox items={playList} value={playId} onChange={this._onPlayListChange} height={300} />
</FormSection>
))}
<FormSection>
<FormHeading>Select a Theme:</FormHeading>
<ListBox items={themeItems} value={dark} onChange={this._onThemeListChange} />
</FormSection>
</div>
);
}
/**
* Calls the callback and returns its result if the expression is truthy
*
* @param {string} expression
* @param {Function} callback
* @return {variant} Value of callback() if expression is true. Otherwise 'undefined'
*/
export function iff(expression, callback) {
if (expression) {
return callback();
}
return void 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment