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?): Script

Constructs new representation of a script.

Parameters

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

Returns

Script

Defined in

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

Properties

cache

Readonly cache: boolean = true

Flag whether use cache or not, true by default.

Defined in

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


caller

Readonly caller: undefined | string

Defined in

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


locator

Readonly locator: NormalizedScriptLocator

Normalized locator data.

Defined in

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


scriptId

Readonly scriptId: string

Defined in

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


DEFAULT_TIMEOUT

Static DEFAULT_TIMEOUT: number = 30000

Defined in

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

Methods

checkIfCacheDataOutdated

checkIfCacheDataOutdated(cachedData): boolean

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

Parameters

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

Returns

boolean

Defined in

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


getCacheData

getCacheData(): Object

Get object to store in cache.

Returns

Object

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

Defined in

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


shouldRefetch

shouldRefetch(cachedData): boolean

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

Parameters

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

Returns

boolean

Defined in

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


shouldUpdateCache

shouldUpdateCache(cachedData): boolean

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

Parameters

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

Returns

boolean

Defined in

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


toObject

toObject(): Object

Returns

Object

NameType
cacheboolean
callerundefined | string
locatorNormalizedScriptLocator
scriptIdstring

Defined in

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


from

from(key, locator, fetch): Script

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

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:68


getDevServerURL

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:25


getFileSystemURL

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:35


getRemoteURL

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:49