Skip to main content
Version: 3x

Class: Script

Representation of a Script to load and execute, used by ScriptManager.

When adding resolvers to ScriptManager in ScriptManager.shared.addResolver(...), you can use Script.getDevServerURL(...), Script.getFileSystemURL(...) or Script.getRemoteURL(...) to create a url for the script.

Other methods are designed for internal use only.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Script(scriptId, caller, locator, cache?)

Constructs new representation of a script.

internal

Parameters

NameTypeDefault valueDescription
scriptIdstringundefined-
callerundefined | stringundefined-
locatorNormalizedScriptLocatorundefinedNormalized locator data.
cachebooleantrueFlag whether use cache or not, true by default.

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:131

Properties

cache

Readonly cache: boolean = true


caller

Readonly caller: undefined | string


locator

Readonly locator: NormalizedScriptLocator


scriptId

Readonly scriptId: string


DEFAULT_TIMEOUT

Static DEFAULT_TIMEOUT: number = 30000

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:20

Methods

checkIfCacheDataOutdated

checkIfCacheDataOutdated(cachedData): boolean

Check if previous cached data is the same as the new one.

internal

Parameters

NameTypeDescription
cachedDataPick<NormalizedScriptLocator, "method" | "url" | "query" | "headers" | "body">Cached data for the same script.

Returns

boolean

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:186


getCacheData

getCacheData(): Object

Get object to store in cache.

internal

Returns

Object

NameType
bodyundefined | string
headersundefined | Record<string, string>
method"GET" | "POST"
queryundefined | string
urlstring

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:208


shouldRefetch

shouldRefetch(cachedData): boolean

Check if the script should be fetched again or reused, based on previous cached data.

internal

Parameters

NameTypeDescription
cachedDataPick<NormalizedScriptLocator, "method" | "url" | "query" | "headers" | "body">Cached data for the same script.

Returns

boolean

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:166


shouldUpdateCache

shouldUpdateCache(cachedData): boolean

Check if the script was already cached and cache should be updated with new data.

internal

Parameters

NameTypeDescription
cachedDataPick<NormalizedScriptLocator, "method" | "url" | "query" | "headers" | "body">Cached data for the same script.

Returns

boolean

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:145


toObject

toObject(): Object

Returns

Object

NameType
cacheboolean
callerundefined | string
locatorNormalizedScriptLocator
scriptIdstring

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:218


from

Static from(key, locator, fetch): Script

Create new instance of Script from non-normalized script locator data.

internal

Parameters

NameTypeDescription
keyObject-
key.caller?string-
key.scriptIdstring-
locatorScriptLocatorNon-normalized locator data.
fetchbooleanInitial flag for whether script should be fetched or not.

Returns

Script

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:70


getDevServerURL

Static getDevServerURL(scriptId): (webpackContext: WebpackContext) => string

Get URL of a script hosted on development server.

Parameters

NameTypeDescription
scriptIdstringId of the script.

Returns

fn

▸ (webpackContext): string

Parameters
NameType
webpackContextWebpackContext
Returns

string

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:27


getFileSystemURL

Static getFileSystemURL(scriptId): (webpackContext: WebpackContext) => string

Get URL of a script stored on filesystem on the target mobile device.

Parameters

NameTypeDescription
scriptIdstringId of the script.

Returns

fn

▸ (webpackContext): string

Parameters
NameType
webpackContextWebpackContext
Returns

string

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:37


getRemoteURL

Static getRemoteURL(url, options?): string | (webpackContext: WebpackContext) => string

Get URL of a script hosted on a remote server.

By default .chunk.bundle extension will be added to the URL. If your script has different extension, you should pass { excludeExtension: true } as 2nd argument.

Parameters

NameTypeDescription
urlstringA URL to remote location where the script is stored.
optionsObjectAdditional options.
options.excludeExtension?boolean-

Returns

string | (webpackContext: WebpackContext) => string

Defined in

packages/repack/src/modules/ScriptManager/Script.ts:51