Bladeren bron

Refactor component name to be number also (#4326)

Refactor component name to be number also
Henrik Raitasola 6 jaren geleden
bovenliggende
commit
e32d8d2c1a

+ 3
- 2
lib/src/Navigation.ts Bestand weergeven

@@ -56,7 +56,8 @@ export class Navigation {
56 56
    * Every navigation component in your app must be registered with a unique name.
57 57
    * The component itself is a traditional React component extending React.Component.
58 58
    */
59
-  public registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): ComponentProvider {
59
+
60
+  public registerComponent(componentName: string | number, getComponentClassFunc: ComponentProvider): ComponentProvider {
60 61
     return this.componentRegistry.registerComponent(componentName, getComponentClassFunc);
61 62
   }
62 63
 
@@ -65,7 +66,7 @@ export class Navigation {
65 66
    * wraps the provided component with a react-redux Provider with the passed redux store
66 67
    */
67 68
   public registerComponentWithRedux(
68
-    componentName: string,
69
+    componentName: string | number,
69 70
     getComponentClassFunc: ComponentProvider,
70 71
     ReduxProvider: any,
71 72
     reduxStore: any

+ 4
- 4
lib/src/components/ComponentRegistry.ts Bestand weergeven

@@ -6,12 +6,12 @@ import { ComponentEventsObserver } from '../events/ComponentEventsObserver';
6 6
 export class ComponentRegistry {
7 7
   constructor(private readonly store: Store, private readonly componentEventsObserver: ComponentEventsObserver, private readonly ComponentWrapperClass: typeof ComponentWrapper) { }
8 8
 
9
-  registerComponent(componentName: string, getComponentClassFunc: ComponentProvider, ReduxProvider?: any, reduxStore?: any): ComponentProvider {
9
+  registerComponent(componentName: string | number, getComponentClassFunc: ComponentProvider, ReduxProvider?: any, reduxStore?: any): ComponentProvider {
10 10
     const NavigationComponent = () => {
11
-      return this.ComponentWrapperClass.wrap(componentName, getComponentClassFunc, this.store, this.componentEventsObserver, ReduxProvider, reduxStore)
11
+      return this.ComponentWrapperClass.wrap(componentName.toString(), getComponentClassFunc, this.store, this.componentEventsObserver, ReduxProvider, reduxStore)
12 12
     };
13
-    this.store.setComponentClassForName(componentName, NavigationComponent);
14
-    AppRegistry.registerComponent(componentName, NavigationComponent);
13
+    this.store.setComponentClassForName(componentName.toString(), NavigationComponent);
14
+    AppRegistry.registerComponent(componentName.toString(), NavigationComponent);
15 15
     return NavigationComponent;
16 16
   }
17 17
 }

+ 1
- 1
lib/src/components/ComponentWrapper.tsx Bestand weergeven

@@ -10,7 +10,7 @@ interface HocProps { componentId: string; }
10 10
 
11 11
 export class ComponentWrapper {
12 12
   static wrap(
13
-    componentName: string,
13
+    componentName: string | number,
14 14
     OriginalComponentGenerator: ComponentProvider,
15 15
     store: Store,
16 16
     componentEventsObserver: ComponentEventsObserver,

+ 5
- 4
lib/src/components/Store.ts Bestand weergeven

@@ -12,12 +12,13 @@ export class Store {
12 12
     return _.get(this.propsById, componentId, {});
13 13
   }
14 14
 
15
-  setComponentClassForName(componentName: string, ComponentClass) {
16
-    _.set(this.componentsByName, componentName, ComponentClass);
15
+
16
+  setComponentClassForName(componentName: string | number, ComponentClass) {
17
+    _.set(this.componentsByName, componentName.toString(), ComponentClass);
17 18
   }
18 19
 
19
-  getComponentClassForName(componentName: string) {
20
-    return _.get(this.componentsByName, componentName);
20
+  getComponentClassForName(componentName: string | number) {
21
+    return _.get(this.componentsByName, componentName.toString());
21 22
   }
22 23
   
23 24
   cleanId(id: string) {