diff --git a/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js b/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js new file mode 100644 index 00000000000..b27db043e70 --- /dev/null +++ b/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js @@ -0,0 +1,23 @@ +/** + * 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. + * + * @flow strict-local + * @format + */ +'use strict'; + +import type {TurboModule} from 'RCTExport'; +import * as TurboModuleRegistry from 'TurboModuleRegistry'; + +export interface Spec extends TurboModule { + +fetchSegment: ( + segmentId: number, + options: Object, // flowlint-line unclear-type: off + callback: (error: ?Object) => void, // flowlint-line unclear-type: off + ) => void; +} + +export default TurboModuleRegistry.getEnforcing('SegmentFetcher'); diff --git a/Libraries/Core/setUpSegmentFetcher.js b/Libraries/Core/setUpSegmentFetcher.js index 440caf380f3..ba2635fff2e 100644 --- a/Libraries/Core/setUpSegmentFetcher.js +++ b/Libraries/Core/setUpSegmentFetcher.js @@ -18,14 +18,7 @@ global.__fetchSegment = function( options: {|+otaBuildNumber: ?string|}, callback: (?Error) => void, ) { - const {SegmentFetcher} = require('NativeModules'); - if (!SegmentFetcher) { - throw new Error( - 'SegmentFetcher is missing. Please ensure that it is ' + - 'included as a NativeModule.', - ); - } - + const SegmentFetcher = require('NativeSegmentFetcher').default; SegmentFetcher.fetchSegment( segmentId, options,