Skip to content

Commit

Permalink
clean up build, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeal committed Mar 18, 2017
1 parent 48ae8e7 commit 1b2fea0
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 79 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Expand Up @@ -24,8 +24,4 @@ coverage
.node_repl_history

# Build directory
/lib
/react-redux-element-portal/lib
/react-redux-element-portal/package.json
/react-redux-element-portal/node_modules
/test/helpers/ReduxElementPortal.js
/build
2 changes: 1 addition & 1 deletion benchmark/transform.js
Expand Up @@ -4,7 +4,7 @@ const suite = new Benchmark.Suite();

import update from 'immutability-helper';
import transform from '../src/transform';
import $set from '../src/navigators/$set';
import $set from '../src/$set';

const state = {
entities: {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/updateIn.js
Expand Up @@ -7,7 +7,7 @@ import updateIn from '../src/updateIn';
import hasIn from '../src/hasIn';
import push from '../src/push';
import set from '../src/set';
import $eachValue from '../src/navigators/$eachValue';
import $eachValue from '../src/$eachValue';
const toUpperCase = s => s.toUpperCase();

const state = {
Expand Down
11 changes: 11 additions & 0 deletions build-package.js
@@ -0,0 +1,11 @@
import pkg from './package.json';
import fs from 'fs';

const newPkg = {
...pkg,
scripts: {},
ava: undefined,
devDependencies: undefined
};

fs.writeFileSync('./build/package.json', JSON.stringify(newPkg, null, 2));
Empty file removed index.js
Empty file.
14 changes: 12 additions & 2 deletions package.json
Expand Up @@ -4,10 +4,19 @@
"description": "Functional style immutability for plain JS with special query sauce.",
"main": "index.js",
"scripts": {
"test": "ava test"
"test": "ava test",
"prebuild": "rm -rf build && mkdir -p build",
"build": "babel src --out-dir build",
"build-package": "babel-node build-package.js",
"prepublish-package": "npm run build && npm run build-package",
"publish-package": "babel-node publish-package.js",
"patch-release": "npm version patch && npm run publish-package && git push --follow-tags"
},
"keywords": [
"immutable"
"immutable",
"select",
"update",
"query"
],
"author": "Justin Deal <justin.deal@gmail.com>",
"license": "MIT",
Expand All @@ -21,6 +30,7 @@
"benchmark": "^2.1.2",
"eslint": "^3.9.0",
"immutability-helper": "^2.1.1",
"shelljs": "^0.7.7",
"sinon": "^1.17.6",
"sprout-data": "^0.2.3"
},
Expand Down
8 changes: 8 additions & 0 deletions publish-package.js
@@ -0,0 +1,8 @@
import shell from 'shelljs';

const cwd = process.cwd();

shell.cd('build');
shell.exec('npm publish', () => {
shell.cd(cwd);
});
4 changes: 2 additions & 2 deletions src/navigators/$eachKey.js → src/$eachKey.js
@@ -1,7 +1,7 @@
import objectAssign from 'object-assign';

import createNavigator from '../createNavigator';
import reduceSequence from '../utils/reduceSequence';
import createNavigator from './createNavigator';
import reduceSequence from './utils/reduceSequence';

const $eachKey = createNavigator({
select: (nav, object, next) => {
Expand Down
4 changes: 2 additions & 2 deletions src/navigators/$eachPair.js → src/$eachPair.js
@@ -1,7 +1,7 @@
import objectAssign from 'object-assign';

import createNavigator from '../createNavigator';
import reduceSequence from '../utils/reduceSequence';
import createNavigator from './createNavigator';
import reduceSequence from './utils/reduceSequence';

const $eachPair = createNavigator({
select: (nav, object, next) => {
Expand Down
4 changes: 2 additions & 2 deletions src/navigators/$eachValue.js → src/$eachValue.js
@@ -1,7 +1,7 @@
import objectAssign from 'object-assign';

import createNavigator from '../createNavigator';
import reduceSequence from '../utils/reduceSequence';
import createNavigator from './createNavigator';
import reduceSequence from './utils/reduceSequence';

const $eachValue = createNavigator({
select: (nav, object, next) => {
Expand Down
6 changes: 5 additions & 1 deletion src/getInOr.js
Expand Up @@ -15,12 +15,16 @@ const getInOr = (defaultValue, path, obj) => {
throw new TypeError('getIn requires array-like object for path');
}

while (pathIndex < path.length && obj !== null) {
while (pathIndex < path.length) {
key = path[pathIndex];
if (key && typeof key !== 'string' && typeof key !== 'number' && typeof key !== 'boolean') {
const selectResult = unreduced(selectEach(null, selectOneResultFn, path, obj, pathIndex));
return isNone(selectResult) ? undefined : selectResult;
}
if (obj == null) {
obj = undefined;
break;
}
obj = obj[key];
pathIndex++;
}
Expand Down
14 changes: 9 additions & 5 deletions src/hasIn.js
Expand Up @@ -18,14 +18,18 @@ const hasIn = (path, obj) => {
}

while (pathIndex < path.length) {
if (obj == null) {
return false;
}
key = path[pathIndex];
if (key && typeof key !== 'string' && typeof key !== 'number' && typeof key !== 'boolean') {
const selectResult = unreduced(selectEach(null, selectOneResultFn, path, obj, pathIndex));
let selectResult = selectEach(null, selectOneResultFn, path, obj, pathIndex);
if (typeof selectResult === 'undefined') {
return false;
}
selectResult = unreduced(selectResult);
return isNone(selectResult) ? false : true;
}
if (obj == null) {
return false;
}
parentObj = obj;
obj = obj[key];
pathIndex++;
Expand All @@ -35,7 +39,7 @@ const hasIn = (path, obj) => {
if (path.length === 0) {
return true;
}
if (!(key in parentObj)) {
if (!parentObj || typeof parentObj !== 'object' || !(key in parentObj)) {
return false;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -11,4 +11,7 @@ export {default as set} from './set';
export {default as setIn} from './setIn';
export {default as update} from './update';
export {default as updateIn} from './updateIn';
export {default as $eachValue} from './navigators/$eachValue';

export {default as $eachKey} from './$eachKey';
export {default as $eachPair} from './$eachPair';
export {default as $eachValue} from './$eachValue';
48 changes: 0 additions & 48 deletions test.js

This file was deleted.

87 changes: 87 additions & 0 deletions test/getIn.js
@@ -0,0 +1,87 @@
import test from 'ava';

import 'babel-core/register';

import {
getIn,
$eachValue,
$eachKey,
$eachPair
} from 'qim/src';

const isEven = value => value % 2 === 0;

test('getIn from primitive', t => {
t.is(
getIn([], 1),
1
);
t.is(
getIn([], null),
null
);
t.is(
getIn(['x'], 1),
undefined
);
t.is(
getIn(['x'], null),
undefined
);
});

test('getIn from object', t => {
t.deepEqual(
getIn([], {x: 1}),
{x: 1}
);
t.deepEqual(
getIn(['x'], {x: 1}),
1
);
});

test('getIn predicate', t => {
t.deepEqual(
getIn([isEven], 1),
undefined
);
t.deepEqual(
getIn([isEven], 2),
2
);
});

test('getIn values', t => {
t.deepEqual(
getIn([$eachValue], [1, 2, 3]),
1
);
t.deepEqual(
getIn([$eachValue, isEven], [1, 2, 3, 4]),
2
);
t.deepEqual(
getIn([$eachValue, 'x'], [{x: 1}, {x: 2}]),
1
);
});

test('getIn keys', t => {
t.deepEqual(
getIn([$eachKey], {x: 1, y: 2}),
'x'
);
});

test('getIn pairs', t => {
t.deepEqual(
getIn([$eachPair], {x: 1, y: 2}),
['x', 1]
);

t.deepEqual(
getIn([$eachPair, 1], {x: 1, y: 2}),
1
);
});
48 changes: 48 additions & 0 deletions test/hasIn.js
@@ -0,0 +1,48 @@
import test from 'ava';

import 'babel-core/register';

import {
hasIn,
$eachValue,
$eachKey,
$eachPair
} from 'qim/src';

const isEven = value => value % 2 === 0;

test('hasIn from primitive', t => {
t.true(hasIn([], 1));
t.true(hasIn([], null));
t.false(hasIn(['x'], 1));
t.false(hasIn(['x'], null));
});

test('hasIn from object', t => {
t.true(hasIn([], {x: 1}));
t.true(hasIn(['x'], {x: 1}));
t.false(hasIn(['y'], {x: 1}));
});

test('hasIn predicate', t => {
t.false(hasIn([isEven], 1));
t.true(hasIn([isEven], 2));
});

test('hasIn values', t => {
t.true(hasIn([$eachValue], [1, 2, 3]));
t.true(hasIn([$eachValue, isEven], [1, 2, 3, 4]));
t.false(hasIn([$eachValue, isEven], [1, 3]));
t.true(hasIn([$eachValue, 'x'], [{x: 1}, {x: 2}]));
t.false(hasIn([$eachValue, 'y'], [{x: 1}, {x: 2}]));
});

test('hasIn keys', t => {
t.true(hasIn([$eachKey], {x: 1, y: 2}));
t.false(hasIn([$eachKey], {}));
});

test('hasIn pairs', t => {
t.true(hasIn([$eachPair], {x: 1, y: 2}));
t.false(hasIn([$eachPair], {}));
});
10 changes: 6 additions & 4 deletions test/selectIn.js
Expand Up @@ -2,10 +2,12 @@ import test from 'ava';

import 'babel-core/register';

import selectIn from 'qim/src/selectIn';
import $eachValue from 'qim/src/navigators/$eachValue';
import $eachKey from 'qim/src/navigators/$eachKey';
import $eachPair from 'qim/src/navigators/$eachPair';
import {
selectIn,
$eachValue,
$eachKey,
$eachPair
} from 'qim/src';

const isEven = value => value % 2 === 0;

Expand Down
12 changes: 7 additions & 5 deletions test/updateIn.js
Expand Up @@ -3,11 +3,13 @@ import test from 'ava';
import 'babel-core/register';
import fp from 'lodash/fp';

import updateIn from 'qim/src/updateIn';
import update from 'qim/src/update';
import $eachValue from 'qim/src/navigators/$eachValue';
import $eachKey from 'qim/src/navigators/$eachKey';
import $eachPair from 'qim/src/navigators/$eachPair';
import {
update,
updateIn,
$eachValue,
$eachKey,
$eachPair
} from 'qim/src';

const increment = value => value + 1;
const isEven = value => value % 2 === 0;
Expand Down

0 comments on commit 1b2fea0

Please sign in to comment.