Loading more data and patches
A card can be updated partially, without loading it again. The download action requests a patch — a description of changes — from the server and applies it to the card elements.
The download action
To load more data in the form of a patch and update the current element, specify the download action:
div-action://download?url=<patch_url>
|
Parameter |
Description |
|
|
URL to get the patch. |
The typed download action can also specify what to do after loading:
{
"log_id": "load_more",
"typed": {
"type": "download",
"url": "https://example.com/patch.json",
"on_success_actions": [
{
"log_id": "loaded",
"url": "div-action://set_variable?name=is_loaded&value=true"
}
],
"on_fail_actions": [
{
"log_id": "load_failed",
"url": "div-action://set_variable?name=has_error&value=true"
}
]
}
}
|
Parameter |
Description |
|
|
Link for getting the patch. |
|
|
Actions in case of successful loading. |
|
|
Actions in case of unsuccessful loading, if the host reported it or the waiting time expired. |
For an action in the url format, the same actions are set in the download_callbacks field.
Patch format
Response format:
{
"patch": {
// data in patch format
},
"templates": {
// templates that can be used in the patch section
}
}
The patch section is described by the patch object:
|
Parameter |
Description |
|
|
Element changes. Required parameter. Each change contains |
|
|
Procedure for applying changes: |
|
|
Actions to perform after the changes are applied. |
|
|
Actions to perform if an error occurs when applying changes in the |
Example: replacing an element
{
"patch": {
"changes": [
{
"id": "placeholder",
"items": [
{
"type": "text",
"text": "Loaded text"
}
]
}
]
}
}
The element with the placeholder ID is replaced with the text from items.
Loading patches on platforms
- Android: patches are loaded through
DivNetworkClientif it is configured, see Configuring the network stack. Your own loader, aDivDownloaderimplementation, is passed toDivConfigurationand takes priority. - iOS: patches are loaded by
DivKitComponents. Your own loader, an implementation of theDivPatchProviderprotocol, is passed in thepatchProviderparameter. - Web: request parameters are set in the
fetchInitparameter of therenderfunction.
Learn more
You can discuss topics of interest in the DivKit user community in Telegram: https://t.me/divkit_community_en.