From 601ec12ee8119bfba476b5c50392d5630e010325 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 15 Jun 2017 22:17:56 +0100 Subject: [PATCH] async/await --- CliClient/.babelrc | 3 +- CliClient/app/cmd.js | 67 ++++++++++++++++++++++++++---------------- CliClient/package.json | 9 ++++-- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/CliClient/.babelrc b/CliClient/.babelrc index 51a07ce22..69163caed 100644 --- a/CliClient/.babelrc +++ b/CliClient/.babelrc @@ -1,3 +1,4 @@ { - "presets": ["env", "react"] + "presets": ["env", "react"], + "plugins": ["syntax-async-functions","transform-runtime"] } \ No newline at end of file diff --git a/CliClient/app/cmd.js b/CliClient/app/cmd.js index c6cd8e2a4..535ef34ab 100644 --- a/CliClient/app/cmd.js +++ b/CliClient/app/cmd.js @@ -1,4 +1,6 @@ require('source-map-support').install(); +//require("babel-polyfill"); +require('babel-plugin-transform-runtime'); import { FileApi } from 'src/file-api.js'; import { FileApiDriverLocal } from 'src/file-api-driver-local.js'; @@ -46,34 +48,32 @@ function createRemoteItems() { }); } -function createLocalItems() { - return Folder.save({ title: "folder1" }).then((f) => { - return Promise.all([ - Note.save({ title: "un", parent_id: f.id }), - Note.save({ title: "deux", parent_id: f.id }), - Note.save({ title: "trois", parent_id: f.id }), - Note.save({ title: "quatre", parent_id: f.id }), - ]); - }).then(() => { - return Folder.save({ title: "folder2" }) - }).then((f) => { - return Promise.all([ - Note.save({ title: "cinq", parent_id: f.id }), - ]); - }).then(() => { - return Folder.save({ title: "folder3" }) - }).then(() => { - return Folder.save({ title: "folder4" }) - }).then((f) => { - return Promise.all([ - Note.save({ title: "six", parent_id: f.id }), - Note.save({ title: "sept", parent_id: f.id }), - Note.save({ title: "huit", parent_id: f.id }), - ]); - }); +async function createLocalItems() { + let folder = await Folder.save({ title: "folder1" }); + await Note.save({ title: "un", parent_id: folder.id }); + await Note.save({ title: "deux", parent_id: folder.id }); + + folder = await Folder.save({ title: "folder2" }); + await Note.save({ title: "trois", parent_id: folder.id }); + + // let folder = await Folder.save({ title: "folder1" }); + // await Note.save({ title: "un", parent_id: folder.id }); + // await Note.save({ title: "deux", parent_id: folder.id }); + // await Note.save({ title: "trois", parent_id: folder.id }); + // await Note.save({ title: "quatre", parent_id: folder.id }); + + // folder = await Folder.save({ title: "folder2" }); + // await Note.save({ title: "cinq", parent_id: folder.id }); + + // folder = await Folder.save({ title: "folder3" }); + + // folder = await Folder.save({ title: "folder4" }); + // await Note.save({ title: "six", parent_id: folder.id }); + // await Note.save({ title: "sept", parent_id: folder.id }); + // await Note.save({ title: "huit", parent_id: folder.id }); } -db.setDebugEnabled(true); +db.setDebugEnabled(!true); db.open({ name: '/home/laurent/Temp/test-sync.sqlite3' }).then(() => { BaseModel.db_ = db; //return clearDatabase(); @@ -87,6 +87,21 @@ db.open({ name: '/home/laurent/Temp/test-sync.sqlite3' }).then(() => { +// function testingProm() { +// return new Promise((resolve, reject) => { +// setTimeout(() => { +// resolve('mavaler'); +// }, 2000); +// }); +// } + +// async function doSomething() { +// let val = await testingProm(); +// console.info(val); +// } + +// doSomething(); + diff --git a/CliClient/package.json b/CliClient/package.json index bd5886c77..c2614550b 100644 --- a/CliClient/package.json +++ b/CliClient/package.json @@ -4,6 +4,8 @@ "private": true, "dependencies": { "app-module-path": "^2.2.0", + "babel-plugin-transform-runtime": "^6.23.0", + "babel-polyfill": "^6.1.4", "form-data": "^2.1.4", "fs-extra": "^3.0.1", "jssha": "^2.3.0", @@ -12,6 +14,7 @@ "moment-timezone": "^0.5.13", "node-fetch": "^1.7.1", "promise": "^7.1.1", + "query-string": "4.3.4", "react": "16.0.0-alpha.6", "sax": "^1.2.2", "source-map-support": "^0.4.15", @@ -26,8 +29,10 @@ "babel-cli": "^6.24.1", "babel-preset-env": "^1.5.1", "babel-preset-react": "^6.24.1", - "jasmine": "^2.6.0", - "query-string": "4.3.4" + "babel-plugin-syntax-async-functions": "^6.1.4", + "babel-plugin-transform-regenerator": "^6.1.4", + "babel-preset-es2015": "^6.1.4", + "jasmine": "^2.6.0" }, "scripts": { "babelbuild": "babel app -d build",