Browse Source

Refactor component name to be number also (#4326)

Refactor component name to be number also
Henrik Raitasola 6 years ago
parent
commit
e32d8d2c1a

+ 3
- 2
lib/src/Navigation.ts View File

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

+ 4
- 4
lib/src/components/ComponentRegistry.ts View File

6
 export class ComponentRegistry {
6
 export class ComponentRegistry {
7
   constructor(private readonly store: Store, private readonly componentEventsObserver: ComponentEventsObserver, private readonly ComponentWrapperClass: typeof ComponentWrapper) { }
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
     const NavigationComponent = () => {
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
     return NavigationComponent;
15
     return NavigationComponent;
16
   }
16
   }
17
 }
17
 }

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

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

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

12
     return _.get(this.propsById, componentId, {});
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
   cleanId(id: string) {
24
   cleanId(id: string) {