Skip to content

Commit 3a5647a

Browse files
authored
Update article.md
Fixed typos / sentence structures
1 parent 3c37e1d commit 3a5647a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ openRequest.onupgradeneeded = function() {
5757
};
5858

5959
openRequest.onerror = function() {
60-
console.error("Error", openResult.error);
60+
console.error("Error", openRequest.error);
6161
};
6262

6363
openRequest.onsuccess = function() {
@@ -107,13 +107,13 @@ IndexedDB uses the [standard serialization algorithm](https://www.w3.org/TR/html
107107

108108
An example of object that can't be stored: an object with circular references. Such objects are not serializable. `JSON.stringify` also fails for such objects.
109109

110-
**There must be an unique `key` for every value in the store.**
110+
**There must be a unique `key` for every value in the store.**
111111

112112
A key must have a type one of: number, date, string, binary, or array. It's a unique object identifier: we can search/remove/update values by the key.
113113

114114
![](indexeddb-structure.png)
115115

116-
We can provide a key when we add an value to the store, similar to `localStorage`. That's good for storing primitive values. But when we store objects, IndexedDB allows to setup an object property as the key, that's much more convenient. Or we can auto-generate keys.
116+
We can provide a key when we add a value to the store, similar to `localStorage`. That's good for storing primitive values. But when we store objects, IndexedDB allows to setup an object property as the key, that's much more convenient. Or we can auto-generate keys.
117117

118118
The syntax to create an object store:
119119
```js
@@ -140,7 +140,7 @@ That's a technical limitation. Outside of the handler we'll be able to add/remov
140140

141141
To do an upgrade, there are two main ways:
142142
1. We can compare versions and run per-version operations.
143-
2. Or we can get a list of existing object stores as `db.objectStoreNames`. That object is a [DOMStringList](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#domstringlist), and it provides `contains(name)` method to check for the existance. And then we can do updates depending on what exists.
143+
2. Or we can get a list of existing object stores as `db.objectStoreNames`. That object is a [DOMStringList](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#domstringlist), and it provides `contains(name)` method to check for the existence. And then we can do updates depending on what exists.
144144

145145
Here's the demo of the second approach:
146146

@@ -190,7 +190,7 @@ db.transaction(store[, type]);
190190
- `readonly` -- can only read, the default.
191191
- `readwrite` -- can only read and write, but not modify object stores.
192192

193-
There'is also `versionchange` transaction type: such transactions can do everything, but we can't create them manually. IndexedDB automatically creates a `versionchange` transaction when opening the database, for `updateneeded` handler. That's why it's a single place where we can update the database structure, create/remove object stores.
193+
There's also `versionchange` transaction type: such transactions can do everything, but we can't create them manually. IndexedDB automatically creates a `versionchange` transaction when opening the database, for `updateneeded` handler. That's why it's a single place where we can update the database structure, create/remove object stores.
194194

195195
```smart header="What are transaction types for?"
196196
Performance is the reason why transactions need to be labeled either `readonly` and `readwrite`.
@@ -463,7 +463,7 @@ objectStore.createIndex(name, keyPath, [options]);
463463
- **`keyPath`** -- path to the object field that the index should track (we're going to search by that field),
464464
- **`option`** -- an optional object with properties:
465465
- **`unique`** -- if true, then there may be only one object in the store with the given value at the `keyPath`. The index will enforce that by generating an error if we try to add a duplicate.
466-
- **`multiEntry`** -- only used if there value on `keyPath` is an array. In that case, by default, the index will treat the whole array as the key. But if `multiEntry` is true, then the index will keep a list of store objects for each value in that array. So array members become index keys.
466+
- **`multiEntry`** -- only used if the value on `keyPath` is an array. In that case, by default, the index will treat the whole array as the key. But if `multiEntry` is true, then the index will keep a list of store objects for each value in that array. So array members become index keys.
467467

468468
In our example, we store books keyed by `id`.
469469

@@ -614,7 +614,7 @@ Whether there are more values matching the cursor or not -- `onsuccess` gets cal
614614

615615
In the example above the cursor was made for the object store.
616616

617-
But we also can make a cursor over an index. As we remember, indexes allow to search by an object field. Cursors over indexes to precisely the same as over object stores -- they save memory by returning one value at a timee.
617+
But we also can make a cursor over an index. As we remember, indexes allow to search by an object field. Cursors over indexes to precisely the same as over object stores -- they save memory by returning one value at a time.
618618

619619
For cursors over indexes, `cursor.key` is the index key (e.g. price), and we should use `cursor.primaryKey` property the object key:
620620

@@ -688,7 +688,7 @@ window.addEventListener('unhandledrejection', event => {
688688

689689
### "Inactive transaction" pitfall
690690

691-
A we know already, a transaction auto-commits as soon as the browser is done with the current code and microtasks. So if we put an *macrotask* like `fetch` in the middle of a transaction, then the transaction won't wait for it to finish. It just auto-commits. So the next request in it fails.
691+
As we already know, a transaction auto-commits as soon as the browser is done with the current code and microtasks. So if we put a *macrotask* like `fetch` in the middle of a transaction, then the transaction won't wait for it to finish. It just auto-commits. So the next request in it fails.
692692

693693
For a promise wrapper and `async/await` the situation is the same.
694694

@@ -715,7 +715,7 @@ The workaround is same as when working with native IndexedDB: either make a new
715715

716716
Internally, the wrapper performs a native IndexedDB request, adding `onerror/onsuccess` to it, and returns a promise that rejects/resolves with the result.
717717

718-
That works most fine of the time. The examples are at the lib page <https://github.com/jakearchibald/idb>.
718+
That works fine most of the time. The examples are at the lib page <https://github.com/jakearchibald/idb>.
719719

720720
In few rare cases, when we need the original `request` object, we can access it as `promise.request` property of the promise:
721721

0 commit comments

Comments
 (0)