From b8ca7f540799d80a5be950425d9ca56a5e8c1d1c Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Fri, 11 Sep 2015 11:57:39 -0700 Subject: [PATCH] Use identity with u.if's false condition Fixes #35 --- lib/if.js | 2 +- package.json | 1 + test/if-spec.js | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/if.js b/lib/if.js index 1e9ed2d..d8b1eac 100644 --- a/lib/if.js +++ b/lib/if.js @@ -2,5 +2,5 @@ import ifElse from './ifElse'; import curry from './util/curry'; export default curry((predicate, trueUpdates, object) => - ifElse(predicate, trueUpdates, {}, object) + ifElse(predicate, trueUpdates, x => x, object) ); diff --git a/package.json b/package.json index 35c605e..683f88d 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ ], "scripts": { "test": "gulp", + "test:watch": "gulp watch", "prepublish": "gulp prepublish", "perf-server": "`npm bin`/webpack-dev-server --config perf/webpack.config.js --hot" }, diff --git a/test/if-spec.js b/test/if-spec.js index 399383f..7f7f485 100644 --- a/test/if-spec.js +++ b/test/if-spec.js @@ -4,8 +4,11 @@ import u from '../lib'; describe('u.if', () => { it('does not update if the predicate is false', () => { const object = { a: 0 }; - const result = u.if(false, { b: 1 }, object); + let result = u.if(false, { b: 1 }, object); expect(result).to.eql(object); + + result = u({ x: u.if(false, 1)}, {}); + expect(result).to.eql({}); }); it('does update if the predicate is true', () => {