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:
Родитель
90938d6053
Коммит
74f56bd557
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче