Browse Source

Use lodash submodules to reduce bundle size (#5734)

Import lodash sub modules
Pontus Abrahamsson 4 years ago
parent
commit
e53a9feb20

+ 2
- 2
e2e/ApplicationLifecycleTest.test.js View File

@@ -1,10 +1,10 @@
1 1
 const Utils = require('./Utils');
2 2
 const Android = require('./AndroidUtils');
3 3
 const TestIDs = require('../playground/src/testIDs');
4
-const _ = require('lodash');
4
+const includes = require('lodash/includes');
5 5
 
6 6
 const { elementByLabel, elementById, sleep } = Utils;
7
-const IS_RELEASE = _.includes(process.argv, '--release');
7
+const IS_RELEASE = includes(process.argv, '--release');
8 8
 const KEY_CODE_R = 46;
9 9
 
10 10
 describe('application lifecycle test', () => {

+ 8
- 7
integration/env.test.js View File

@@ -1,4 +1,5 @@
1
-const _ = require('lodash');
1
+const eq = require('lodash/eq');
2
+const isEqual = require('lodash/isEqual');
2 3
 
3 4
 describe('testing that the environment is working properly', () => {
4 5
   it('object spread', () => {
@@ -14,16 +15,16 @@ describe('testing that the environment is working properly', () => {
14 15
   });
15 16
 
16 17
   it('equality tests', () => {
17
-    expect(_.eq('hello', 'hello')).toBe(true);
18
-    expect(_.isEqual('hello', 'hello')).toBe(true);
18
+    expect(eq('hello', 'hello')).toBe(true);
19
+    expect(isEqual('hello', 'hello')).toBe(true);
19 20
 
20
-    expect(_.eq('hello', Object('hello'))).toBe(false);
21
-    expect(_.isEqual('hello', Object('hello'))).toBe(true);
21
+    expect(eq('hello', Object('hello'))).toBe(false);
22
+    expect(isEqual('hello', Object('hello'))).toBe(true);
22 23
 
23 24
     const a = {};
24 25
     const b = {};
25 26
 
26
-    expect(_.eq(a, b)).toBe(false);
27
-    expect(_.isEqual(a, b)).toBe(true);
27
+    expect(eq(a, b)).toBe(false);
28
+    expect(isEqual(a, b)).toBe(true);
28 29
   });
29 30
 });

+ 5
- 4
integration/redux/MyStore.js View File

@@ -1,5 +1,6 @@
1 1
 const redux = require('redux');
2
-const _ = require('lodash');
2
+const merge = require('lodash/merge');
3
+const get = require('lodash/get');
3 4
 
4 5
 const initialState = {
5 6
   person: {
@@ -10,10 +11,10 @@ const initialState = {
10 11
 const reducer = (state = initialState, action) => {
11 12
   switch (action.type) {
12 13
     case 'redux.MyStore.setName': {
13
-      return _.merge({}, state, { person: { name: action.name } });
14
+      return merge({}, state, { person: { name: action.name } });
14 15
     }
15 16
     case 'redux.MyStore.setAge': {
16
-      return _.merge({}, state, { person: { age: action.age } });
17
+      return merge({}, state, { person: { age: action.age } });
17 18
     }
18 19
     default: {
19 20
       return state;
@@ -23,7 +24,7 @@ const reducer = (state = initialState, action) => {
23 24
 
24 25
 const selectors = {
25 26
   getName(state) {
26
-    return _.get(state, 'person.name');
27
+    return get(state, 'person.name');
27 28
   },
28 29
 
29 30
   getAge(state) {

+ 1
- 1
lib/src/Navigation.ts View File

@@ -1,4 +1,4 @@
1
-import { isArray } from 'lodash';
1
+import isArray from 'lodash/isArray';
2 2
 import { NativeCommandsSender } from './adapters/NativeCommandsSender';
3 3
 import { NativeEventsReceiver } from './adapters/NativeEventsReceiver';
4 4
 import { UniqueIdProvider } from './adapters/UniqueIdProvider';

+ 2
- 2
lib/src/adapters/UniqueIdProvider.ts View File

@@ -1,7 +1,7 @@
1
-import * as _ from 'lodash';
1
+import uniqueId from 'lodash/uniqueId';
2 2
 
3 3
 export class UniqueIdProvider {
4 4
   generate(prefix?: string): string {
5
-    return _.uniqueId(prefix);
5
+    return uniqueId(prefix);
6 6
   }
7 7
 }

+ 6
- 4
lib/src/commands/Commands.test.ts View File

@@ -1,4 +1,6 @@
1
-import * as _ from 'lodash';
1
+import forEach from 'lodash/forEach'
2
+import filter from 'lodash/filter'
3
+import invoke from 'lodash/invoke'
2 4
 import { mock, verify, instance, deepEqual, when, anything, anyString } from 'ts-mockito';
3 5
 
4 6
 import { LayoutTreeParser } from './LayoutTreeParser';
@@ -398,7 +400,7 @@ describe('Commands', () => {
398 400
 
399 401
     function getAllMethodsOfUut() {
400 402
       const uutFns = Object.getOwnPropertyNames(Commands.prototype);
401
-      const methods = _.filter(uutFns, (fn) => fn !== 'constructor');
403
+      const methods = filter(uutFns, (fn) => fn !== 'constructor');
402 404
       expect(methods.length).toBeGreaterThan(1);
403 405
       return methods;
404 406
     }
@@ -445,11 +447,11 @@ describe('Commands', () => {
445 447
         dismissOverlay: { commandId: 'dismissOverlay+UNIQUE_ID', componentId: 'id' },
446 448
         getLaunchArgs: { commandId: 'getLaunchArgs+UNIQUE_ID' }
447 449
       };
448
-      _.forEach(getAllMethodsOfUut(), (m) => {
450
+      forEach(getAllMethodsOfUut(), (m) => {
449 451
         it(`for ${m}`, () => {
450 452
           expect(argsForMethodName).toHaveProperty(m);
451 453
           expect(paramsForMethodName).toHaveProperty(m);
452
-          _.invoke(uut, m, ...argsForMethodName[m]);
454
+          invoke(uut, m, ...argsForMethodName[m]);
453 455
           expect(cb).toHaveBeenCalledTimes(1);
454 456
           expect(cb).toHaveBeenCalledWith(m, paramsForMethodName[m]);
455 457
         });

+ 12
- 11
lib/src/commands/Commands.ts View File

@@ -1,4 +1,5 @@
1
-import * as _ from 'lodash';
1
+import cloneDeep from 'lodash/cloneDeep'
2
+import map from 'lodash/map'
2 3
 import { CommandsObserver } from '../events/CommandsObserver';
3 4
 import { NativeCommandsSender } from '../adapters/NativeCommandsSender';
4 5
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
@@ -21,14 +22,14 @@ export class Commands {
21 22
   ) {}
22 23
 
23 24
   public setRoot(simpleApi: LayoutRoot) {
24
-    const input = _.cloneDeep(simpleApi);
25
+    const input = cloneDeep(simpleApi);
25 26
     const root = this.layoutTreeParser.parse(input.root);
26 27
 
27
-    const modals = _.map(input.modals, (modal) => {
28
+    const modals = map(input.modals, (modal) => {
28 29
       return this.layoutTreeParser.parse(modal);
29 30
     });
30 31
 
31
-    const overlays = _.map(input.overlays, (overlay) => {
32
+    const overlays = map(input.overlays, (overlay) => {
32 33
       return this.layoutTreeParser.parse(overlay);
33 34
     });
34 35
 
@@ -48,7 +49,7 @@ export class Commands {
48 49
   }
49 50
 
50 51
   public setDefaultOptions(options: Options) {
51
-    const input = _.cloneDeep(options);
52
+    const input = cloneDeep(options);
52 53
     this.optionsProcessor.processOptions(input);
53 54
 
54 55
     this.nativeCommandsSender.setDefaultOptions(input);
@@ -56,7 +57,7 @@ export class Commands {
56 57
   }
57 58
 
58 59
   public mergeOptions(componentId: string, options: Options) {
59
-    const input = _.cloneDeep(options);
60
+    const input = cloneDeep(options);
60 61
     this.optionsProcessor.processOptions(input);
61 62
 
62 63
     this.nativeCommandsSender.mergeOptions(componentId, input);
@@ -64,13 +65,13 @@ export class Commands {
64 65
   }
65 66
 
66 67
   public updateProps(componentId: string, props: object) {
67
-    const input = _.cloneDeep(props);
68
+    const input = cloneDeep(props);
68 69
     this.store.updateProps(componentId, input);
69 70
     this.commandsObserver.notify('updateProps', { componentId, props });
70 71
   }
71 72
 
72 73
   public showModal(layout: Layout) {
73
-    const layoutCloned = _.cloneDeep(layout);
74
+    const layoutCloned = cloneDeep(layout);
74 75
     const layoutNode = this.layoutTreeParser.parse(layoutCloned);
75 76
 
76 77
     const commandId = this.uniqueIdProvider.generate('showModal');
@@ -96,7 +97,7 @@ export class Commands {
96 97
   }
97 98
 
98 99
   public push(componentId: string, simpleApi: Layout) {
99
-    const input = _.cloneDeep(simpleApi);
100
+    const input = cloneDeep(simpleApi);
100 101
     const layout = this.layoutTreeParser.parse(input);
101 102
 
102 103
     const commandId = this.uniqueIdProvider.generate('push');
@@ -129,7 +130,7 @@ export class Commands {
129 130
   }
130 131
 
131 132
   public setStackRoot(componentId: string, children: Layout[]) {
132
-    const input = _.map(_.cloneDeep(children), (simpleApi) => {
133
+    const input = map(cloneDeep(children), (simpleApi) => {
133 134
       const layout = this.layoutTreeParser.parse(simpleApi);
134 135
       return layout;
135 136
     });
@@ -145,7 +146,7 @@ export class Commands {
145 146
   }
146 147
 
147 148
   public showOverlay(simpleApi: Layout) {
148
-    const input = _.cloneDeep(simpleApi);
149
+    const input = cloneDeep(simpleApi);
149 150
     const layout = this.layoutTreeParser.parse(input);
150 151
 
151 152
     const commandId = this.uniqueIdProvider.generate('showOverlay');

+ 4
- 3
lib/src/commands/LayoutTreeCrawler.ts View File

@@ -1,4 +1,5 @@
1
-import * as _ from 'lodash';
1
+import merge from 'lodash/merge'
2
+import isFunction from 'lodash/isFunction'
2 3
 import { LayoutType } from './LayoutType';
3 4
 import { OptionsProcessor } from './OptionsProcessor';
4 5
 import { Store } from '../components/Store';
@@ -47,14 +48,14 @@ export class LayoutTreeCrawler {
47 48
   }
48 49
 
49 50
   private applyStaticOptions(node: LayoutNode) {
50
-    node.data.options = _.merge({}, this.staticOptionsIfPossible(node), node.data.options);
51
+    node.data.options = merge({}, this.staticOptionsIfPossible(node), node.data.options);
51 52
   }
52 53
 
53 54
   private staticOptionsIfPossible(node: LayoutNode) {
54 55
     const foundReactGenerator = this.store.getComponentClassForName(node.data.name!);
55 56
     const reactComponent = foundReactGenerator ? foundReactGenerator() : undefined;
56 57
     if (reactComponent && this.isComponentWithOptions(reactComponent)) {
57
-      return _.isFunction(reactComponent.options) ? reactComponent.options(node.data.passProps || {}) : reactComponent.options;
58
+      return isFunction(reactComponent.options) ? reactComponent.options(node.data.passProps || {}) : reactComponent.options;
58 59
     }
59 60
     return {};
60 61
   }

+ 4
- 4
lib/src/commands/LayoutTreeParser.test.ts View File

@@ -1,4 +1,4 @@
1
-import * as _ from 'lodash';
1
+import keys from 'lodash/keys';
2 2
 import { LayoutTreeParser } from './LayoutTreeParser';
3 3
 import { LayoutType } from './LayoutType';
4 4
 import { Options } from '../interfaces/Options';
@@ -89,7 +89,7 @@ describe('LayoutTreeParser', () => {
89 89
 
90 90
     it('bottom tabs', () => {
91 91
       const result = uut.parse(LayoutExamples.bottomTabs);
92
-      expect(_.keys(result)).toEqual(['id', 'type', 'data', 'children']);
92
+      expect(keys(result)).toEqual(['id', 'type', 'data', 'children']);
93 93
       expect(result.id).toEqual('myUniqueId');
94 94
       expect(result.type).toEqual(LayoutType.BottomTabs);
95 95
       expect(result.data).toEqual({});
@@ -101,7 +101,7 @@ describe('LayoutTreeParser', () => {
101 101
 
102 102
     it('side menus', () => {
103 103
       const result = uut.parse(LayoutExamples.sideMenu);
104
-      expect(_.keys(result)).toEqual(['id', 'type', 'data', 'children']);
104
+      expect(keys(result)).toEqual(['id', 'type', 'data', 'children']);
105 105
       expect(result.id).toEqual('myUniqueId');
106 106
       expect(result.type).toEqual(LayoutType.SideMenuRoot);
107 107
       expect(result.data).toEqual({});
@@ -119,7 +119,7 @@ describe('LayoutTreeParser', () => {
119 119
 
120 120
     it('top tabs', () => {
121 121
       const result = uut.parse(LayoutExamples.topTabs);
122
-      expect(_.keys(result)).toEqual(['id', 'type', 'data', 'children']);
122
+      expect(keys(result)).toEqual(['id', 'type', 'data', 'children']);
123 123
       expect(result.id).toEqual('myUniqueId');
124 124
       expect(result.type).toEqual(LayoutType.TopTabs);
125 125
       expect(result.data).toEqual({ options: LayoutExamples.options });

+ 15
- 11
lib/src/commands/OptionsProcessor.ts View File

@@ -1,4 +1,8 @@
1
-import * as _ from 'lodash';
1
+import isEqual from 'lodash/isEqual'
2
+import isObject from 'lodash/isObject'
3
+import isArray from 'lodash/isArray'
4
+import endsWith from 'lodash/endsWith'
5
+import forEach from 'lodash/forEach'
2 6
 
3 7
 import { Store } from '../components/Store';
4 8
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
@@ -19,7 +23,7 @@ export class OptionsProcessor {
19 23
   }
20 24
 
21 25
   private processObject(objectToProcess: object) {
22
-    _.forEach(objectToProcess, (value, key) => {
26
+    forEach(objectToProcess, (value, key) => {
23 27
       this.processColor(key, value, objectToProcess);
24 28
 
25 29
       if (!value) {
@@ -30,32 +34,32 @@ export class OptionsProcessor {
30 34
       this.processImage(key, value, objectToProcess);
31 35
       this.processButtonsPassProps(key, value);
32 36
 
33
-      if (!_.isEqual(key, 'passProps') && (_.isObject(value) || _.isArray(value))) {
37
+      if (!isEqual(key, 'passProps') && (isObject(value) || isArray(value))) {
34 38
         this.processObject(value);
35 39
       }
36 40
     });
37 41
   }
38 42
 
39 43
   private processColor(key: string, value: any, options: Record<string, any>) {
40
-    if (_.isEqual(key, 'color') || _.endsWith(key, 'Color')) {
44
+    if (isEqual(key, 'color') || endsWith(key, 'Color')) {
41 45
       options[key] = value === null ? 'NoColor' : this.colorService.toNativeColor(value);
42 46
     }
43 47
   }
44 48
 
45 49
   private processImage(key: string, value: any, options: Record<string, any>) {
46 50
     if (
47
-      _.isEqual(key, 'icon') ||
48
-      _.isEqual(key, 'image') ||
49
-      _.endsWith(key, 'Icon') ||
50
-      _.endsWith(key, 'Image')
51
+      isEqual(key, 'icon') ||
52
+      isEqual(key, 'image') ||
53
+      endsWith(key, 'Icon') ||
54
+      endsWith(key, 'Image')
51 55
     ) {
52 56
       options[key] = this.assetService.resolveFromRequire(value);
53 57
     }
54 58
   }
55 59
 
56 60
   private processButtonsPassProps(key: string, value: any) {
57
-    if (_.endsWith(key, 'Buttons')) {
58
-      _.forEach(value, (button) => {
61
+    if (endsWith(key, 'Buttons')) {
62
+      forEach(value, (button) => {
59 63
         if (button.passProps && button.id) {
60 64
           this.store.updateProps(button.id, button.passProps);
61 65
           button.passProps = undefined;
@@ -65,7 +69,7 @@ export class OptionsProcessor {
65 69
   }
66 70
 
67 71
   private processComponent(key: string, value: any, options: Record<string, any>) {
68
-    if (_.isEqual(key, 'component')) {
72
+    if (isEqual(key, 'component')) {
69 73
       value.componentId = value.id ? value.id : this.uniqueIdProvider.generate('CustomComponent');
70 74
       if (value.passProps) {
71 75
         this.store.updateProps(value.componentId, value.passProps);

+ 3
- 3
lib/src/components/ComponentWrapper.tsx View File

@@ -1,6 +1,6 @@
1 1
 import * as React from 'react';
2 2
 import { ComponentProvider } from 'react-native';
3
-import * as  _ from 'lodash';
3
+import merge from 'lodash/merge'
4 4
 import { polyfill } from 'react-lifecycles-compat';
5 5
 import hoistNonReactStatics = require('hoist-non-react-statics');
6 6
 
@@ -28,7 +28,7 @@ export class ComponentWrapper {
28 28
     class WrappedComponent extends React.Component<HocProps, HocState> {
29 29
       static getDerivedStateFromProps(nextProps: any, prevState: HocState) {
30 30
         return {
31
-          allProps: _.merge({}, nextProps, store.getPropsForId(prevState.componentId))
31
+          allProps: merge({}, nextProps, store.getPropsForId(prevState.componentId))
32 32
         };
33 33
       }
34 34
 
@@ -43,7 +43,7 @@ export class ComponentWrapper {
43 43
       }
44 44
 
45 45
       public setProps(newProps: any) {
46
-        this.setState({allProps: newProps});
46
+        this.setState({ allProps: newProps });
47 47
       }
48 48
 
49 49
       componentWillUnmount() {

+ 11
- 7
lib/src/events/ComponentEventsObserver.ts View File

@@ -1,4 +1,8 @@
1
-import * as _ from 'lodash';
1
+import isString from 'lodash/isString'
2
+import isNil from 'lodash/isNil'
3
+import uniqueId from 'lodash/uniqueId'
4
+import unset from 'lodash/unset'
5
+import forEach from 'lodash/forEach'
2 6
 import { EventSubscription } from '../interfaces/EventSubscription';
3 7
 import {
4 8
   ComponentDidAppearEvent,
@@ -47,20 +51,20 @@ export class ComponentEventsObserver {
47 51
   public bindComponent(component: React.Component<any>, componentId?: string): EventSubscription {
48 52
     const computedComponentId = componentId || component.props.componentId;
49 53
 
50
-    if (!_.isString(computedComponentId)) {
54
+    if (!isString(computedComponentId)) {
51 55
       throw new Error(`bindComponent expects a component with a componentId in props or a componentId as the second argument`);
52 56
     }
53
-    if (_.isNil(this.listeners[computedComponentId])) {
57
+    if (isNil(this.listeners[computedComponentId])) {
54 58
       this.listeners[computedComponentId] = {};
55 59
     }
56
-    const key = _.uniqueId();
60
+    const key = uniqueId();
57 61
     this.listeners[computedComponentId][key] = component;
58 62
 
59
-    return { remove: () => _.unset(this.listeners[computedComponentId], key) };
63
+    return { remove: () => unset(this.listeners[computedComponentId], key) };
60 64
   }
61 65
 
62 66
   public unmounted(componentId: string) {
63
-    _.unset(this.listeners, componentId);
67
+    unset(this.listeners, componentId);
64 68
   }
65 69
 
66 70
   notifyComponentDidAppear(event: ComponentDidAppearEvent) {
@@ -93,7 +97,7 @@ export class ComponentEventsObserver {
93 97
   }
94 98
 
95 99
   private triggerOnAllListenersByComponentId(event: ComponentEvent, method: string) {
96
-    _.forEach(this.listeners[event.componentId], (component) => {
100
+    forEach(this.listeners[event.componentId], (component) => {
97 101
       if (component && component[method]) {
98 102
         component[method](event);
99 103
       }

+ 8
- 7
package.json View File

@@ -58,27 +58,28 @@
58 58
   },
59 59
   "devDependencies": {
60 60
     "@babel/core": "7.6.4",
61
-    "@babel/types": "7.6.x",
62 61
     "@babel/plugin-proposal-export-default-from": "7.2.0",
63 62
     "@babel/plugin-proposal-export-namespace-from": "7.2.0",
64
-    "@types/hoist-non-react-statics": "^3.0.1",
63
+    "@babel/types": "7.6.x",
65 64
     "@react-native-community/eslint-config": "0.0.3",
66
-    "babel-jest": "24.9.x",
65
+    "@types/hoist-non-react-statics": "^3.0.1",
67 66
     "@types/jest": "24.x.x",
68
-    "@types/lodash": "4.x.x",
67
+    "@types/lodash": "^4.14.149",
69 68
     "@types/react": "16.x.x",
70 69
     "@types/react-native": "0.57.7",
71 70
     "@types/react-test-renderer": "16.x.x",
71
+    "babel-jest": "24.9.x",
72 72
     "detox": "14.x.x",
73
-    "react-native-ui-lib": "3.24.2",
74 73
     "handlebars": "4.x.x",
75 74
     "jest": "24.9.x",
75
+    "lodash": "^4.17.15",
76 76
     "metro-react-native-babel-preset": "0.57.x",
77 77
     "react": "16.9.0",
78 78
     "react-native": "0.61.4",
79
+    "react-native-keyboard-tracking-view": "5.x.x",
79 80
     "react-native-typescript-transformer": "1.2.12",
81
+    "react-native-ui-lib": "3.24.2",
80 82
     "react-native-view-overflow": "0.0.4",
81
-    "react-native-keyboard-tracking-view": "5.x.x",
82 83
     "react-redux": "5.x.x",
83 84
     "react-test-renderer": "16.9.x",
84 85
     "redux": "3.x.x",
@@ -160,4 +161,4 @@
160 161
       }
161 162
     }
162 163
   }
163
-}
164
+}

+ 2
- 1
playground/src/commons/Layouts.js View File

@@ -1,4 +1,5 @@
1
-const { isString, isArray } = require('lodash');
1
+const isString = require('lodash/isString');
2
+const isArray = require('lodash/isArray');
2 3
 
3 4
 const stack = (rawChildren, id) => {
4 5
   const childrenArray = isArray(rawChildren) ? rawChildren : [rawChildren];

+ 4
- 3
playground/src/screens/FullScreenModalScreen.js View File

@@ -1,4 +1,5 @@
1
-const _ = require('lodash');
1
+const concat = require('lodash/concat');
2
+const last = require('lodash/last');
2 3
 const React = require('react');
3 4
 const Root = require('../components/Root');
4 5
 const Button = require('../components/Button')
@@ -42,7 +43,7 @@ class FullScreenModalScreen extends React.Component {
42 43
         name: Screens.Modal,
43 44
         passProps: {
44 45
           modalPosition: this.getModalPosition() + 1,
45
-          previousModalIds: _.concat([], this.props.previousModalIds || [], this.props.componentId)
46
+          previousModalIds: concat([], this.props.previousModalIds || [], this.props.componentId)
46 47
         }
47 48
       }
48 49
     });
@@ -65,6 +66,6 @@ class FullScreenModalScreen extends React.Component {
65 66
 
66 67
   getModalPosition = () => this.props.modalPosition || 1;
67 68
 
68
-  getPreviousModalId = () => _.last(this.props.previousModalIds);
69
+  getPreviousModalId = () => last(this.props.previousModalIds);
69 70
 }
70 71
 module.exports = FullScreenModalScreen;

+ 8
- 5
playground/src/screens/ModalScreen.js View File

@@ -1,4 +1,7 @@
1
-const _ = require('lodash');
1
+const last = require('lodash/last');
2
+const concat = require('lodash/concat');
3
+const forEach = require('lodash/forEach');
4
+const head = require('lodash/head');
2 5
 const React = require('react');
3 6
 const Root = require('../components/Root');
4 7
 const Button = require('../components/Button')
@@ -54,7 +57,7 @@ class ModalScreen extends React.Component {
54 57
         name: Screens.Modal,
55 58
         passProps: {
56 59
           modalPosition: this.getModalPosition() + 1,
57
-          previousModalIds: _.concat([], this.props.previousModalIds || [], this.props.componentId)
60
+          previousModalIds: concat([], this.props.previousModalIds || [], this.props.componentId)
58 61
         }
59 62
       }
60 63
     });
@@ -66,9 +69,9 @@ class ModalScreen extends React.Component {
66 69
 
67 70
   dismissUnknownModal = () => Navigation.dismissModal('unknown');
68 71
 
69
-  dismissAllPreviousModals = () => _.forEach(this.props.previousModalIds, (id) => Navigation.dismissModal(id));
72
+  dismissAllPreviousModals = () => forEach(this.props.previousModalIds, (id) => Navigation.dismissModal(id));
70 73
 
71
-  dismissFirstModal = () => Navigation.dismissModal(_.head(this.props.previousModalIds));
74
+  dismissFirstModal = () => Navigation.dismissModal(head(this.props.previousModalIds));
72 75
 
73 76
   dismissAllModals = () => Navigation.dismissAllModals();
74 77
 
@@ -85,6 +88,6 @@ class ModalScreen extends React.Component {
85 88
 
86 89
   getModalPosition = () => this.props.modalPosition || 1;
87 90
 
88
-  getPreviousModalId = () => _.last(this.props.previousModalIds);
91
+  getPreviousModalId = () => last(this.props.previousModalIds);
89 92
 }
90 93
 module.exports = ModalScreen;

+ 4
- 4
playground/src/screens/PushedScreen.js View File

@@ -1,4 +1,4 @@
1
-const _ = require('lodash');
1
+const concat = require('lodash/concat');
2 2
 const React = require('react');
3 3
 const { BackHandler } = require('react-native');
4 4
 const Navigation = require('../services/Navigation');
@@ -99,7 +99,7 @@ class PushedScreen extends React.Component {
99 99
         name: Screens.Pushed,
100 100
         passProps: {
101 101
           stackPosition: this.getStackPosition() + 1,
102
-          previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.componentId)
102
+          previousScreenIds: concat([], this.props.previousScreenIds || [], this.props.componentId)
103 103
         },
104 104
         options: {
105 105
           animations: {
@@ -120,7 +120,7 @@ class PushedScreen extends React.Component {
120 120
         name: Screens.Pushed,
121 121
         passProps: {
122 122
           stackPosition: this.getStackPosition() + 1,
123
-          previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.componentId)
123
+          previousScreenIds: concat([], this.props.previousScreenIds || [], this.props.componentId)
124 124
         },
125 125
         options: {
126 126
           animations: {
@@ -152,7 +152,7 @@ class PushedScreen extends React.Component {
152 152
   createPassProps = () => {
153 153
     return {
154 154
       stackPosition: this.getStackPosition() + 1,
155
-      previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.componentId)
155
+      previousScreenIds: concat([], this.props.previousScreenIds || [], this.props.componentId)
156 156
     }
157 157
   };
158 158
   getStackPosition = () => this.props.stackPosition || 1;

+ 3
- 1
playground/src/services/Navigation.js View File

@@ -1,4 +1,6 @@
1
-const { isString, get } = require('lodash');
1
+const get = require('lodash/get');
2
+const isString= require('lodash/isString');
3
+
2 4
 const { stack, component } = require('../commons/Layouts');
3 5
 const { Navigation } = require('react-native-navigation');
4 6
 

+ 2
- 2
scripts/gen-docs/MarkdownWriter.ts View File

@@ -1,4 +1,4 @@
1
-import * as _ from 'lodash';
1
+import concat from 'lodash/concat'
2 2
 import * as Handlebars from 'handlebars';
3 3
 import * as fs from 'fs';
4 4
 import { ClassContext } from './ClassParser';
@@ -34,7 +34,7 @@ export class MarkdownWriter {
34 34
     const files2 = interfaceContexts.map(mapper);
35 35
     const files3 = enumContexts.map(mapper);
36 36
 
37
-    const menuMarkdown = this.menuFn({ files: _.concat(files, files2, files3) });
37
+    const menuMarkdown = this.menuFn({ files: concat(files, files2, files3) });
38 38
     fs.writeFileSync(`${this.outputDir}/_sidebar.md`, menuMarkdown, { encoding: 'utf8' });
39 39
     fs.writeFileSync(`${this.outputDir}/README.md`, menuMarkdown, { encoding: 'utf8' });
40 40
   }

+ 2
- 2
scripts/install-android.js View File

@@ -1,7 +1,7 @@
1
-const _ = require('lodash');
1
+const includes = require('lodash/includes')
2 2
 const exec = require('shell-utils').exec;
3 3
 
4
-const release = _.includes(process.argv, '--release');
4
+const release = includes(process.argv, '--release');
5 5
 
6 6
 run();
7 7
 

+ 2
- 2
scripts/release.js View File

@@ -2,7 +2,7 @@
2 2
 const exec = require('shell-utils').exec;
3 3
 const semver = require('semver');
4 4
 const fs = require('fs');
5
-const _ = require('lodash');
5
+const includes = require('lodash/includes');
6 6
 const path = require('path');
7 7
 
8 8
 // Workaround JS
@@ -82,7 +82,7 @@ function tryPublishAndTag(version) {
82 82
             console.log(`Released ${theCandidate}`);
83 83
             return;
84 84
         } catch (err) {
85
-            const alreadyPublished = _.includes(err.toString(), 'You cannot publish over the previously published version');
85
+            const alreadyPublished = includes(err.toString(), 'You cannot publish over the previously published version');
86 86
             if (!alreadyPublished) {
87 87
                 throw err;
88 88
             }

+ 7
- 7
scripts/test-e2e.js View File

@@ -1,12 +1,12 @@
1
-const _ = require('lodash');
1
+const includes = require('lodash/includes');
2 2
 const exec = require('shell-utils').exec;
3 3
 
4
-const android = _.includes(process.argv, '--android');
5
-const release = _.includes(process.argv, '--release');
6
-const skipBuild = _.includes(process.argv, '--skipBuild');
7
-const headless = _.includes(process.argv, '--headless');
8
-const multi = _.includes(process.argv, '--multi');
9
-const verbose = _.includes(process.argv, '--verbose');
4
+const android = includes(process.argv, '--android');
5
+const release = includes(process.argv, '--release');
6
+const skipBuild = includes(process.argv, '--skipBuild');
7
+const headless = includes(process.argv, '--headless');
8
+const multi = includes(process.argv, '--multi');
9
+const verbose = includes(process.argv, '--verbose');
10 10
 
11 11
 run();
12 12
 

+ 5
- 5
scripts/test-js.js View File

@@ -1,7 +1,7 @@
1 1
 const exec = require('shell-utils').exec;
2
-const _ = require('lodash');
2
+const { includes, chain, split, filter } = require('lodash');
3 3
 
4
-const fix = _.includes(process.argv, '--fix') ? '--fix' : '';
4
+const fix = includes(process.argv, '--fix') ? '--fix' : '';
5 5
 
6 6
 const dirs = [
7 7
   'lib/src',
@@ -14,7 +14,7 @@ const dirs = [
14 14
 run();
15 15
 
16 16
 function run() {
17
-  const paths = _.chain(dirs).map((d) => d === 'e2e' ? `${d}/**/*.[tj]s` : `${d}/**/*.[tj]sx?`).join(' ').value();
17
+  const paths = chain(dirs).map((d) => d === 'e2e' ? `${d}/**/*.[tj]s` : `${d}/**/*.[tj]sx?`).join(' ').value();
18 18
   exec.execSync(`tslint ${paths} ${fix} --format verbose`);
19 19
   assertAllTsFilesInSrc();
20 20
   exec.execSync(`jest --coverage`);
@@ -22,8 +22,8 @@ function run() {
22 22
 
23 23
 function assertAllTsFilesInSrc() {
24 24
   const allFiles = exec.execSyncRead('find ./lib/src -type f');
25
-  const lines = _.split(allFiles, '\n');
26
-  const offenders = _.filter(lines, (f) => !f.endsWith('.ts') && !f.endsWith('.tsx'));
25
+  const lines = split(allFiles, '\n');
26
+  const offenders = filter(lines, (f) => !f.endsWith('.ts') && !f.endsWith('.tsx'));
27 27
   if (offenders.length) {
28 28
     throw new Error(`\n\nOnly ts/tsx files are allowed:\n${offenders.join('\n')}\n\n\n`);
29 29
   }

+ 3
- 3
scripts/test-unit.js View File

@@ -1,8 +1,8 @@
1
-const _ = require('lodash');
1
+const includes = require('lodash/includes');
2 2
 const exec = require('shell-utils').exec;
3 3
 
4
-const android = _.includes(process.argv, '--android');
5
-const release = _.includes(process.argv, '--release');
4
+const android = includes(process.argv, '--android');
5
+const release = includes(process.argv, '--release');
6 6
 
7 7
 function run() {
8 8
   if (android) {

+ 1
- 1
tsconfig-strict.json View File

@@ -1,7 +1,7 @@
1 1
 {
2 2
   "$schema": "http://json.schemastore.org/tsconfig",
3 3
   "compilerOptions": {
4
-    "allowSyntheticDefaultImports": false,
4
+    "allowSyntheticDefaultImports": true,
5 5
     "allowUnreachableCode": false,
6 6
     "allowUnusedLabels": false,
7 7
     "diagnostics": true,

+ 1
- 0
tsconfig.json View File

@@ -7,6 +7,7 @@
7 7
     "module": "commonjs",
8 8
     "jsx": "react-native",
9 9
     "declaration": true,
10
+    "esModuleInterop": true,
10 11
     "skipLibCheck": true,
11 12
     "types": [
12 13
       "jest",