Skip to content

Commit

Permalink
Refactor component name to be number also (#4326)
Browse files Browse the repository at this point in the history
Refactor component name to be number also
  • Loading branch information
henrikra authored and guyca committed Nov 27, 2018
1 parent 40d1746 commit e32d8d2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lib/src/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export class Navigation {
* Every navigation component in your app must be registered with a unique name.
* The component itself is a traditional React component extending React.Component.
*/
public registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): ComponentProvider {

public registerComponent(componentName: string | number, getComponentClassFunc: ComponentProvider): ComponentProvider {
return this.componentRegistry.registerComponent(componentName, getComponentClassFunc);
}

Expand All @@ -65,7 +66,7 @@ export class Navigation {
* wraps the provided component with a react-redux Provider with the passed redux store
*/
public registerComponentWithRedux(
componentName: string,
componentName: string | number,
getComponentClassFunc: ComponentProvider,
ReduxProvider: any,
reduxStore: any
Expand Down
8 changes: 4 additions & 4 deletions lib/src/components/ComponentRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { ComponentEventsObserver } from '../events/ComponentEventsObserver';
export class ComponentRegistry {
constructor(private readonly store: Store, private readonly componentEventsObserver: ComponentEventsObserver, private readonly ComponentWrapperClass: typeof ComponentWrapper) { }

registerComponent(componentName: string, getComponentClassFunc: ComponentProvider, ReduxProvider?: any, reduxStore?: any): ComponentProvider {
registerComponent(componentName: string | number, getComponentClassFunc: ComponentProvider, ReduxProvider?: any, reduxStore?: any): ComponentProvider {
const NavigationComponent = () => {
return this.ComponentWrapperClass.wrap(componentName, getComponentClassFunc, this.store, this.componentEventsObserver, ReduxProvider, reduxStore)
return this.ComponentWrapperClass.wrap(componentName.toString(), getComponentClassFunc, this.store, this.componentEventsObserver, ReduxProvider, reduxStore)
};
this.store.setComponentClassForName(componentName, NavigationComponent);
AppRegistry.registerComponent(componentName, NavigationComponent);
this.store.setComponentClassForName(componentName.toString(), NavigationComponent);
AppRegistry.registerComponent(componentName.toString(), NavigationComponent);
return NavigationComponent;
}
}
2 changes: 1 addition & 1 deletion lib/src/components/ComponentWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface HocProps { componentId: string; }

export class ComponentWrapper {
static wrap(
componentName: string,
componentName: string | number,
OriginalComponentGenerator: ComponentProvider,
store: Store,
componentEventsObserver: ComponentEventsObserver,
Expand Down
9 changes: 5 additions & 4 deletions lib/src/components/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export class Store {
return _.get(this.propsById, componentId, {});
}

setComponentClassForName(componentName: string, ComponentClass) {
_.set(this.componentsByName, componentName, ComponentClass);

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

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

cleanId(id: string) {
Expand Down

0 comments on commit e32d8d2

Please sign in to comment.