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

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

url

Link for getting the patch.

on_success_actions

Actions in case of successful loading.

on_fail_actions

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

changes

Element changes. Required parameter. Each change contains id, the ID of the element to be replaced or removed, and items, the elements to be inserted. If items is not specified, the element is removed.

mode

Procedure for applying changes:
- partial — all possible changes are applied, and errors are reported (default value);
- transactional — if an error occurs while applying at least one change, no changes are applied.

on_applied_actions

Actions to perform after the changes are applied.

on_failed_actions

Actions to perform if an error occurs when applying changes in the transactional mode.

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 DivNetworkClient if it is configured, see Configuring the network stack. Your own loader, a DivDownloader implementation, is passed to DivConfiguration and takes priority.
  • iOS: patches are loaded by DivKitComponents. Your own loader, an implementation of the DivPatchProvider protocol, is passed in the patchProvider parameter.
  • Web: request parameters are set in the fetchInit parameter of the render function.

Learn more

You can discuss topics of interest in the DivKit user community in Telegram: https://t.me/divkit_community_en.

DivKit Repository