Blame view
imports/client/components/Logic.js
656 Bytes
ff976df49
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import _ from 'lodash'; import React, { Component } from 'react'; const instance = (value) => ( _.isFunction(value) ? value() : (value || null) ); export class If extends Component { render() { return this.props.if ? instance(this.props.then) : instance(this.props.else); }; }; export class Case extends Component { render() { const val = this.props.switch; for(let i = 0; i < 999; ++i) { if(this.props['case' + i] === undefined) return instance(this.props.else); if(this.props['case' + i] === val) return instance(this.props['then' + i]); } return null; }; }; |