You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2018/07/18 13:58:37 UTC

[couchdb-nano] 07/08: modernise JS in migration guide

This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit 166c23c252048da4d4e8b7c76156698d2049db13
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 14:50:10 2018 +0100

    modernise JS in migration guide
---
 migration_6_to_7.md | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/migration_6_to_7.md b/migration_6_to_7.md
index 84aaee7..33d1f92 100644
--- a/migration_6_to_7.md
+++ b/migration_6_to_7.md
@@ -16,9 +16,8 @@ In Nano 7:
 
 ```js
 // Nano 7
-var db = nano.db.use('mydb')
-var x = db.get('mydoc') 
-// x is a Promise
+const db = nano.db.use('mydb')
+const x = await db.get('mydoc') 
 ```
 
 If you are not using the streaming properties of Nano 6's return value, you may not need to change any code at all. This document outlines the areas that have changed and what you need to do to your code.
@@ -53,7 +52,7 @@ If you have code in the *callback* style, then Nano 7 will still work:
 
 ```js
 // Nano 7
-db.get('mydoc', function(err, data)  {
+db.get('mydoc', (err, data) => {
   console.log(err, data)
 })
 ```
@@ -84,9 +83,9 @@ db.get('mydoc').then((doc) => {
 In a JavaScript [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function), the code becomes even neater with the [await operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await):
 
 ```js
-var doc = await db.get('mydoc')
+let doc = await db.get('mydoc')
 doc.last_updated = new Date().getTime()
-var response = await db.insert(doc)
+let response = await db.insert(doc)
 ```
 
 You may find that using the Promise style of coding helps you create neater, simpler code, but pre-existing code that uses the callback style should still work.