mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e8037cb942
Summary: Part of #24875, adds a spec for Networking. Since `sendRequest` methods are different for both platforms, I had to create 2 spec files as Flow would merge their definitions even when I added `Platform.OS` check ## Changelog [General] [Added] - TM spec for Networking Pull Request resolved: https://github.com/facebook/react-native/pull/24892 Reviewed By: RSNara Differential Revision: D15543067 Pulled By: fkgozali fbshipit-source-id: 2b91114dfa45e7899bbb139656a30a6fd52e31db
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const NativeEventEmitter = require('../EventEmitter/NativeEventEmitter');
|
|
import NativeNetworkingIOS from './NativeNetworkingIOS';
|
|
const convertRequestBody = require('./convertRequestBody');
|
|
|
|
import type {RequestBody} from './convertRequestBody';
|
|
|
|
import type {NativeResponseType} from './XMLHttpRequest';
|
|
|
|
class RCTNetworking extends NativeEventEmitter {
|
|
constructor() {
|
|
super(NativeNetworkingIOS);
|
|
}
|
|
|
|
sendRequest(
|
|
method: string,
|
|
trackingName: string,
|
|
url: string,
|
|
headers: Object,
|
|
data: RequestBody,
|
|
responseType: NativeResponseType,
|
|
incrementalUpdates: boolean,
|
|
timeout: number,
|
|
callback: (requestId: number) => mixed,
|
|
withCredentials: boolean,
|
|
) {
|
|
const body = convertRequestBody(data);
|
|
NativeNetworkingIOS.sendRequest(
|
|
{
|
|
method,
|
|
url,
|
|
data: {...body, trackingName},
|
|
headers,
|
|
responseType,
|
|
incrementalUpdates,
|
|
timeout,
|
|
withCredentials,
|
|
},
|
|
callback,
|
|
);
|
|
}
|
|
|
|
abortRequest(requestId: number) {
|
|
NativeNetworkingIOS.abortRequest(requestId);
|
|
}
|
|
|
|
clearCookies(callback: (result: boolean) => mixed) {
|
|
NativeNetworkingIOS.clearCookies(callback);
|
|
}
|
|
}
|
|
|
|
module.exports = new RCTNetworking();
|