Quellcode durchsuchen

changed API, better naming

Daniel Zlotin vor 7 Jahren
Ursprung
Commit
7b51a48936

+ 4
- 4
lib/src/adapters/NativeEventsReceiver.ts Datei anzeigen

10
     this.emitter = new NativeEventEmitter(NativeModules.RNNEventEmitter);
10
     this.emitter = new NativeEventEmitter(NativeModules.RNNEventEmitter);
11
   }
11
   }
12
 
12
 
13
-  registerAppLaunched(callback: () => void): EventSubscription {
14
-    return this.emitter.addListener('RNN.appLaunched', callback);
13
+  registerOnAppLaunched(callback: () => void): EventSubscription {
14
+    return this.emitter.addListener('RNN.onAppLaunched', callback);
15
   }
15
   }
16
 
16
 
17
   registerComponentDidAppear(callback: (componendId: string, componentName: string) => void): EventSubscription {
17
   registerComponentDidAppear(callback: (componendId: string, componentName: string) => void): EventSubscription {
22
     return this.emitter.addListener('RNN.componentDidDisappear', callback);
22
     return this.emitter.addListener('RNN.componentDidDisappear', callback);
23
   }
23
   }
24
 
24
 
25
-  registerInteraction(callback: (name: string) => void): EventSubscription {
26
-    return this.emitter.addListener('RNN.interaction', callback);
25
+  registerOnNavigationInteraction(callback: (name: string) => void): EventSubscription {
26
+    return this.emitter.addListener('RNN.onNavigationInteraction', callback);
27
   }
27
   }
28
 }
28
 }

+ 25
- 25
lib/src/components/ComponentWrapper.test.tsx Datei anzeigen

143
   });
143
   });
144
 
144
 
145
   describe('component lifecycle', () => {
145
   describe('component lifecycle', () => {
146
-    const didAppearCallback = jest.fn();
147
-    const didDisappearCallback = jest.fn();
148
-    const onNavigationButtonPressedCallback = jest.fn();
146
+    const componentDidAppearCallback = jest.fn();
147
+    const componentDidDisappearCallback = jest.fn();
148
+    const onNavigationInteractionCallback = jest.fn();
149
 
149
 
150
     class MyLifecycleComponent extends MyComponent {
150
     class MyLifecycleComponent extends MyComponent {
151
-      didAppear() {
152
-        didAppearCallback();
151
+      componentDidAppear() {
152
+        componentDidAppearCallback();
153
       }
153
       }
154
 
154
 
155
-      didDisappear() {
156
-        didDisappearCallback();
155
+      componentDidDisappear() {
156
+        componentDidDisappearCallback();
157
       }
157
       }
158
 
158
 
159
-      onNavigationButtonPressed() {
160
-        onNavigationButtonPressedCallback();
159
+      onNavigationInteraction() {
160
+        onNavigationInteractionCallback();
161
       }
161
       }
162
     }
162
     }
163
 
163
 
164
-    it('didAppear, didDisappear and onNavigationButtonPressed are optional', () => {
164
+    it('componentDidAppear, componentDidDisappear and onNavigationInteraction are optional', () => {
165
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
165
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
166
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
166
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
167
-      expect(() => tree.getInstance()!.didAppear()).not.toThrow();
168
-      expect(() => tree.getInstance()!.didDisappear()).not.toThrow();
169
-      expect(() => tree.getInstance()!.onNavigationButtonPressed()).not.toThrow();
167
+      expect(() => tree.getInstance()!.componentDidAppear()).not.toThrow();
168
+      expect(() => tree.getInstance()!.componentDidDisappear()).not.toThrow();
169
+      expect(() => tree.getInstance()!.onNavigationInteraction()).not.toThrow();
170
     });
170
     });
171
 
171
 
172
-    it('calls didAppear on OriginalComponent', () => {
172
+    it('calls componentDidAppear on OriginalComponent', () => {
173
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
173
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
174
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
174
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
175
-      expect(didAppearCallback).toHaveBeenCalledTimes(0);
176
-      tree.getInstance()!.didAppear();
177
-      expect(didAppearCallback).toHaveBeenCalledTimes(1);
175
+      expect(componentDidAppearCallback).toHaveBeenCalledTimes(0);
176
+      tree.getInstance()!.componentDidAppear();
177
+      expect(componentDidAppearCallback).toHaveBeenCalledTimes(1);
178
     });
178
     });
179
 
179
 
180
-    it('calls didDisappear on OriginalComponent', () => {
180
+    it('calls componentDidDisappear on OriginalComponent', () => {
181
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
181
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
182
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
182
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
183
-      expect(didDisappearCallback).toHaveBeenCalledTimes(0);
184
-      tree.getInstance()!.didDisappear();
185
-      expect(didDisappearCallback).toHaveBeenCalledTimes(1);
183
+      expect(componentDidDisappearCallback).toHaveBeenCalledTimes(0);
184
+      tree.getInstance()!.componentDidDisappear();
185
+      expect(componentDidDisappearCallback).toHaveBeenCalledTimes(1);
186
     });
186
     });
187
 
187
 
188
-    it('calls onNavigationButtonPressed on OriginalComponent', () => {
188
+    it('calls onNavigationInteraction on OriginalComponent', () => {
189
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
189
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
190
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
190
       const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
191
-      expect(onNavigationButtonPressedCallback).toHaveBeenCalledTimes(0);
192
-      tree.getInstance()!.onNavigationButtonPressed();
193
-      expect(onNavigationButtonPressedCallback).toHaveBeenCalledTimes(1);
191
+      expect(onNavigationInteractionCallback).toHaveBeenCalledTimes(0);
192
+      tree.getInstance()!.onNavigationInteraction();
193
+      expect(onNavigationInteractionCallback).toHaveBeenCalledTimes(1);
194
     });
194
     });
195
   });
195
   });
196
 });
196
 });

+ 10
- 10
lib/src/components/ComponentWrapper.tsx Datei anzeigen

41
         store.cleanId(this.state.componentId);
41
         store.cleanId(this.state.componentId);
42
       }
42
       }
43
 
43
 
44
-      didAppear() {
45
-        if (this.originalComponentRef.didAppear) {
46
-          this.originalComponentRef.didAppear();
44
+      componentDidAppear() {
45
+        if (this.originalComponentRef.componentDidAppear) {
46
+          this.originalComponentRef.componentDidAppear();
47
         }
47
         }
48
       }
48
       }
49
 
49
 
50
-      didDisappear() {
51
-        if (this.originalComponentRef.didDisappear) {
52
-          this.originalComponentRef.didDisappear();
50
+      componentDidDisappear() {
51
+        if (this.originalComponentRef.componentDidDisappear) {
52
+          this.originalComponentRef.componentDidDisappear();
53
         }
53
         }
54
       }
54
       }
55
 
55
 
56
-      onNavigationButtonPressed(buttonId) {
57
-        if (this.originalComponentRef.onNavigationButtonPressed) {
58
-          this.originalComponentRef.onNavigationButtonPressed(buttonId);
56
+      onNavigationInteraction(buttonId) {
57
+        if (this.originalComponentRef.onNavigationInteraction) {
58
+          this.originalComponentRef.onNavigationInteraction(buttonId);
59
         }
59
         }
60
       }
60
       }
61
 
61
 
69
         return (
69
         return (
70
           <OriginalComponentClass
70
           <OriginalComponentClass
71
             ref={this._saveComponentRef}
71
             ref={this._saveComponentRef}
72
-            { ...this.state.allProps }
72
+            {...this.state.allProps}
73
             componentId={this.state.componentId}
73
             componentId={this.state.componentId}
74
             key={this.state.componentId}
74
             key={this.state.componentId}
75
           />
75
           />

+ 8
- 8
lib/src/events/EventsRegistry.test.ts Datei anzeigen

13
   it('exposes appLaunch event', () => {
13
   it('exposes appLaunch event', () => {
14
     const subscription = {};
14
     const subscription = {};
15
     const cb = jest.fn();
15
     const cb = jest.fn();
16
-    mockNativeEventsReceiver.registerAppLaunched.mockReturnValueOnce(subscription);
16
+    mockNativeEventsReceiver.registerOnAppLaunched.mockReturnValueOnce(subscription);
17
 
17
 
18
-    const result = uut.appLaunched(cb);
18
+    const result = uut.onAppLaunched(cb);
19
 
19
 
20
     expect(result).toBe(subscription);
20
     expect(result).toBe(subscription);
21
-    expect(mockNativeEventsReceiver.registerAppLaunched).toHaveBeenCalledTimes(1);
22
-    expect(mockNativeEventsReceiver.registerAppLaunched).toHaveBeenCalledWith(cb);
21
+    expect(mockNativeEventsReceiver.registerOnAppLaunched).toHaveBeenCalledTimes(1);
22
+    expect(mockNativeEventsReceiver.registerOnAppLaunched).toHaveBeenCalledWith(cb);
23
   });
23
   });
24
 
24
 
25
   it('exposes componentDidAppear event', () => {
25
   it('exposes componentDidAppear event', () => {
49
   it('exposes interaction event', () => {
49
   it('exposes interaction event', () => {
50
     const subscription = {};
50
     const subscription = {};
51
     const cb = jest.fn();
51
     const cb = jest.fn();
52
-    mockNativeEventsReceiver.registerInteraction.mockReturnValueOnce(subscription);
52
+    mockNativeEventsReceiver.registerOnNavigationInteraction.mockReturnValueOnce(subscription);
53
 
53
 
54
-    const result = uut.interaction(cb);
54
+    const result = uut.onNavigationInteraction(cb);
55
 
55
 
56
     expect(result).toBe(subscription);
56
     expect(result).toBe(subscription);
57
-    expect(mockNativeEventsReceiver.registerInteraction).toHaveBeenCalledTimes(1);
58
-    expect(mockNativeEventsReceiver.registerInteraction).toHaveBeenCalledWith(cb);
57
+    expect(mockNativeEventsReceiver.registerOnNavigationInteraction).toHaveBeenCalledTimes(1);
58
+    expect(mockNativeEventsReceiver.registerOnNavigationInteraction).toHaveBeenCalledWith(cb);
59
   });
59
   });
60
 });
60
 });

+ 4
- 4
lib/src/events/EventsRegistry.ts Datei anzeigen

7
     this.nativeEventsReceiver = nativeEventsReceiver;
7
     this.nativeEventsReceiver = nativeEventsReceiver;
8
   }
8
   }
9
 
9
 
10
-  public appLaunched(callback: () => void): EventSubscription {
11
-    return this.nativeEventsReceiver.registerAppLaunched(callback);
10
+  public onAppLaunched(callback: () => void): EventSubscription {
11
+    return this.nativeEventsReceiver.registerOnAppLaunched(callback);
12
   }
12
   }
13
 
13
 
14
   public componentDidAppear(callback: (componendId: string, componentName: string) => void): EventSubscription {
14
   public componentDidAppear(callback: (componendId: string, componentName: string) => void): EventSubscription {
19
     return this.nativeEventsReceiver.registerComponentDidDisappear(callback);
19
     return this.nativeEventsReceiver.registerComponentDidDisappear(callback);
20
   }
20
   }
21
 
21
 
22
-  public interaction(callback: (name: string) => void): EventSubscription {
23
-    return this.nativeEventsReceiver.registerInteraction(callback);
22
+  public onNavigationInteraction(callback: (name: string) => void): EventSubscription {
23
+    return this.nativeEventsReceiver.registerOnNavigationInteraction(callback);
24
   }
24
   }
25
 }
25
 }