export default ({ state, trigger }) => { const updateInput = ev => state.ui.set('input', ev.currentTarget.value).now(); return ( h('header.header', [ h('h1', 'todos'), h('input.new-todo', { props: { placeholder: 'What needs to be done?', autofocus: true, value: state.ui.input }, on: { input: updateInput, keydown: R.when( R.propEq('keyCode', ENTER_KEY), R.pipe( R.prop('currentTarget'), R.prop('value'), R.trim, R.unless( R.isEmpty, val => trigger('save', val) ) ) ) } }) ]) ); };
export const getKeysFromIfplId = ifplId => R.pipe( getKeys, R.propOr(null, ifplId), R.unless( R.isNil, R.assoc('ifplId', ifplId), ), );
const getOneById = _.curry((db, sql, id, no_cache = false) => { const throwError = bindError(throwNotFoundError, sql, id); return getOne(db, sql, [id], no_cache) .tap(_.unless(idMatch(id), throwError)); });
export function setRefreshMetadata(element, action) { let { metadata, readId } = action return flow( element, R.unless( el => el == null || readId !== getReadId(el), setRefreshMeta(metadata) ) ) }
const getOne = _.curry((db, sql, params, no_cache = false) => { const throwError = bindError(throwNotFoundError, sql, params); return select(db, sql, params, no_cache) .then(_.head) .then(_.unless(_.identity, throwError)); });
// binded :: Ctor || Object -> Object function binded(input) { return R.pipe( R.unless( R.or(R.is(Object), R.is(Function)), () => { throw new TypeError(errorText('input', Object, Function, input)); } ), Object.getOwnPropertyNames, R.without(strictModeIncompatibleProps), R.filter(R.propSatisfies(R.is(Function), R.__, input)), R.reduce(bind(input), {}) )(input); }
function(parent) { const selection = thread( parent, selectAll(prop('selector', vNode)), dataFn(joinData, keySelector)); const enterSelection = thread( selection, enter, introduceNode(vNode, insertSelector), enterTransform); thread( selection, attr(boundAttributes(vNode)), style(boundStyle(vNode)), unless(always(isNil(boundTextContent(vNode))), text(boundTextContent(vNode))), updateTransform); thread( vNode, constantChildren, forEach(partialRight(introduceNode, [null, enterSelection]))); thread( vNode, boundChildren, forEach(child => child(selection))); thread( selection, exit, exitTransform, remove); return selection; };
const checkParam = (test, msg) => _.unless(test, () => { throw new TypeError(msg) });
const explicitMultipleOperators = R.allPass([ explicitOperator, R.compose(R.gt(R.__, 1), R.length, R.keys, R.last), R.compose(R.not, R.path([1, regexOptionsKey])) ]) const getQueryTypeFn = R.flip(R.propOr(R.T))(queryValueTypes) function throwOnInvalidQueryVal(q) { throw new Error(q.op + " query value (" + q.val + ") isn't valid") } const assertValidQueryValue = R.compose( R.unless( R.converge(R.call, [ R.compose(getQueryTypeFn, R.prop("op")), R.prop("val") ]), throwOnInvalidQueryVal ) ) const formatQuery = R.compose( assertValidQueryValue, R.applySpec({ _type: R.always("query"), key: R.head, op: R.nth(1), val: R.last }) ) const formatCompound = R.curryN(2, R.applySpec({
'Possibilities parameter must be a non-empty array.'; const throwTypeError = (message) => () => { throw new TypeError(message); }; // isComparator : * -> Bool const isComparator = _.both( _.is(Function) , _.compose(_.equals(2), _.length) ); // validateComparator : * -> * : throws TypeError const validateComparator = _.unless( isComparator , throwTypeError(ERROR_MESSAGE_COMPARATOR) ); // isValidPossibilitiesArray : * -> Bool const isValidPossibilitiesArray = _.both( _.partial(typeCheck, ['[String]']) , _.compose(_.not, _.isEmpty) ); // validatePossibilities : * -> * : throws TypeError const validatePossibilites = _.unless( isValidPossibilitiesArray , throwTypeError(ERROR_MESSAGE_POSSIBILITIES) );
const keyDownMod = (key, activeKeys) => unless(contains(key), append(key))(activeKeys)
const contractP = R.curry((name, ctor, param) => R.unless( R.is(ctor), () => reject(new TypeError(errorText(name, ctor, param))) )(param));
const contract = R.curry((name, ctor, param) => R.unless( R.is(ctor), () => { throw new TypeError(errorText(name, ctor, param)); } )(param));
var step = function(scenarios) { var thenClauses = toBeApplied(scenarios); return R.map(R.unless(R.complement(R.prop('unapplied')),applyThenClauses(thenClauses)), markUnaplied(scenarios)); }
export default (value: ?any, fn: Function): ?any => unless( isNil, fn, )(value);
// but can actually catch some bugs statically const psatE: boolean = _.pathSatisfies(y => y > 0, ["x", "y"], { x: { y: 2 } }); const psat: boolean = _.pathSatisfies( y => typeof y === "number" && y > 0, ["x", "y"], { x: { y: 2 } } ); const psatPart = _.pathSatisfies(y => typeof y === "number" && y > 0); const psat2: boolean = psatPart(["x", "y"])({ x: { y: 2 }, z: true }); const psatPart2 = _.pathSatisfies(y => typeof y === "number" && y > 0, [ "x", "y" ]); const psat3: boolean = psatPart2({ x: { y: 2 }, z: true }); const propSat: boolean = _.propSatisfies(x => x > 0, "x", { x: 1, y: 2 }); const coerceArray = _.unless(_.isArrayLike, _.of); const coer: Array<number | Array<number>> | number = coerceArray([1, 2, 3]); const coer1: Array<number | Array<number>> | number = coerceArray(1); const coerceString = _.unless(_.is(String), _.toString); const coer2: string | Array<number> = coerceString([1, 2, 3]); const coer3: string | Array<number> = coerceString("s"); const unlPrt = _.unless(_.is(Number), _.T); const unl: number | boolean | Array<number> = unlPrt([1, 2, 3]); const unl2: number | boolean | Array<number> = unlPrt(1); const un: number = _.until(_.gt(100), _.multiply(2))(1);
constructor() { super(); Eventify.enable(this); this.player = new Player(); this.stats = new Stats(this); this.hud = new Hud(this); this.level = new Level(this); this.level.on('collect', item => { if (isGood(item)) { this.trigger('collect', item.type); } else { if (item.type === this.player.type) { this.trigger('collect', item.type); } else { this.trigger('error', item.type); } } }); this.level.on('delete', R.unless(isGood, () => this.trigger('error'))); this.on('error', play('error')); let starCombo = 0; this.on('collect', R.ifElse( R.equals(STAR), () => stars.play(Math.min(6, ++starCombo)), R.pipe(play('pickup'), () => { starCombo = 0; }) )); this.on('error', () => { starCombo = 0; }); this.level.on('levelup', level => levels.play(level)); this.handler = new KeyHandler(); this.isMovingLeft = false; this.isMovingRight = false; this.paused = false; this.stats.on('life', R.when(R.gte(0), () => this.trigger('gameover'))); this.on('gameover', () => { this.paused = true; }); this.on('pause', () => { this.paused = true; }); this.on('unpause', () => { if (this.stats.life === 0) { this.trigger('start'); } this.paused = false; }); const setPlayerType = type => () => { this.player.type = type; }; this.handler.addKeyDownListener('KeyQ', setPlayerType(CIRCLE)); this.handler.addKeyDownListener('KeyW', setPlayerType(SQUARE)); this.handler.addKeyDownListener('KeyE', setPlayerType(TRIANGLE)); this.handler.addKeyDownListener('KeyR', setPlayerType(HEXAGON)); this.handler.addKeyDownListener('Space', () => this.player.shiftIt()); this.handler.addKeyDownListener('Escape', () => { if (this.paused) { this.trigger('unpause'); } else { this.trigger('pause'); } }); this.handler.addKeyDownListener(['ArrowLeft', 'KeyJ'], () => { this.isMovingLeft = true; }); this.handler.addKeyDownListener(['ArrowRight', 'KeyK'], () => { this.isMovingRight = true; }); this.handler.addKeyUpListener(['ArrowLeft', 'KeyJ'], () => { this.isMovingLeft = false; }); this.handler.addKeyUpListener(['ArrowRight', 'KeyK'], () => { this.isMovingRight = false; }); this.addChild(this.player); this.addChild(this.level); this.addChild(this.hud); }