Skip to content

Commit 8256767

Browse files
author
Ron Radtke
committed
Fixing the import cycles
1 parent a95cd84 commit 8256767

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

blobResponse.js renamed to class/ReactnativeBlobUtilBlobResponse.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {ReactNativeBlobUtilResponseInfo, ReactNativeBlobUtilStream} from "types";
2-
import fs from "fs";
3-
import polyfill from "polyfill";
1+
import {ReactNativeBlobUtilResponseInfo, ReactNativeBlobUtilStream} from "../types";
2+
import fs from "../fs";
3+
import polyfill from "../polyfill";
44

55
/**
66
* ReactNativeBlobUtil response object class.

fetch.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
import {ReactNativeBlobUtilConfig} from "types";
2-
import URIUtil from "utils/uri";
3-
import fs from "fs";
4-
import getUUID from "utils/uuid";
1+
import {ReactNativeBlobUtilConfig} from "./types";
2+
import URIUtil from "./utils/uri";
3+
import fs from "./fs";
4+
import getUUID from "./utils/uuid";
5+
import {DeviceEventEmitter, NativeModules} from "react-native";
6+
import {FetchBlobResponse} from "./class/ReactnativeBlobUtilBlobResponse";
7+
8+
const emitter = DeviceEventEmitter;
9+
const ReactNativeBlobUtil = NativeModules.ReactNativeBlobUtil;
10+
11+
// register message channel event handler.
12+
emitter.addListener("ReactNativeBlobUtilMessage", (e) => {
13+
14+
if (e.event === 'warn') {
15+
console.warn(e.detail);
16+
}
17+
else if (e.event === 'error') {
18+
throw e.detail;
19+
}
20+
else {
21+
console.log("ReactNativeBlobUtil native message", e.detail);
22+
}
23+
});
524

625
export function wrap(path: string): string {
726
const prefix = path.startsWith('content://') ? 'ReactNativeBlobUtil-content://' : 'ReactNativeBlobUtil-file://';

index.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ if (Platform.OS === 'ios') {
4343
});
4444
}
4545

46-
// register message channel event handler.
47-
emitter.addListener("ReactNativeBlobUtilMessage", (e) => {
48-
49-
if (e.event === 'warn') {
50-
console.warn(e.detail);
51-
}
52-
else if (e.event === 'error') {
53-
throw e.detail;
54-
}
55-
else {
56-
console.log("ReactNativeBlobUtil native message", e.detail);
57-
}
58-
});
59-
6046
// Show warning if native module not detected
6147
if (!ReactNativeBlobUtil || !ReactNativeBlobUtil.fetchBlobForm || !ReactNativeBlobUtil.fetchBlob) {
6248
console.warn(
@@ -67,7 +53,7 @@ if (!ReactNativeBlobUtil || !ReactNativeBlobUtil.fetchBlobForm || !ReactNativeBl
6753
}
6854
export {ReactNativeBlobUtilConfig, ReactNativeBlobUtilResponseInfo, ReactNativeBlobUtilStream} from './types';
6955
export URIUtil from './utils/uri';
70-
export {FetchBlobResponse} from './blobResponse';
56+
export {FetchBlobResponse} from './class/ReactnativeBlobUtilBlobResponse';
7157
export getUUID from './utils/uuid';
7258
export default {
7359
fetch,

polyfill/Blob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import getUUID from '../utils/uuid';
77
import Log from '../utils/log.js';
88
import EventTarget from './EventTarget';
99

10-
import ReactNativeBlobUtil from "../index";
10+
import {wrap} from "../fetch";
1111

1212
const log = new Log('Blob');
1313
const blobCacheDir = fs.dirs.DocumentDir + '/ReactNativeBlobUtil-blobs/';
@@ -237,7 +237,7 @@ export default class Blob extends EventTarget {
237237
let resPath = blobCacheDir + getBlobName();
238238
let pass = false;
239239
log.debug('fs.slice new blob will at', resPath);
240-
let result = new Blob(ReactNativeBlobUtil.wrap(resPath), {type: contentType}, true);
240+
let result = new Blob(wrap(resPath), {type: contentType}, true);
241241
fs.exists(blobCacheDir)
242242
.then((exist) => {
243243
if (exist)

polyfill/Fetch.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import Log from '../utils/log.js';
22
import Blob from './Blob';
3-
import {NativeModules} from "react-native";
4-
5-
const ReactNativeBlobUtil: ReactNativeBlobUtilNative = NativeModules.ReactNativeBlobUtil;
3+
import {wrap, config as RNconfig} from "../fetch";
4+
import type {ReactNativeBlobUtilConfig} from "../types";
65

76
const log = new Log('FetchPolyfill');
87

@@ -40,12 +39,12 @@ class ReactNativeBlobUtilFetchPolyfill {
4039
promise = Blob.build(body).then((b) => {
4140
blobCache = b;
4241
options.headers['Content-Type'] = 'multipart/form-data;boundary=' + b.multipartBoundary;
43-
return Promise.resolve(ReactNativeBlobUtil.wrap(b._ref));
42+
return Promise.resolve(wrap(b._ref));
4443
});
4544
}
4645
// When request body is a Blob, use file URI of the Blob as request body.
4746
else if (body.isReactNativeBlobUtilPolyfill)
48-
promise = Promise.resolve(ReactNativeBlobUtil.wrap(body.blobPath));
47+
promise = Promise.resolve(wrap(body.blobPath));
4948
else if (typeof body !== 'object' && options.headers['Content-Type'] !== 'application/json')
5049
promise = Promise.resolve(JSON.stringify(body));
5150
else if (typeof body !== 'string')
@@ -60,7 +59,7 @@ class ReactNativeBlobUtilFetchPolyfill {
6059
let progressHandler, uploadHandler, cancelHandler;
6160
let statefulPromise = promise
6261
.then((body) => {
63-
let task = ReactNativeBlobUtil.config(config)
62+
let task = RNconfig(config)
6463
.fetch(options.method, url, options.headers, body);
6564
if (progressHandler)
6665
task.progress(progressHandler);

0 commit comments

Comments
 (0)