Skip to content

Commit f717a2b

Browse files
authored
refactor: Replace require with import statement (#2143)
1 parent 09a2d0b commit f717a2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+654
-209
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"require-atomic-updates": "off",
4141
"prefer-spread": "off",
4242
"prefer-rest-params": "off",
43+
"@typescript-eslint/ban-ts-comment": "off",
4344
"@typescript-eslint/triple-slash-reference": "off",
4445
"@typescript-eslint/no-empty-function": "off",
4546
"@typescript-eslint/no-explicit-any": "off",

src/Analytics.js renamed to src/Analytics.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @flow
3-
*/
4-
51
import CoreManager from './CoreManager';
62

73
/**
@@ -44,7 +40,7 @@ import CoreManager from './CoreManager';
4440
* @returns {Promise} A promise that is resolved when the round-trip
4541
* to the server completes.
4642
*/
47-
export function track(name: string, dimensions: { [key: string]: string }): Promise {
43+
export function track(name: string, dimensions: { [key: string]: string }): Promise<void> {
4844
name = name || '';
4945
name = name.replace(/^\s*/, '');
5046
name = name.replace(/\s*$/, '');
@@ -62,10 +58,10 @@ export function track(name: string, dimensions: { [key: string]: string }): Prom
6258
}
6359

6460
const DefaultController = {
65-
track(name, dimensions) {
61+
track(name: string, dimensions: { [key: string]: string }) {
6662
const path = 'events/' + name;
6763
const RESTController = CoreManager.getRESTController();
68-
return RESTController.request('POST', path, { dimensions: dimensions });
64+
return RESTController.request('POST', path, { dimensions });
6965
},
7066
};
7167

src/AnonymousUtils.js renamed to src/AnonymousUtils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/**
2-
* @flow-weak
3-
*/
4-
51
import ParseUser from './ParseUser';
62
import type { RequestOptions } from './RESTController';
7-
const uuidv4 = require('./uuid');
3+
import uuidv4 from './uuid';
84

95
let registered = false;
106

File renamed without changes.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let AES;
2-
let ENC;
1+
let AES: any;
2+
let ENC: any;
33

44
if (process.env.PARSE_BUILD === 'react-native') {
55
const CryptoJS = require('react-native-crypto-js');
@@ -11,15 +11,16 @@ if (process.env.PARSE_BUILD === 'react-native') {
1111
}
1212

1313
const CryptoController = {
14-
encrypt(obj: any, secretKey: string): ?string {
14+
encrypt(obj: any, secretKey: string): string {
1515
const encrypted = AES.encrypt(JSON.stringify(obj), secretKey);
1616
return encrypted.toString();
1717
},
1818

19-
decrypt(encryptedText: string, secretKey: string): ?string {
19+
decrypt(encryptedText: string, secretKey: string): string {
2020
const decryptedStr = AES.decrypt(encryptedText, secretKey).toString(ENC);
2121
return decryptedStr;
2222
},
2323
};
2424

2525
module.exports = CryptoController;
26+
export default CryptoController;

src/EventEmitter.js renamed to src/EventEmitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This is a simple wrapper to unify EventEmitter implementations across platforms.
33
*/
44

5-
let EventEmitter;
5+
let EventEmitter: any;
66

77
try {
88
if (process.env.PARSE_BUILD === 'react-native') {
@@ -18,3 +18,4 @@ try {
1818
// EventEmitter unavailable
1919
}
2020
module.exports = EventEmitter;
21+
export default EventEmitter;

src/LiveQueryClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ const generateInterval = k => {
7272
* We expose three events to help you monitor the status of the LiveQueryClient.
7373
*
7474
* <pre>
75-
* let Parse = require('parse/node');
76-
* let LiveQueryClient = Parse.LiveQueryClient;
77-
* let client = new LiveQueryClient({
75+
* const LiveQueryClient = Parse.LiveQueryClient;
76+
* const client = new LiveQueryClient({
7877
* applicationId: '',
7978
* serverURL: '',
8079
* javascriptKey: '',

src/LocalDatastore.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import CoreManager from './CoreManager';
2-
2+
import LocalDatastoreController from './LocalDatastoreController';
33
import type ParseObject from './ParseObject';
44
import ParseQuery from './ParseQuery';
55
import { DEFAULT_PIN, PIN_PREFIX, OBJECT_PREFIX } from './LocalDatastoreUtils';
@@ -390,9 +390,5 @@ const LocalDatastore = {
390390
module.exports = LocalDatastore;
391391
export default LocalDatastore;
392392

393-
if (process.env.PARSE_BUILD === 'react-native') {
394-
CoreManager.setLocalDatastoreController(require('./LocalDatastoreController.react-native'));
395-
} else {
396-
CoreManager.setLocalDatastoreController(require('./LocalDatastoreController'));
397-
}
393+
CoreManager.setLocalDatastoreController(LocalDatastoreController);
398394
CoreManager.setLocalDatastore(LocalDatastore);

src/LocalDatastoreController.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/LocalDatastoreController.react-native.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isLocalDatastoreKey } from './LocalDatastoreUtils';
2-
const RNStorage = require('./StorageController.react-native');
2+
import RNStorage from './StorageController.react-native';
33

44
const LocalDatastoreController = {
55
async fromPinWithName(name: string): Promise<Array<any>> {
@@ -35,7 +35,7 @@ const LocalDatastoreController = {
3535
}
3636
}
3737
const LDS = {};
38-
let results: any[] = [];
38+
let results: any = [];
3939
try {
4040
results = await RNStorage.multiGet(batch);
4141
} catch (error) {
@@ -57,8 +57,8 @@ const LocalDatastoreController = {
5757
async getRawStorage(): Promise<any> {
5858
const keys = await RNStorage.getAllKeysAsync();
5959
const storage = {};
60-
const results = await RNStorage.multiGet(keys);
61-
results.map(pair => {
60+
const results = await RNStorage.multiGet(keys as string[]);
61+
results!.map(pair => {
6262
const [key, value] = pair;
6363
storage[key] = value;
6464
});
@@ -74,7 +74,7 @@ const LocalDatastoreController = {
7474
batch.push(key);
7575
}
7676
}
77-
return RNStorage.multiRemove(batch).catch(error =>
77+
await RNStorage.multiRemove(batch).catch(error =>
7878
console.error('Error clearing local datastore: ', error)
7979
);
8080
},

0 commit comments

Comments
 (0)