mirror of
https://github.com/twirl/The-API-Book.git
synced 2025-05-31 22:09:37 +02:00
typos
This commit is contained in:
parent
25f163013f
commit
a067bf28d4
@ -63,7 +63,7 @@ However, this code is flawed for several reasons:
|
||||
* If an exception is thrown while loading the data, the `endDataLoad` event will never happen and the interface will remain blocked indefinitely.
|
||||
|
||||
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:
|
||||
* The access flag must have an explicit name, such as `offerFullViewLocked`m and not `isDataLoading`.
|
||||
* The access flag must have an explicit name, such as `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).
|
||||
|
||||
```typescript
|
||||
@ -149,7 +149,7 @@ lock.events.on('tryAcquire', (actor) => {
|
||||
// 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:
|
||||
@ -157,7 +157,7 @@ Additionally, we might add a handler to react to losing control — for example,
|
||||
```typescript
|
||||
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.
|
||||
|
@ -149,7 +149,7 @@ lock.events.on('tryAcquire', (actor) => {
|
||||
// Иначе запрещаем перехват
|
||||
return false;
|
||||
}
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
Дополнительно мы можем ввести и обработку потери контроля ресурса — например, отменить загрузку данных, которые больше не нужны.
|
||||
@ -157,7 +157,7 @@ lock.events.on('tryAcquire', (actor) => {
|
||||
```typescript
|
||||
lock.events.on('lost', () => {
|
||||
this.cancelFullOfferDataLoad();
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
Паттерн контроля разделяемых ресурсов также хорошо сочетается с паттерном «модель»: акторы могут захватывать доступ на чтение и/или изменение свойств или групп свойств модели.
|
||||
|
Loading…
x
Reference in New Issue
Block a user