Add method to get a segment path without injecting it in the VM

Reviewed By: cpojer

Differential Revision: D15575463

fbshipit-source-id: 0b481c48f02353e0d15e0dec6162850a0e2140e9
This commit is contained in:
Rubén Norte 2019-05-31 02:26:37 -07:00 коммит произвёл Facebook Github Bot
Родитель 90938d6053
Коммит 74f56bd557
2 изменённых файлов: 49 добавлений и 3 удалений

Просмотреть файл

@ -18,6 +18,11 @@ export interface Spec extends TurboModule {
options: Object, // flowlint-line unclear-type: off
callback: (error: ?Object) => void, // flowlint-line unclear-type: off
) => void;
+getSegment?: (
segmentId: number,
options: Object, // flowlint-line unclear-type: off
callback: (error: ?Object, path: ?string) => void, // flowlint-line unclear-type: off
) => void;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SegmentFetcher');

Просмотреть файл

@ -9,13 +9,20 @@
*/
'use strict';
export type FetchSegmentFunction = typeof __fetchSegment;
export type GetSegmentFunction = typeof __getSegment;
/**
* Set up SegmentFetcher.
* You can use this module directly, or just require InitializeCore.
*/
global.__fetchSegment = function(
function __fetchSegment(
segmentId: number,
options: {|+otaBuildNumber: ?string|},
options: {|
+otaBuildNumber: ?string,
+requestedModuleName?: ?string,
|},
callback: (?Error) => void,
) {
const SegmentFetcher = require('./SegmentFetcher/NativeSegmentFetcher')
@ -33,4 +40,38 @@ global.__fetchSegment = function(
callback(null);
},
);
};
}
global.__fetchSegment = __fetchSegment;
function __getSegment(
segmentId: number,
options: {|
+otaBuildNumber: ?string,
+requestedModuleName?: ?string,
|},
callback: (?Error, ?string) => void,
) {
const SegmentFetcher = require('./SegmentFetcher/NativeSegmentFetcher')
.default;
if (!SegmentFetcher.getSegment) {
throw new Error('SegmentFetcher.getSegment must be defined');
}
SegmentFetcher.getSegment(
segmentId,
options,
(errorObject: ?{message: string, code: string}, path: ?string) => {
if (errorObject) {
const error = new Error(errorObject.message);
(error: any).code = errorObject.code; // flowlint-line unclear-type: off
callback(error);
}
callback(null, path);
},
);
}
global.__getSegment = __getSegment;