Skip to content

indexedDB#695

Merged
leviding merged 10 commits intojavascript-tutorial:masterfrom
Maricaya:master
Apr 18, 2020
Merged

indexedDB#695
leviding merged 10 commits intojavascript-tutorial:masterfrom
Maricaya:master

Conversation

@Maricaya
Copy link
Copy Markdown
Contributor

@Maricaya Maricaya commented Mar 30, 2020

目标章节
6-data-storage/03-indexeddb

当前上游最新 commit
62299ed

本 PR 所做更改如下:

文件名 参考上游 commit 更改(理由)
article.md 7cd8f55 新增 indexedDB 中文翻译

注意,参考上游 commit 是指你所修改的文件,在英文仓库中同名文件的对应 commit,即你此次提交的修改的依据。如果本 PR 你只是提交一个文字或者语句优化,并非根据上游英文仓库的修改而提交的更新,则请填无。

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 30, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Member

@leviding leviding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我大概看了一下,有几个格式上的小问题,是代表性问题,麻烦全文检查修改下哈~

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
# IndexedDB

IndexedDB is a built-in database, much more powerful than `localStorage`.
indexedDB是一个内置的数据库,它比 `localStorage` 强大的多。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
indexedDB是一个内置的数据库,它比 `localStorage` 强大的多
indexedDB是一个内置的数据库,它比 `localStorage` 强大得多

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
- 键/值 储存:值(几乎)可以是任何类型,键有多种类型。
- 支撑事务的可靠性。
- 支持键范围查询、索引。
- `localStorage` 相比,它可以存储更多数据 。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-`localStorage` 相比,它可以存储更多数据
-`localStorage` 相比,它可以存储更多数据。

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
根据规范 <https://www.w3.org/TR/IndexedDB> 中的描述,IndexedDB 的本机接口是基于事件的。

We can also use `async/await` with the help of a promise-based wrapper, like <https://github.com/jakearchibald/idb>. That's pretty convenient, but the wrapper is not perfect, it can't replace events for all cases. So we'll start with events, and then, after we gain understanding of IndexedDb, we'll use the wrapper.
我们还可以在基于 promise 的包装器(wrapper),如 <https://github.com/jakearchibald/idb> 的帮助下使用 `async/await` 。这要方便的多,但是包装器并不完美,它并不能替代所有情况下的事件。因此,我们先练习事件(events),在理解 IndexedDB 之后,我们将使用包装器。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
我们还可以在基于 promise 的包装器(wrapper),如 <https://github.com/jakearchibald/idb> 的帮助下使用 `async/await` 。这要方便的多,但是包装器并不完美,它并不能替代所有情况下的事件。因此,我们先练习事件(events),在理解 IndexedDB 之后,我们将使用包装器。
我们还可以在基于 promise 的包装器(wrapper),如 <https://github.com/jakearchibald/idb> 的帮助下使用 `async/await`。这要方便的多,但是包装器并不完美,它并不能替代所有情况下的事件。因此,我们先练习事件(events),在理解 IndexedDB 之后,我们将使用包装器。

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
- `error`: opening failed.
- `upgradeneeded`: database is ready, but its version is outdated (see below).
调用之后,需要监听 `openRequest` 对象上的事件:
- `success`: 数据库准备就绪,`openRequest.result` 中有了一个数据库对象"Database Object",使用它进行进一步的调用。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `success` 数据库准备就绪,`openRequest.result` 中有了一个数据库对象"Database Object",使用它进行进一步的调用。
- `success`:数据库准备就绪,`openRequest.result` 中有了一个数据库对象 "Database Object",使用它进行进一步的调用。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为这里用了英文半角双引号,那就加空格。中文全角的不加。

Comment thread 6-data-storage/03-indexeddb/article.md Outdated

openRequest.onupgradeneeded = function() {
// the existing database version is less than 2 (or it doesn't exist)
// 现有的数据库版本小于2(或不存在)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 现有的数据库版本小于2(或不存在)
// 现有的数据库版本小于 2(或不存在)

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
```
基本有四个步骤:
1. 创建一个事务,在(1)表明要访问的所有存储。
2. 使用 `transaction.objectStore(name)` ,在(2)中获取存储对象。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. 使用 `transaction.objectStore(name)` ,在(2)中获取存储对象。
2. 使用 `transaction.objectStore(name)`,在(2)中获取存储对象。

@javascript-translate-bot
Copy link
Copy Markdown

Please make the requested changes. After it, add a comment "/done".
Then I'll ask for a new review 👻

@Maricaya
Copy link
Copy Markdown
Contributor Author

/done

Copy link
Copy Markdown
Member

@MartinsYong MartinsYong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

校对完成。不错的翻译,辛苦了~

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
# IndexedDB

IndexedDB is a built-in database, much more powerful than `localStorage`.
indexedDB 是一个内置的数据库,它比 `localStorage` 强大得多。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
indexedDB 是一个内置的数据库,它比 `localStorage` 强大得多。
IndexedDB 是一个内置的数据库,它比 `localStorage` 强大得多。

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
**IndexedDB has a built-in mechanism of "schema versioning", absent in server-side databases.**

Unlike server-side databases, IndexedDB is client-side, the data is stored in the browser, so we, developers, don't have direct access to it. But when we publish a new version of our app, we may need to update the database.
**IndexedDB 具有内建的“模式版本控制”机制,这在服务器端数据库中是不存在的。**
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**IndexedDB 具有内建的“模式版本控制”机制,这在服务器端数据库中是不存在的。**
**IndexedDB 具有内建的“模式(scheme)版本控制”机制,这在服务器端数据库中是不存在的。**

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
与服务器端数据库不同,IndexedDB 存在于客户端,数据存储在浏览器中。因此开发人员不能直接访问它。但当新版本的应用程序发布之后,我们可能需要更新数据库。

The event also triggers when the database did not exist yet, so we can perform initialization.
如果本地数据库版本低于 `open` 中指定的版本,会触发一个特殊事件 `upgradeneeded`。我们可以根据需要比较版本和升级数据结构。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
如果本地数据库版本低于 `open` 中指定的版本,会触发一个特殊事件 `upgradeneeded`我们可以根据需要比较版本和升级数据结构
如果本地数据库版本低于 `open` 中指定的版本,会触发一个特殊事件 `upgradeneeded`我们可以根据需要比较版本并升级数据结构

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
*/!*

// ...the db is ready, use it...
// ...数据库已经准备好,使用它...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ...数据库已经准备好,使用它...
// ……数据库已经准备好,请使用它……

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
```

**An object store can only be created/modified while updating the DB version, in `upgradeneeded` handler.**
**在 `upgradeneeded` 程序中,只有在创建数据库版本时,对象库被才能被 创建/修改。**
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**`upgradeneeded` 程序中,只有在创建数据库版本时,对象库被才能被 创建/修改。**
**`upgradeneeded` 处理程序中,只有在创建数据库版本时,对象库被才能被 创建/修改。**

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
- **`direction`** 是一个可选参数,使用顺序是:
- `"next"` —— 默认值,光标从有最小索引的记录向上移动。
- `"prev"` —— 相反的顺序:从有最大的索引的记录开始下降。
- `"nextunique"``"prevunique"` —— 同上,但是跳过键相同的记录 (仅适用于索引上的光标,例如,对于价格为5的书,仅返回第一本)。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `"nextunique"``"prevunique"` —— 同上,但是跳过键相同的记录 (仅适用于索引上的光标,例如,对于价格为5的书,仅返回第一本)。
- `"nextunique"``"prevunique"` —— 同上,但是跳过键相同的记录 (仅适用于索引上的光标,例如,对于价格为 5 的书,仅返回第一本)。

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
...report about the error...
let request = event.target; // IndexedDB 本机请求对象
let error = event.reason; // 未处理的错误对象,与 request.error 相同
// ...报告错误...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ...报告错误...
// ……报告错误……

Comment thread 6-data-storage/03-indexeddb/article.md Outdated

### "Inactive transaction" pitfall

### “非活跃交易”陷阱
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 非活跃交易”陷阱
### 非活跃事务”陷阱

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
The next `inventory.add` after `fetch` `(*)` fails with an "inactive transaction" error, because the transaction is already committed and closed at that time.
`fetch` `(*)` 后的下一个 `inventory.add` 失败,出现“非活动事务”错误,因为这时事务已经被提交并且关闭了。

解决方法与使用本机 IndexedDB 时相同:进行新事务,或者将事物分开。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
解决方法与使用本机 IndexedDB 时相同:进行新事务,或者将事物分开
解决方法与使用本机 IndexedDB 时相同:进行新事务,或者将事情分开

Comment thread 6-data-storage/03-indexeddb/article.md Outdated
let transaction = request.transaction; // 本地事务对象

// ...do some native IndexedDB voodoo...
// ...做些本地的 IndexedDB 的处理...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ...做些本地的 IndexedDB 的处理...
// ……做些本地的 IndexedDB 的处理……

@javascript-translate-bot
Copy link
Copy Markdown

Please make the requested changes. After it, add a comment "/done".
Then I'll ask for a new review 👻

@MartinsYong
Copy link
Copy Markdown
Member

还有冲突耶,顺便处理一下吧,谢谢~

@leviding
Copy link
Copy Markdown
Member

leviding commented Apr 6, 2020

还有冲突耶,顺便处理一下吧,谢谢~

@Maricaya 图片不翻译,目前是因为本 PR 翻译了图片,而上游 master 更新了导致错误。你把你对图片文件的修改撤销即可。

@Maricaya
Copy link
Copy Markdown
Contributor Author

Maricaya commented Apr 6, 2020

@MartinsYong @leviding 冲突已处理,谢谢各位的校验~

@Maricaya
Copy link
Copy Markdown
Contributor Author

Maricaya commented Apr 7, 2020

/done

@MartinsYong
Copy link
Copy Markdown
Member

咦,我的 change requests 你还没处理
@Maricaya

@Maricaya
Copy link
Copy Markdown
Contributor Author

@MartinsYong 现在都处理完成啦,重新看下吧

@Maricaya
Copy link
Copy Markdown
Contributor Author

/done

@leviding leviding merged commit f78b294 into javascript-tutorial:master Apr 18, 2020
@leviding leviding added DONE and removed needs +1 labels Apr 18, 2020
@leviding
Copy link
Copy Markdown
Member

辛苦啦两位!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants