Browse Source

migrating

Daniel Zlotin 7 years ago
parent
commit
a8d4aee11d

+ 0
- 1
lib/src/Navigation.js View File

@@ -11,7 +11,6 @@ const PublicEventsRegistry = require('./events/PublicEventsRegistry');
11 11
 
12 12
 import { Element } from './adapters/Element';
13 13
 
14
-/** @constructor */
15 14
 class Navigation {
16 15
   constructor() {
17 16
     this.store = new Store();

+ 0
- 1
lib/src/adapters/NativeCommandsSender.mock.js View File

@@ -1 +0,0 @@
1
-module.exports = jest.genMockFromModule('./NativeCommandsSender');

+ 1
- 0
lib/src/adapters/NativeCommandsSender.mock.ts View File

@@ -0,0 +1 @@
1
+export const { NativeCommandsSender } = jest.genMockFromModule('./NativeCommandsSender');

lib/src/adapters/NativeCommandsSender.js → lib/src/adapters/NativeCommandsSender.ts View File

@@ -1,45 +1,47 @@
1
-const { NativeModules } = require('react-native');
1
+import { NativeModules } from 'react-native';
2
+
3
+export class NativeCommandsSender {
4
+  private nativeCommandsModule: any;
2 5
 
3
-class NativeCommandsSender {
4 6
   constructor() {
5 7
     this.nativeCommandsModule = NativeModules.RNNBridgeModule;
6 8
   }
7 9
 
8
-  setRoot(layoutTree) {
10
+  setRoot(layoutTree: object) {
9 11
     return this.nativeCommandsModule.setRoot(layoutTree);
10 12
   }
11 13
 
12
-  setDefaultOptions(options) {
14
+  setDefaultOptions(options: object) {
13 15
     this.nativeCommandsModule.setDefaultOptions(options);
14 16
   }
15 17
 
16
-  setOptions(componentId, options) {
18
+  setOptions(componentId: string, options: object) {
17 19
     this.nativeCommandsModule.setOptions(componentId, options);
18 20
   }
19 21
 
20
-  async push(onComponentId, layout) {
22
+  async push(onComponentId: string, layout: object) {
21 23
     const pushedComponentId = await this.nativeCommandsModule.push(onComponentId, layout);
22 24
     return pushedComponentId;
23 25
   }
24 26
 
25
-  pop(componentId, options) {
27
+  pop(componentId: string, options: object) {
26 28
     return this.nativeCommandsModule.pop(componentId, options);
27 29
   }
28 30
 
29
-  popTo(componentId) {
31
+  popTo(componentId: string) {
30 32
     return this.nativeCommandsModule.popTo(componentId);
31 33
   }
32 34
 
33
-  popToRoot(componentId) {
35
+  popToRoot(componentId: string) {
34 36
     return this.nativeCommandsModule.popToRoot(componentId);
35 37
   }
36 38
 
37
-  async showModal(layout) {
39
+  async showModal(layout: object) {
38 40
     const completed = await this.nativeCommandsModule.showModal(layout);
39 41
     return completed;
40 42
   }
41 43
 
42
-  dismissModal(componentId) {
44
+  dismissModal(componentId: string) {
43 45
     return this.nativeCommandsModule.dismissModal(componentId);
44 46
   }
45 47
 
@@ -47,7 +49,7 @@ class NativeCommandsSender {
47 49
     return this.nativeCommandsModule.dismissAllModals();
48 50
   }
49 51
 
50
-  showOverlay(type, options) {
52
+  showOverlay(type: any, options: object) {
51 53
     return this.nativeCommandsModule.showOverlay(type, options);
52 54
   }
53 55
 
@@ -56,5 +58,3 @@ class NativeCommandsSender {
56 58
     return Promise.resolve(true);
57 59
   }
58 60
 }
59
-
60
-module.exports = NativeCommandsSender;

+ 0
- 1
lib/src/adapters/NativeEventsReceiver.mock.js View File

@@ -1 +0,0 @@
1
-module.exports = jest.genMockFromModule('./NativeEventsReceiver');

+ 1
- 0
lib/src/adapters/NativeEventsReceiver.mock.ts View File

@@ -0,0 +1 @@
1
+export const { NativeEventsReceiver } = jest.genMockFromModule('./NativeEventsReceiver');

lib/src/adapters/NativeEventsReceiver.js → lib/src/adapters/NativeEventsReceiver.ts View File

@@ -1,25 +1,25 @@
1
-const { NativeModules, NativeEventEmitter } = require('react-native');
1
+import { NativeModules, NativeEventEmitter } from 'react-native';
2
+
3
+export class NativeEventsReceiver {
4
+  private emitter: NativeEventEmitter;
2 5
 
3
-class NativeEventsReceiver {
4 6
   constructor() {
5 7
     this.emitter = new NativeEventEmitter(NativeModules.RNNEventEmitter);
6 8
   }
7 9
 
8
-  registerComponentDidAppear(callback) {
10
+  registerComponentDidAppear(callback: any) {
9 11
     this.emitter.addListener('RNN.componentDidAppear', callback);
10 12
   }
11 13
 
12
-  registerComponentDidDisappear(callback) {
14
+  registerComponentDidDisappear(callback: any) {
13 15
     this.emitter.addListener('RNN.componentDidDisappear', callback);
14 16
   }
15 17
 
16
-  registerAppLaunched(callback) {
18
+  registerAppLaunched(callback: any) {
17 19
     this.emitter.addListener('RNN.appLaunched', callback);
18 20
   }
19 21
 
20
-  registerNavigationButtonPressed(callback) {
22
+  registerNavigationButtonPressed(callback: any) {
21 23
     this.emitter.addListener('RNN.navigationButtonPressed', callback);
22 24
   }
23 25
 }
24
-
25
-module.exports = NativeEventsReceiver;

+ 0
- 9
lib/src/adapters/UniqueIdProvider.js View File

@@ -1,9 +0,0 @@
1
-const _ = require('lodash');
2
-
3
-class UniqueIdProvider {
4
-  generate(prefix) {
5
-    return _.uniqueId(prefix);
6
-  }
7
-}
8
-
9
-module.exports = UniqueIdProvider;

+ 0
- 7
lib/src/adapters/UniqueIdProvider.mock.js View File

@@ -1,7 +0,0 @@
1
-class UniqueIdProvider {
2
-  generate(prefix) {
3
-    return `${prefix}+UNIQUE_ID`;
4
-  }
5
-}
6
-
7
-module.exports = UniqueIdProvider;

+ 5
- 0
lib/src/adapters/UniqueIdProvider.mock.ts View File

@@ -0,0 +1,5 @@
1
+export class UniqueIdProvider {
2
+  generate(prefix: string): string {
3
+    return `${prefix}+UNIQUE_ID`;
4
+  }
5
+}

+ 7
- 0
lib/src/adapters/UniqueIdProvider.ts View File

@@ -0,0 +1,7 @@
1
+import * as _ from 'lodash';
2
+
3
+export class UniqueIdProvider {
4
+  generate(prefix: string): string {
5
+    return _.uniqueId(prefix);
6
+  }
7
+}

+ 2
- 2
lib/src/commands/Commands.test.js View File

@@ -1,8 +1,8 @@
1 1
 const LayoutTreeParser = require('./LayoutTreeParser');
2 2
 const LayoutTreeCrawler = require('./LayoutTreeCrawler');
3 3
 const Store = require('../components/Store');
4
-const UniqueIdProvider = require('../adapters/UniqueIdProvider.mock');
5
-const NativeCommandsSender = require('../adapters/NativeCommandsSender.mock');
4
+const { UniqueIdProvider } = require('../adapters/UniqueIdProvider.mock');
5
+const { NativeCommandsSender } = require('../adapters/NativeCommandsSender.mock');
6 6
 const Commands = require('./Commands');
7 7
 
8 8
 describe('Commands', () => {

+ 2
- 1
lib/src/commands/LayoutTreeCrawler.js View File

@@ -1,5 +1,6 @@
1
+import { LayoutTypes } from './LayoutTypes';
2
+
1 3
 const _ = require('lodash');
2
-const LayoutTypes = require('./LayoutTypes');
3 4
 const OptionsProcessor = require('./OptionsProcessor');
4 5
 
5 6
 class LayoutTreeCrawler {

+ 2
- 1
lib/src/commands/LayoutTreeParser.js View File

@@ -1,5 +1,6 @@
1
+import { LayoutTypes } from './LayoutTypes';
2
+
1 3
 const _ = require('lodash');
2
-const LayoutTypes = require('./LayoutTypes');
3 4
 
4 5
 class LayoutTreeParser {
5 6
   constructor() {

+ 0
- 10
lib/src/commands/LayoutTypes.js View File

@@ -1,10 +0,0 @@
1
-module.exports = {
2
-  Component: 'Component',
3
-  Stack: 'Stack',
4
-  BottomTabs: 'BottomTabs',
5
-  SideMenuRoot: 'SideMenuRoot',
6
-  SideMenuCenter: 'SideMenuCenter',
7
-  SideMenuLeft: 'SideMenuLeft',
8
-  SideMenuRight: 'SideMenuRight',
9
-  TopTabs: 'TopTabs'
10
-};

+ 10
- 0
lib/src/commands/LayoutTypes.ts View File

@@ -0,0 +1,10 @@
1
+export const enum LayoutTypes {
2
+  Component = 'Component',
3
+  Stack = 'Stack',
4
+  BottomTabs = 'BottomTabs',
5
+  SideMenuRoot = 'SideMenuRoot',
6
+  SideMenuCenter = 'SideMenuCenter',
7
+  SideMenuLeft = 'SideMenuLeft',
8
+  SideMenuRight = 'SideMenuRight',
9
+  TopTabs = 'TopTabs'
10
+};

lib/src/commands/OptionsProcessor.test.js → lib/src/commands/OptionsProcessor.test.ts View File

@@ -1,7 +1,7 @@
1
-const OptionsProcessor = require('./OptionsProcessor');
1
+import { OptionsProcessor } from './OptionsProcessor';
2 2
 
3 3
 describe('navigation options', () => {
4
-  let options;
4
+  let options: any;
5 5
 
6 6
   beforeEach(() => {
7 7
     options = {};

lib/src/commands/OptionsProcessor.js → lib/src/commands/OptionsProcessor.ts View File

@@ -1,9 +1,9 @@
1
-const _ = require('lodash');
2
-const { processColor } = require('react-native');
3
-const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
1
+import * as _ from 'lodash';
2
+import { processColor } from 'react-native';
3
+import * as resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
4 4
 
5
-class OptionsProcessor {
6
-  static processOptions(options) {
5
+export class OptionsProcessor {
6
+  static processOptions(options: any) {
7 7
     _.forEach(options, (value, key) => {
8 8
       if (value) {
9 9
         if (_.endsWith(key, 'Color')) {
@@ -19,5 +19,3 @@ class OptionsProcessor {
19 19
     });
20 20
   }
21 21
 }
22
-
23
-module.exports = OptionsProcessor;

lib/src/events/PrivateEventsListener.test.js → lib/src/events/PrivateEventsListener.test.ts View File

@@ -1,11 +1,11 @@
1
-const PrivateEventsListener = require('./PrivateEventsListener');
2
-const NativeEventsReceiver = require('../adapters/NativeEventsReceiver.mock');
3
-const Store = require('../components/Store');
1
+import { PrivateEventsListener } from './PrivateEventsListener';
2
+import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver.mock';
3
+import * as  Store from '../components/Store';
4 4
 
5 5
 describe('PrivateEventsListener', () => {
6
-  let uut;
7
-  let nativeEventsReceiver;
8
-  let store;
6
+  let uut: PrivateEventsListener;
7
+  let nativeEventsReceiver: any;
8
+  let store: any;
9 9
 
10 10
   beforeEach(() => {
11 11
     nativeEventsReceiver = new NativeEventsReceiver();

lib/src/events/PrivateEventsListener.js → lib/src/events/PrivateEventsListener.ts View File

@@ -1,7 +1,10 @@
1
-const Lifecycle = require('../components/Lifecycle');
1
+import * as Lifecycle from '../components/Lifecycle';
2 2
 
3
-class PrivateEventsListener {
4
-  constructor(nativeEventsReceiver, store) {
3
+export class PrivateEventsListener {
4
+  private nativeEventsReceiver: any;
5
+  private lifecycle: any;
6
+
7
+  constructor(nativeEventsReceiver: any, store: any) {
5 8
     this.nativeEventsReceiver = nativeEventsReceiver;
6 9
     this.lifecycle = new Lifecycle(store);
7 10
   }
@@ -12,5 +15,3 @@ class PrivateEventsListener {
12 15
     this.nativeEventsReceiver.registerNavigationButtonPressed(this.lifecycle.onNavigationButtonPressed);
13 16
   }
14 17
 }
15
-
16
-module.exports = PrivateEventsListener;

+ 1
- 0
lib/src/globals.d.ts View File

@@ -0,0 +1 @@
1
+declare module 'react-native/Libraries/Image/resolveAssetSource';

+ 0
- 1
tsconfig.json View File

@@ -1,5 +1,4 @@
1 1
 {
2
-  "extends": "./tsconfig-strict",
3 2
   "compilerOptions": {
4 3
     "outDir": "./lib/dist",
5 4
     "allowJs": true,