IfElse.js 771 B

12345678910111213141516171819202122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const utils_1 = require("./utils");
  4. function ifElse(condition, ifTrueFragment, elseFragment) {
  5. return new IfElse(condition, ifTrueFragment, elseFragment);
  6. }
  7. exports.ifElse = ifElse;
  8. class IfElse {
  9. constructor(condition, ifTrueFragment, elseFragment) {
  10. this.condition = condition;
  11. this.ifTrueFragment = ifTrueFragment;
  12. this.elseFragment = elseFragment;
  13. }
  14. build() {
  15. const value = Boolean(typeof this.condition === 'function' ? this.condition() : this.condition);
  16. return utils_1.buildChildren([
  17. value ? this.ifTrueFragment : this.elseFragment || '',
  18. ]);
  19. }
  20. }
  21. exports.IfElse = IfElse;
  22. //# sourceMappingURL=IfElse.js.map