UNPKG

1.03 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow strict-local
8 * @format
9 */
10'use strict';
11
12/**
13 * Set up SegmentFetcher.
14 * You can use this module directly, or just require InitializeCore.
15 */
16global.__fetchSegment = function(
17 segmentId: number,
18 options: {|+otaBuildNumber: ?string|},
19 callback: (?Error) => void,
20) {
21 const {SegmentFetcher} = require('NativeModules');
22 if (!SegmentFetcher) {
23 throw new Error(
24 'SegmentFetcher is missing. Please ensure that it is ' +
25 'included as a NativeModule.',
26 );
27 }
28
29 SegmentFetcher.fetchSegment(
30 segmentId,
31 options,
32 (errorObject: ?{message: string, code: string}) => {
33 if (errorObject) {
34 const error = new Error(errorObject.message);
35 (error: any).code = errorObject.code; // flowlint-line unclear-type: off
36 callback(error);
37 }
38
39 callback(null);
40 },
41 );
42};