diff --git a/docs/API.en.epub b/docs/API.en.epub index 41fd252..3a3d334 100644 Binary files a/docs/API.en.epub and b/docs/API.en.epub differ diff --git a/docs/API.en.html b/docs/API.en.html index 203b023..1e1a22c 100644 --- a/docs/API.en.html +++ b/docs/API.en.html @@ -6639,7 +6639,7 @@ api.subscribe(
If you have read the previous chapters thoroughly, the solution to these problems should be obvious. We need to abstract from the fact of loading data and reformulate the issue in high-level terms. We have a shared resource: the space on the screen. Only one offer can be displayed at a time. This means that every actor needing lasting access to the panel must explicitly obtain it. This entails two conclusions:
offerFullViewLocked
m and not isDataLoading
.offerFullViewLocked
, and not isDataLoading
.Composer
must control this flag, not the offer panel itself (additionally, because preparing data for displaying in the panel is Composer
's responsibility).class SearchBoxComposer {
@@ -6669,9 +6669,9 @@ api.subscribe(
selectOffer (offer) {
let lock;
try {
- // Trying to catpture the
+ // Trying to capture the
// `offerFullView` resource
- lock = this.acquireLock(
+ lock = await this.acquireLock(
'offerFullView', '10s'
);
let fullData = await api
@@ -6696,7 +6696,7 @@ api.subscribe(
NB: the second argument to the acquireLock
function is the lock's lifespan (10 seconds, in our case). This implies that the lock will be automatically released after this timeout has passed (which is useful in case we have forgotten to catch an exception or set a timeout for a data load request), thus unblocking the UI.
With this approach, we can implement not only locks, but also various scenarios to flexibly manage them. Let's add data regarding the acquirer in the lock function:
-lock = this.acquireLock(
+lock = await this.acquireLock(
'offerFullView', '10s', {
// Who is trying to acquire a lock
// and for what reason
@@ -6714,12 +6714,12 @@ api.subscribe(
// of the lock
return false;
}
-})
+});
Additionally, we might add a handler to react to losing control — for example, to cancel the request for data if it is no longer needed:
lock.events.on('lost', () => {
this.cancelFullOfferDataLoad();
-})
+});
The shared resource access control partner aligns well with the “model” pattern: actors can acquire read and/or write locks for specific data fields (or groups of fields) of the model.
NB: we could have addressed the data load problem differently:
diff --git a/docs/API.en.pdf b/docs/API.en.pdf
index 78526be..173f244 100644
Binary files a/docs/API.en.pdf and b/docs/API.en.pdf differ
diff --git a/docs/API.ru.epub b/docs/API.ru.epub
index 7726bca..23ffe46 100644
Binary files a/docs/API.ru.epub and b/docs/API.ru.epub differ
diff --git a/docs/API.ru.html b/docs/API.ru.html
index fc44a26..44b13e1 100644
--- a/docs/API.ru.html
+++ b/docs/API.ru.html
@@ -6699,7 +6699,7 @@ api.subscribe(
try {
// Пытаемся захватить ресурс
// `offerFullView`
- lock = this.acquireLock(
+ lock = await this.acquireLock(
'offerFullView', '10s'
);
let fullData = await api
@@ -6724,7 +6724,7 @@ api.subscribe(
NB: вторым параметром в acquireLock
мы передали максимальное время жизни блокировки — 10 секунд. Если в течение этого времени блокировка не снята (например, в случае, если мы забыли обработать какое-то исключение или выставить таймаут на запрос к серверу), она будет отменена автоматически, и интерфейс будет разблокирован.
В таком подходе мы можем реализовать не только блокировки, но и различные сценарии, которые позволяют нам более гибко ими управлять. Добавим в функцию захвата ресурса дополнительные данные о целях захвата:
-lock = this.acquireLock(
+lock = await this.acquireLock(
'offerFullView', '10s', {
// Добавляем описание,
// кто и зачем пытается
@@ -6742,12 +6742,12 @@ api.subscribe(
// Иначе запрещаем перехват
return false;
}
-})
+});
Дополнительно мы можем ввести и обработку потери контроля ресурса — например, отменить загрузку данных, которые больше не нужны.
lock.events.on('lost', () => {
this.cancelFullOfferDataLoad();
-})
+});
Паттерн контроля разделяемых ресурсов также хорошо сочетается с паттерном «модель»: акторы могут захватывать доступ на чтение и/или изменение свойств или групп свойств модели.
NB: мы могли бы решить проблему подгрузки данных иначе:
diff --git a/docs/API.ru.pdf b/docs/API.ru.pdf
index adaac66..2007502 100644
Binary files a/docs/API.ru.pdf and b/docs/API.ru.pdf differ
diff --git a/src/en/clean-copy/06-[Work in Progress] Section V. SDKs & UI Libraries/07.md b/src/en/clean-copy/06-[Work in Progress] Section V. SDKs & UI Libraries/07.md
index 2dd276b..73c56b0 100644
--- a/src/en/clean-copy/06-[Work in Progress] Section V. SDKs & UI Libraries/07.md
+++ b/src/en/clean-copy/06-[Work in Progress] Section V. SDKs & UI Libraries/07.md
@@ -97,9 +97,9 @@ class SearchBoxComposer {
selectOffer (offer) {
let lock;
try {
- // Trying to catpture the
+ // Trying to capture the
// `offerFullView` resource
- lock = this.acquireLock(
+ lock = await this.acquireLock(
'offerFullView', '10s'
);
let fullData = await api
@@ -128,7 +128,7 @@ class SearchBoxComposer {
With this approach, we can implement not only locks, but also various scenarios to flexibly manage them. Let's add data regarding the acquirer in the lock function:
```typescript
-lock = this.acquireLock(
+lock = await this.acquireLock(
'offerFullView', '10s', {
// Who is trying to acquire a lock
// and for what reason
diff --git a/src/ru/clean-copy/06-[В разработке] Раздел V. SDK и UI-библиотеки/07.md b/src/ru/clean-copy/06-[В разработке] Раздел V. SDK и UI-библиотеки/07.md
index 44f6853..b24cfd3 100644
--- a/src/ru/clean-copy/06-[В разработке] Раздел V. SDK и UI-библиотеки/07.md
+++ b/src/ru/clean-copy/06-[В разработке] Раздел V. SDK и UI-библиотеки/07.md
@@ -99,7 +99,7 @@ class SearchBoxComposer {
try {
// Пытаемся захватить ресурс
// `offerFullView`
- lock = this.acquireLock(
+ lock = await this.acquireLock(
'offerFullView', '10s'
);
let fullData = await api
@@ -128,7 +128,7 @@ class SearchBoxComposer {
В таком подходе мы можем реализовать не только блокировки, но и различные сценарии, которые позволяют нам более гибко ими управлять. Добавим в функцию захвата ресурса дополнительные данные о целях захвата:
```typescript
-lock = this.acquireLock(
+lock = await this.acquireLock(
'offerFullView', '10s', {
// Добавляем описание,
// кто и зачем пытается