Ver código fonte

changed API, better naming

Daniel Zlotin 6 anos atrás
pai
commit
7b51a48936

+ 4
- 4
lib/src/adapters/NativeEventsReceiver.ts Ver arquivo

@@ -10,8 +10,8 @@ export class NativeEventsReceiver {
10 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 17
   registerComponentDidAppear(callback: (componendId: string, componentName: string) => void): EventSubscription {
@@ -22,7 +22,7 @@ export class NativeEventsReceiver {
22 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 Ver arquivo

@@ -143,54 +143,54 @@ describe('ComponentWrapper', () => {
143 143
   });
144 144
 
145 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 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 165
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
166 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 173
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
174 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 181
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
182 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 189
       const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
190 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 Ver arquivo

@@ -41,21 +41,21 @@ export class ComponentWrapper {
41 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,7 +69,7 @@ export class ComponentWrapper {
69 69
         return (
70 70
           <OriginalComponentClass
71 71
             ref={this._saveComponentRef}
72
-            { ...this.state.allProps }
72
+            {...this.state.allProps}
73 73
             componentId={this.state.componentId}
74 74
             key={this.state.componentId}
75 75
           />

+ 8
- 8
lib/src/events/EventsRegistry.test.ts Ver arquivo

@@ -13,13 +13,13 @@ describe('EventsRegistry', () => {
13 13
   it('exposes appLaunch event', () => {
14 14
     const subscription = {};
15 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 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 25
   it('exposes componentDidAppear event', () => {
@@ -49,12 +49,12 @@ describe('EventsRegistry', () => {
49 49
   it('exposes interaction event', () => {
50 50
     const subscription = {};
51 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 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 Ver arquivo

@@ -7,8 +7,8 @@ export class EventsRegistry {
7 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 14
   public componentDidAppear(callback: (componendId: string, componentName: string) => void): EventSubscription {
@@ -19,7 +19,7 @@ export class EventsRegistry {
19 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
 }