Browse Source

refactor eventListener

Daniel Zlotin 6 years ago
parent
commit
a93cb53718

+ 4
- 4
lib/src/adapters/NativeEventsReceiver.js View File

@@ -5,19 +5,19 @@ class NativeEventsReceiver {
5 5
     this.emitter = new NativeEventEmitter(NativeModules.RNNEventEmitter);
6 6
   }
7 7
 
8
-  componentDidAppear(callback) {
8
+  registerComponentDidAppear(callback) {
9 9
     this.emitter.addListener('RNN.componentDidAppear', callback);
10 10
   }
11 11
 
12
-  componentDidDisappear(callback) {
12
+  registerComponentDidDisappear(callback) {
13 13
     this.emitter.addListener('RNN.componentDidDisappear', callback);
14 14
   }
15 15
 
16
-  appLaunched(callback) {
16
+  registerAppLaunched(callback) {
17 17
     this.emitter.addListener('RNN.appLaunched', callback);
18 18
   }
19 19
 
20
-  navigationButtonPressed(callback) {
20
+  registerNavigationButtonPressed(callback) {
21 21
     this.emitter.addListener('RNN.navigationButtonPressed', callback);
22 22
   }
23 23
 }

+ 3
- 3
lib/src/events/PrivateEventsListener.js View File

@@ -7,9 +7,9 @@ class PrivateEventsListener {
7 7
   }
8 8
 
9 9
   listenAndHandlePrivateEvents() {
10
-    this.nativeEventsReceiver.componentDidAppear(this.lifecycle.componentDidAppear);
11
-    this.nativeEventsReceiver.componentDidDisappear(this.lifecycle.componentDidDisappear);
12
-    this.nativeEventsReceiver.navigationButtonPressed(this.lifecycle.onNavigationButtonPressed);
10
+    this.nativeEventsReceiver.registerComponentDidAppear(this.lifecycle.componentDidAppear);
11
+    this.nativeEventsReceiver.registerComponentDidDisappear(this.lifecycle.componentDidDisappear);
12
+    this.nativeEventsReceiver.registerNavigationButtonPressed(this.lifecycle.onNavigationButtonPressed);
13 13
   }
14 14
 }
15 15
 

+ 5
- 5
lib/src/events/PrivateEventsListener.test.js View File

@@ -19,8 +19,8 @@ describe('PrivateEventsListener', () => {
19 19
     };
20 20
     store.setRefForComponentId('myComponentId', mockRef);
21 21
     uut.listenAndHandlePrivateEvents();
22
-    expect(nativeEventsReceiver.componentDidAppear).toHaveBeenCalledTimes(1);
23
-    const callbackFunction = nativeEventsReceiver.componentDidAppear.mock.calls[0][0];
22
+    expect(nativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledTimes(1);
23
+    const callbackFunction = nativeEventsReceiver.registerComponentDidAppear.mock.calls[0][0];
24 24
     expect(callbackFunction).toBeInstanceOf(Function);
25 25
 
26 26
     expect(mockRef.didAppear).not.toHaveBeenCalled();
@@ -31,7 +31,7 @@ describe('PrivateEventsListener', () => {
31 31
 
32 32
   it('register and listen componentDidDisappear', () => {
33 33
     uut.listenAndHandlePrivateEvents();
34
-    expect(nativeEventsReceiver.componentDidDisappear).toHaveBeenCalledTimes(1);
34
+    expect(nativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledTimes(1);
35 35
   });
36 36
 
37 37
   it('register and handle onNavigationButtonPressed', () => {
@@ -40,8 +40,8 @@ describe('PrivateEventsListener', () => {
40 40
     };
41 41
     store.setRefForComponentId('myComponentId', mockRef);
42 42
     uut.listenAndHandlePrivateEvents();
43
-    expect(nativeEventsReceiver.navigationButtonPressed).toHaveBeenCalledTimes(1);
44
-    const callbackFunction = nativeEventsReceiver.navigationButtonPressed.mock.calls[0][0];
43
+    expect(nativeEventsReceiver.registerNavigationButtonPressed).toHaveBeenCalledTimes(1);
44
+    const callbackFunction = nativeEventsReceiver.registerNavigationButtonPressed.mock.calls[0][0];
45 45
     expect(callbackFunction).toBeInstanceOf(Function);
46 46
 
47 47
     expect(mockRef.onNavigationButtonPressed).not.toHaveBeenCalled();

+ 1
- 1
lib/src/events/PublicEventsRegistry.js View File

@@ -4,7 +4,7 @@ class PublicEventsRegistry {
4 4
   }
5 5
 
6 6
   onAppLaunched(callback) {
7
-    this.nativeEventsReceiver.appLaunched(callback);
7
+    this.nativeEventsReceiver.registerAppLaunched(callback);
8 8
   }
9 9
 }
10 10
 

+ 2
- 2
lib/src/events/PublicEventsRegistry.test.js View File

@@ -13,7 +13,7 @@ describe('PublicEventsRegistry', () => {
13 13
   it('exposes onAppLaunch event', () => {
14 14
     const cb = jest.fn();
15 15
     uut.onAppLaunched(cb);
16
-    expect(nativeEventsReceiver.appLaunched).toHaveBeenCalledTimes(1);
17
-    expect(nativeEventsReceiver.appLaunched).toHaveBeenCalledWith(cb);
16
+    expect(nativeEventsReceiver.registerAppLaunched).toHaveBeenCalledTimes(1);
17
+    expect(nativeEventsReceiver.registerAppLaunched).toHaveBeenCalledWith(cb);
18 18
   });
19 19
 });

+ 18
- 17
scripts/generate-js-doc.js View File

@@ -1,4 +1,5 @@
1
-throw new Error('temporarily disabled, until newAPI is complete')
1
+throw new Error('temporarily disabled, until newAPI is complete');
2
+/*
2 3
 const jsdoc2md = require('jsdoc-to-markdown');
3 4
 const fs = require('fs');
4 5
 const path = require('path');
@@ -60,23 +61,23 @@ function inputFiles() {
60 61
       };
61 62
     }),
62 63
     ...fs.readdirSync(CONTAINERS_DIR)
63
-        .map((file) => {
64
-          return {
65
-            file: CONTAINERS_DIR + file,
66
-            outputDir: OUTPUT_DIR,
67
-            partial: PARAMS_PARTIALS,
68
-            separator: false
69
-          };
70
-        }),
64
+      .map((file) => {
65
+        return {
66
+          file: CONTAINERS_DIR + file,
67
+          outputDir: OUTPUT_DIR,
68
+          partial: PARAMS_PARTIALS,
69
+          separator: false
70
+        };
71
+      }),
71 72
     ...fs.readdirSync(BASE_DIR)
72
-        .filter((file) => fs.statSync(BASE_DIR + file).isFile())
73
-        .map((file) => {
74
-          return {
75
-            file: BASE_DIR + file,
76
-            outputDir: OUTPUT_DIR
77
-          };
78
-        })
73
+      .filter((file) => fs.statSync(BASE_DIR + file).isFile())
74
+      .map((file) => {
75
+        return {
76
+          file: BASE_DIR + file,
77
+          outputDir: OUTPUT_DIR
78
+        };
79
+      })
79 80
   ];
80 81
 }
81 82
 
82
-inputFiles().forEach((inputFile) => generateMarkdownForFile(inputFile));
83
+inputFiles().forEach((inputFile) => generateMarkdownForFile(inputFile)); */