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.
• new Script(scriptId, caller, locator, cache?)
Constructs new representation of a script.
internal
| 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, trueby default. | 
packages/repack/src/modules/ScriptManager/Script.ts:131
• Readonly cache: boolean = true
• Readonly caller: undefined | string
• Readonly locator: NormalizedScriptLocator
• Readonly scriptId: string
▪ Static DEFAULT_TIMEOUT: number = 30000
packages/repack/src/modules/ScriptManager/Script.ts:20
▸ checkIfCacheDataOutdated(cachedData): boolean
Check if previous cached data is the same as the new one.
internal
| Name | Type | Description | 
|---|---|---|
| cachedData | Pick<NormalizedScriptLocator,"method"|"url"|"query"|"headers"|"body"> | Cached data for the same script. | 
boolean
packages/repack/src/modules/ScriptManager/Script.ts:186
▸ getCacheData(): Object
Get object to store in cache.
internal
Object
| Name | Type | 
|---|---|
| body | undefined|string | 
| headers | undefined|Record<string,string> | 
| method | "GET"|"POST" | 
| query | undefined|string | 
| url | string | 
packages/repack/src/modules/ScriptManager/Script.ts:208
▸ shouldRefetch(cachedData): boolean
Check if the script should be fetched again or reused, based on previous cached data.
internal
| Name | Type | Description | 
|---|---|---|
| cachedData | Pick<NormalizedScriptLocator,"method"|"url"|"query"|"headers"|"body"> | Cached data for the same script. | 
boolean
packages/repack/src/modules/ScriptManager/Script.ts:166
▸ shouldUpdateCache(cachedData): boolean
Check if the script was already cached and cache should be updated with new data.
internal
| Name | Type | Description | 
|---|---|---|
| cachedData | Pick<NormalizedScriptLocator,"method"|"url"|"query"|"headers"|"body"> | Cached data for the same script. | 
boolean
packages/repack/src/modules/ScriptManager/Script.ts:145
▸ toObject(): Object
Object
| Name | Type | 
|---|---|
| cache | boolean | 
| caller | undefined|string | 
| locator | NormalizedScriptLocator | 
| scriptId | string | 
packages/repack/src/modules/ScriptManager/Script.ts:218
▸ Static from(key, locator, fetch): Script
Create new instance of Script from non-normalized script locator data.
internal
| 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. | 
packages/repack/src/modules/ScriptManager/Script.ts:70
▸ Static getDevServerURL(scriptId): (webpackContext: WebpackContext) => string
Get URL of a script hosted on development server.
| Name | Type | Description | 
|---|---|---|
| scriptId | string | Id of the script. | 
fn
▸ (webpackContext): string
| Name | Type | 
|---|---|
| webpackContext | WebpackContext | 
string
packages/repack/src/modules/ScriptManager/Script.ts:27
▸ Static getFileSystemURL(scriptId): (webpackContext: WebpackContext) => string
Get URL of a script stored on filesystem on the target mobile device.
| Name | Type | Description | 
|---|---|---|
| scriptId | string | Id of the script. | 
fn
▸ (webpackContext): string
| Name | Type | 
|---|---|
| webpackContext | WebpackContext | 
string
packages/repack/src/modules/ScriptManager/Script.ts:37
▸ 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.
| Name | Type | Description | 
|---|---|---|
| url | string | A URL to remote location where the script is stored. | 
| options | Object | Additional options. | 
| options.excludeExtension? | boolean | - | 
string | (webpackContext: WebpackContext) => string