From 32d471576c0f6f00ebfdf0c7f7fd8f9866d78834 Mon Sep 17 00:00:00 2001 From: Thibault Maekelbergh Date: Mon, 21 Nov 2016 01:28:58 +0100 Subject: [PATCH] :zap: Use lodash.find instead of lodash 80kb module download instead of 4.8MB #18 Signed-off-by: Thibault Maekelbergh --- .babelrc | 4 ++++ __mocks__/composedFetch.js | 23 +++++++++++++++++++++++ package.json | 2 +- rollup.config.js | 3 --- src/lib/methods/events.js | 2 +- src/lib/methods/getStatus.js | 2 +- src/lib/methods/postalPoint.js | 2 +- yarn.lock | 6 +++++- 8 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 __mocks__/composedFetch.js diff --git a/.babelrc b/.babelrc index 6bd7e67..a0c3fbb 100644 --- a/.babelrc +++ b/.babelrc @@ -12,6 +12,10 @@ "presets": [ ["es2015", {"loose": true, "modules": false}] ] + }, + "test": { + "presets": ["es2015"], + "plugins": ["transform-async-to-generator"] } } } diff --git a/__mocks__/composedFetch.js b/__mocks__/composedFetch.js new file mode 100644 index 0000000..69abb67 --- /dev/null +++ b/__mocks__/composedFetch.js @@ -0,0 +1,23 @@ +const statusResult = { + name: `delivered`, + status: `active`, + label: { + main: `pickedUp`, + detail: `inPostPoint`, + }, + knownProcessStep: `PICKED_UP_IN_POST_POINT_INTERNATIONAL`, +}; + +const composedFetch = id => { + return new Promise((resolve, reject) => { + process.nextTick(() => + statusResult[status] === `active` + ? resolve(statusResult) + : reject({ + error: `no active step found for ${id}`, + }) + ); + }); +}; + +export default composedFetch; diff --git a/package.json b/package.json index 030917a..5872e13 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,6 @@ }, "dependencies": { "axios": "^0.15.2", - "lodash": "^4.17.2" + "lodash.find": "^4.6.0" } } diff --git a/rollup.config.js b/rollup.config.js index 3f820b7..6ddeb1b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -14,9 +14,6 @@ const plugins = [ }), commonjs({ include: `node_modules/**`, - namedExports: { - 'node_modules/lodash/lodash.js': [`find`], - }, }), bundleSize(), ]; diff --git a/src/lib/methods/events.js b/src/lib/methods/events.js index 7e5e740..e64fc87 100644 --- a/src/lib/methods/events.js +++ b/src/lib/methods/events.js @@ -1,4 +1,4 @@ -import { find } from 'lodash'; +import find from 'lodash.find'; import composedFetch from '../composedFetch'; export const droppedOffBySender = id => composedFetch(id) diff --git a/src/lib/methods/getStatus.js b/src/lib/methods/getStatus.js index 284b008..c9d3478 100644 --- a/src/lib/methods/getStatus.js +++ b/src/lib/methods/getStatus.js @@ -1,4 +1,4 @@ -import { find } from 'lodash'; +import find from 'lodash.find'; import composedFetch from '../composedFetch'; export default id => composedFetch(id) diff --git a/src/lib/methods/postalPoint.js b/src/lib/methods/postalPoint.js index db874ea..bf37261 100644 --- a/src/lib/methods/postalPoint.js +++ b/src/lib/methods/postalPoint.js @@ -1,4 +1,4 @@ -import { find } from 'lodash'; +import find from 'lodash.find'; import composedFetch from '../composedFetch'; export const sourcePostalPoint = id => { diff --git a/yarn.lock b/yarn.lock index a7420a2..579c8f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2356,6 +2356,10 @@ lodash.defaults@^3.1.2: lodash.assign "^3.0.0" lodash.restparam "^3.0.0" +lodash.find@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1" + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -2384,7 +2388,7 @@ lodash@4.16.6: version "4.16.6" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.16.6.tgz#d22c9ac660288f3843e16ba7d2b5d06cca27d777" -lodash@^4.0.0, lodash@^4.17.2, lodash@^4.2.0, lodash@^4.3.0: +lodash@^4.0.0, lodash@^4.2.0, lodash@^4.3.0: version "4.17.2" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"