Skip to content

Commit 90d03d2

Browse files
authored
Move uuidv4 to helper to avoid circular dependency with React Compiler (#342)
* Create helpers.ts * Update Uploader.tsx * Update Downloader.tsx * Update index.tsx
1 parent 509e5ed commit 90d03d2

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/utils/Downloader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NativeEventEmitter, Platform } from 'react-native';
22
import type { NativeEventSubscription } from 'react-native';
33
import { Compressor } from '../Main';
44
const CompressEventEmitter = new NativeEventEmitter(Compressor);
5-
import { uuidv4 } from './index';
5+
import { uuidv4 } from './helpers';
66
export const download = async (
77
fileUrl: string,
88
downloadProgress?: (progress: number) => void,

src/utils/Uploader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NativeEventEmitter, Platform } from 'react-native';
22
import type { NativeEventSubscription } from 'react-native';
33
import { Compressor } from '../Main';
44
const CompressEventEmitter = new NativeEventEmitter(Compressor);
5-
import { uuidv4 } from './index';
5+
import { uuidv4 } from './helpers';
66
export enum UploadType {
77
BINARY_CONTENT = 0,
88
MULTIPART = 1,

src/utils/helpers.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const uuidv4 = () => {
2+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
3+
const r =
4+
(parseFloat(
5+
'0.' +
6+
Math.random().toString().replace('0.', '') +
7+
new Date().getTime()
8+
) *
9+
16) |
10+
0,
11+
// eslint-disable-next-line eqeqeq
12+
v = c == 'x' ? r : (r & 0x3) | 0x8;
13+
return v.toString(16);
14+
});
15+
};

src/utils/index.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,6 @@ export const getFileSize = async (filePath: string): Promise<string> => {
194194
return Compressor.getFileSize(filePath);
195195
};
196196

197-
export const uuidv4 = () => {
198-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
199-
const r =
200-
(parseFloat(
201-
'0.' +
202-
Math.random().toString().replace('0.', '') +
203-
new Date().getTime()
204-
) *
205-
16) |
206-
0,
207-
// eslint-disable-next-line eqeqeq
208-
v = c == 'x' ? r : (r & 0x3) | 0x8;
209-
return v.toString(16);
210-
});
211-
};
212197
export * from './Downloader';
213198
export * from './Uploader';
199+
export * from './helpers';

0 commit comments

Comments
 (0)