mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
47e6e155b9
updated version to 20.0.1 fix demoapp_release_config fix demeapp_release_config (cherry-pick from e2647d8a317018b940da1390fd63f66461ac907b) Fix max sized of DivFrameLayout with match parent child (cherry-pick from 23fb83533a5e4aeb7f3e5ae1ad3831331bb2c7bc) Fix border drawing in animations (cherry-pick from 5c74b7c45d59566c6b0ffed5e007b9623f5e84a7) Cherry pickadd build config for demoapp release Check view is laid out before draw it to bitmap (cherry-pick from 8e610704677942792289bd1c0e58ddc0a0fd1887) Request layout after weight updating (cherry-pick from c6f488dd9b2c7f628de152672a73a95c98ce191d) added dns requirement into github task (cherry-pick from c6bcc5d6fdc7f1fa1ea2e09351c7a5ab622c4824) update changelog update changelog (cherry-pick from 7a50c5c8acc5288eb9123ef5e8d430d5148f0494) update api dump update div.api (cherry-pick from 0563c1635b4695e6a5c9cfa45d0be620056b2914) updated version to 20.0.0 (cherry-pick from 8894effabe2379433255ef389125c6bea46b74ae)
DivKit TypeScript JSON Buidler
What is this and what for
@divkitframework/jsonbuilder library provides type safe tools to generate DivKit JSON
Example
import { divCard, DivContainer, DivText, reference, rewritRefs, template, templateHelper } from '@divkitframework/jsonbuilder';
const templates = {
sampleBlock: new DivContainer({
items: [
template('header', {
text: reference('title')
}),
template('header', {
text: reference('subtitle')
}),
],
}),
header: new DivText({
font_size: 24,
}),
};
const tHelper = templateHelper(templates);
console.log(JSON.stringify(
divCard(rewriteRefs(templates), {
log_id: 'sample_card',
states: [
{
state_id: 0,
div: tHelper.sampleBlock({
title: "Some Title",
subtitle: "Some Subtitle",
}),
},
],
}
)));
In the result JSON.stringify(divCard(...)) will return JSON below:
{
"templates": {
"sampleBlock": {
"type": "container",
"items": [
{
"type": "header",
"$text": "title"
},
{
"type": "header",
"$text": "subtitle"
},
]
},
"header": {
"type": "text",
"font_size": 24
}
},
"card": {
"log_id": "sample_card",
"states": [
{
"state_id": 0,
"div": {
"type": "sampleBlock",
"title": "Some Title",
"subtitle": "Some Subtitle",
}
}
]
}
}
Typesafe templates with compile-time validation
You can use templateHelper helper function to achieve compile time template parameters validation. Type safety works only when you enable strictNullChecks in tsconfig.json
const block = template('header', {
title: 'Some Title'
});
// using templateHelper for checking template parameters at compile-time
const safeBlock = tHelper.header({
title: 'Some Title'
});
Validity guarantees
While developing cards you need to make sure that:
- Textual string are not empty;
- Urls of images, actions, etc are valid;
- Arrays are non-empty.
Documentation. Medium tutorial. Habr tutorial.
Telegram: News | English-speaking chat | Чат на русском.