Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c13f21d

Browse files
authored
Fixed onupgradeneeded handling
`openRequest.result.version` in `onupgradeneeded` is not the current DB version. It is the requested version, equal to `event.newVersion`. `event.oldVersion` contains the current version.
1 parent a9925f4 commit c13f21d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ libs:
55

66
# IndexedDB
77

8-
IndexedDB is a database, that is built into browser, much more powerful than `localStorage`.
8+
IndexedDB is a database that is built into browser, much more powerful than `localStorage`.
99

1010
- Stores almost any kind of values by keys, multiple key types.
1111
- Supports transactions for reliability.
@@ -75,10 +75,10 @@ We can open it with version `2` and perform the upgrade like this:
7575
```js
7676
let openRequest = indexedDB.open("store", *!*2*/!*);
7777

78-
openRequest.onupgradeneeded = function() {
78+
openRequest.onupgradeneeded = function(event) {
7979
// the existing database version is less than 2 (or it doesn't exist)
8080
let db = openRequest.result;
81-
switch(db.version) { // existing db version
81+
switch(event.oldVersion) { // existing db version
8282
case 0:
8383
// version 0 means that the client had no database
8484
// perform initialization

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /