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
- checkIfCacheDataOutdated
- getCacheData
- shouldRefetch
- shouldUpdateCache
- toObject
- from
- getDevServerURL
- getFileSystemURL
- getRemoteURL
Constructors
constructor
• new Script(scriptId
, caller
, locator
, cache?
)
Constructs new representation of a script.
internal
Parameters
Name | Type | Default value | Description |
---|---|---|---|
scriptId | string | undefined | - |
caller | undefined | string | undefined | - |
locator | NormalizedScriptLocator | undefined | Normalized locator data. |
cache | boolean | true | Flag 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
Name | Type | Description |
---|---|---|
cachedData | Pick <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
Name | Type |
---|---|
body | undefined | string |
headers | undefined | Record <string , string > |
method | "GET" | "POST" |
query | undefined | string |
url | string |
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
Name | Type | Description |
---|---|---|
cachedData | Pick <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
Name | Type | Description |
---|---|---|
cachedData | Pick <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
Name | Type |
---|---|
cache | boolean |
caller | undefined | string |
locator | NormalizedScriptLocator |
scriptId | string |
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
Name | Type | Description |
---|---|---|
key | Object | - |
key.caller? | string | - |
key.scriptId | string | - |
locator | ScriptLocator | Non-normalized locator data. |
fetch | boolean | Initial flag for whether script should be fetched or not. |
Returns
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
Name | Type | Description |
---|---|---|
scriptId | string | Id of the script. |
Returns
fn
▸ (webpackContext
): string
Parameters
Name | Type |
---|---|
webpackContext | WebpackContext |
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
Name | Type | Description |
---|---|---|
scriptId | string | Id of the script. |
Returns
fn
▸ (webpackContext
): string
Parameters
Name | Type |
---|---|
webpackContext | WebpackContext |
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
Name | Type | Description |
---|---|---|
url | string | A URL to remote location where the script is stored. |
options | Object | Additional options. |
options.excludeExtension? | boolean | - |
Returns
string
| (webpackContext
: WebpackContext
) => string