Skip to content

Instantly share code, notes, and snippets.

@frank-weindel
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frank-weindel/44f4e627f90fb9cac817 to your computer and use it in GitHub Desktop.
Save frank-weindel/44f4e627f90fb9cac817 to your computer and use it in GitHub Desktop.
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