Browse Source

Stop using lodash in store.js (#4729)

Using lodash.set caused issues when keys contained the dot symbol. _.set created objects inside the store, which is intended to be a simple key value dictionary -
In some cases, set would overwrite previously set values.
Guy Carmeli 5 years ago
parent
commit
8ba9796d2d
No account linked to committer's email address
1 changed files with 5 additions and 6 deletions
  1. 5
    6
      lib/src/components/Store.ts

+ 5
- 6
lib/src/components/Store.ts View File

@@ -1,4 +1,3 @@
1
-import * as _ from 'lodash';
2 1
 import { ComponentProvider } from 'react-native';
3 2
 
4 3
 export class Store {
@@ -6,22 +5,22 @@ export class Store {
6 5
   private propsById: Record<string, any> = {};
7 6
 
8 7
   setPropsForId(componentId: string, props: any) {
9
-    _.set(this.propsById, componentId, props);
8
+    this.propsById[componentId] = props;
10 9
   }
11 10
 
12 11
   getPropsForId(componentId: string) {
13
-    return _.get(this.propsById, componentId, {});
12
+    return this.propsById[componentId] || {};
14 13
   }
15 14
 
16 15
   cleanId(componentId: string) {
17
-    _.unset(this.propsById, componentId);
16
+    delete this.propsById[componentId];
18 17
   }
19 18
 
20 19
   setComponentClassForName(componentName: string | number, ComponentClass: ComponentProvider) {
21
-    _.set(this.componentsByName, componentName.toString(), ComponentClass);
20
+    this.componentsByName[componentName.toString()] = ComponentClass;
22 21
   }
23 22
 
24 23
   getComponentClassForName(componentName: string | number): ComponentProvider | undefined {
25
-    return _.get(this.componentsByName, componentName.toString());
24
+    return this.componentsByName[componentName.toString()];
26 25
   }
27 26
 }