UNPKG

bottender-compose

Version:

An utility library for bottender and higher-order handlers

27 lines (20 loc) 548 B
"use strict"; const curry = require('lodash/curry'); const { withProps } = require('bottender'); function Noop() {} const branch = (predicate, OnTrue, OnFalse = Noop) => { const Fn = async (context, props) => { if (await predicate(context, props)) { return withProps(OnTrue, props); } return withProps(OnFalse, props); }; const name = `Branch(${OnTrue.name || 'Anonymous'}, ${OnFalse.name || 'Anonymous'})`; Object.defineProperty(Fn, 'name', { value: name }); return Fn; }; module.exports = curry(branch);