Skip to content

Commit

Permalink
Stop using lodash in store.js (#4729)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guyca authored Feb 13, 2019
1 parent a9bbec8 commit 8ba9796
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/src/components/Store.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import * as _ from 'lodash';
import { ComponentProvider } from 'react-native';

export class Store {
private componentsByName: Record<string, ComponentProvider> = {};
private propsById: Record<string, any> = {};

setPropsForId(componentId: string, props: any) {
_.set(this.propsById, componentId, props);
this.propsById[componentId] = props;
}

getPropsForId(componentId: string) {
return _.get(this.propsById, componentId, {});
return this.propsById[componentId] || {};
}

cleanId(componentId: string) {
_.unset(this.propsById, componentId);
delete this.propsById[componentId];
}

setComponentClassForName(componentName: string | number, ComponentClass: ComponentProvider) {
_.set(this.componentsByName, componentName.toString(), ComponentClass);
this.componentsByName[componentName.toString()] = ComponentClass;
}

getComponentClassForName(componentName: string | number): ComponentProvider | undefined {
return _.get(this.componentsByName, componentName.toString());
return this.componentsByName[componentName.toString()];
}
}

0 comments on commit 8ba9796

Please sign in to comment.