Skip to content

Commit ffd8e03

Browse files
authoredApr 18, 2021
typos? easier reading - review pls
1 parent 870a88c commit ffd8e03

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
 

‎6-data-storage/03-indexeddb/article.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ openRequest.onupgradeneeded = function(event) {
9595
};
9696
```
9797

98-
Please note: as our current version is `2`, `onupgradeneeded` handler has a code branch for version `0`, suitable for users that are accessing for the first time and have no database, and also for version `1`, for upgrades.
98+
Please note: as our current version is `2`, the `onupgradeneeded` handler has a code branch for version `0`, suitable for users that are accessing for the first time and have no database, and also for version `1`, for upgrades.
9999

100100
And then, only if `onupgradeneeded` handler finishes without errors, `openRequest.onsuccess` triggers, and the database is considered successfully opened.
101101

@@ -156,7 +156,7 @@ openRequest.onsuccess = function() {
156156
openRequest.onblocked = function() {
157157
// this event shouldn't trigger if we handle onversionchange correctly
158158

159-
// it means that there's another open connection to same database
159+
// it means that there's another open connection to the same database
160160
// and it wasn't closed after db.onversionchange triggered for it
161161
};
162162
*/!*
@@ -171,7 +171,7 @@ We can handle things more gracefully in `db.onversionchange`, prompt the visitor
171171

172172
Or, an alternative approach would be to not close the database in `db.onversionchange`, but instead use the `onblocked` handler (in the new tab) to alert the visitor, tell him that the newer version can't be loaded until they close other tabs.
173173

174-
These update collisions happen rarely, but we should at least have some handling for them, at least `onblocked` handler, to prevent our script from dying silently.
174+
These update collisions happen rarely, but we should at least have some handling for them, at least an `onblocked` handler, to prevent our script from dying silently.
175175

176176
## Object store
177177

@@ -189,7 +189,7 @@ An example of an object that can't be stored: an object with circular references
189189

190190
**There must be a unique `key` for every value in the store.**
191191

192-
A key must be one of the these types - number, date, string, binary, or array. It's a unique identifier, so we can search/remove/update values by the key.
192+
A key must be one of these types - number, date, string, binary, or array. It's a unique identifier, so we can search/remove/update values by the key.
193193

194194
![](indexeddb-structure.svg)
195195

@@ -253,7 +253,7 @@ db.deleteObjectStore('books')
253253

254254
The term "transaction" is generic, used in many kinds of databases.
255255

256-
A transaction is a group operations, that should either all succeed or all fail.
256+
A transaction is a group of operations, that should either all succeed or all fail.
257257

258258
For instance, when a person buys something, we need to:
259259
1. Subtract the money from their account.
@@ -347,9 +347,9 @@ Usually, we can assume that a transaction commits when all its requests are comp
347347

348348
So, in the example above no special call is needed to finish the transaction.
349349

350-
Transactions auto-commit principle has an important side effect. We can't insert an async operation like `fetch`, `setTimeout` in the middle of transaction. IndexedDB will not keep the transaction waiting till these are done.
350+
Transactions auto-commit principle has an important side effect. We can't insert an async operation like `fetch`, `setTimeout` in the middle of a transaction. IndexedDB will not keep the transaction waiting till these are done.
351351

352-
In the code below, `request2` in line `(*)` fails, because the transaction is already committed, and can't make any request in it:
352+
In the code below, `request2` in the line `(*)` fails, because the transaction is already committed, and can't make any request in it:
353353

354354
```js
355355
let request1 = books.add(book);
@@ -370,7 +370,7 @@ That's because `fetch` is an asynchronous operation, a macrotask. Transactions a
370370

371371
Authors of IndexedDB spec believe that transactions should be short-lived. Mostly for performance reasons.
372372

373-
Notably, `readwrite` transactions "lock" the stores for writing. So if one part of application initiated `readwrite` on `books` object store, then another part that wants to do the same has to wait: the new transaction "hangs" till the first one is done. That can lead to strange delays if transactions take a long time.
373+
Notably, `readwrite` transactions "lock" the stores for writing. So if one part of the application initiated `readwrite` on `books` object store, then another part that wants to do the same has to wait: the new transaction "hangs" till the first one is done. That can lead to strange delays if transactions take a long time.
374374

375375
So, what to do?
376376

@@ -792,7 +792,7 @@ await inventory.add({ id: 'js', price: 10, created: new Date() }); // Error
792792

793793
The next `inventory.add` after `fetch` `(*)` fails with an "inactive transaction" error, because the transaction is already committed and closed at that time.
794794

795-
The workaround is same as when working with native IndexedDB: either make a new transaction or just split things apart.
795+
The workaround is the same as when working with native IndexedDB: either make a new transaction or just split things apart.
796796
1. Prepare the data and fetch all that's needed first.
797797
2. Then save in the database.
798798

0 commit comments

Comments
 (0)
Failed to load comments.