mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 18:25:06 +00:00
Make access to SourceCode Native Extension lazy
Reviewed By: fromcelticpark Differential Revision: D6987478 fbshipit-source-id: 6d600131239be34480bd1c5a0ca84b4fab360386
This commit is contained in:
parent
def789cd7e
commit
c73242938c
@ -17,11 +17,26 @@ const AssetSourceResolver = require('AssetSourceResolver');
|
||||
import type { ResolvedAssetSource } from 'AssetSourceResolver';
|
||||
|
||||
let _customSourceTransformer, _serverURL, _scriptURL;
|
||||
|
||||
let _sourceCodeScriptURL: ?string;
|
||||
function getSourceCodeScriptURL(): ?string {
|
||||
if (_sourceCodeScriptURL) {
|
||||
return _sourceCodeScriptURL;
|
||||
}
|
||||
|
||||
let sourceCode = global.nativeExtensions && global.nativeExtensions.SourceCode;
|
||||
if (!sourceCode) {
|
||||
const NativeModules = require('NativeModules');
|
||||
sourceCode = NativeModules && NativeModules.SourceCode;
|
||||
}
|
||||
_sourceCodeScriptURL = sourceCode.scriptURL;
|
||||
return _sourceCodeScriptURL;
|
||||
}
|
||||
|
||||
function getDevServerURL(): ?string {
|
||||
if (_serverURL === undefined) {
|
||||
const match = _sourceCodeScriptURL && _sourceCodeScriptURL.match(/^https?:\/\/.*?\//);
|
||||
const sourceCodeScriptURL = getSourceCodeScriptURL();
|
||||
const match = sourceCodeScriptURL && sourceCodeScriptURL.match(/^https?:\/\/.*?\//);
|
||||
if (match) {
|
||||
// jsBundle was loaded from network
|
||||
_serverURL = match[0];
|
||||
@ -51,7 +66,7 @@ function _coerceLocalScriptURL(scriptURL: ?string): ?string {
|
||||
|
||||
function getScriptURL(): ?string {
|
||||
if (_scriptURL === undefined) {
|
||||
_scriptURL = _coerceLocalScriptURL(_sourceCodeScriptURL);
|
||||
_scriptURL = _coerceLocalScriptURL(getSourceCodeScriptURL());
|
||||
}
|
||||
return _scriptURL;
|
||||
}
|
||||
@ -87,13 +102,6 @@ function resolveAssetSource(source: any): ?ResolvedAssetSource {
|
||||
return resolver.defaultAsset();
|
||||
}
|
||||
|
||||
let sourceCode = global.nativeExtensions && global.nativeExtensions.SourceCode;
|
||||
if (!sourceCode) {
|
||||
const NativeModules = require('NativeModules');
|
||||
sourceCode = NativeModules && NativeModules.SourceCode;
|
||||
}
|
||||
_sourceCodeScriptURL = sourceCode && sourceCode.scriptURL;
|
||||
|
||||
module.exports = resolveAssetSource;
|
||||
module.exports.pickScale = AssetSourceResolver.pickScale;
|
||||
module.exports.setCustomSourceTransformer = setCustomSourceTransformer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user