1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

async/await

This commit is contained in:
Laurent Cozic 2017-06-15 22:17:56 +01:00
parent f0aa00945e
commit 601ec12ee8
3 changed files with 50 additions and 29 deletions

View File

@ -1,3 +1,4 @@
{ {
"presets": ["env", "react"] "presets": ["env", "react"],
"plugins": ["syntax-async-functions","transform-runtime"]
} }

View File

@ -1,4 +1,6 @@
require('source-map-support').install(); require('source-map-support').install();
//require("babel-polyfill");
require('babel-plugin-transform-runtime');
import { FileApi } from 'src/file-api.js'; import { FileApi } from 'src/file-api.js';
import { FileApiDriverLocal } from 'src/file-api-driver-local.js'; import { FileApiDriverLocal } from 'src/file-api-driver-local.js';
@ -46,34 +48,32 @@ function createRemoteItems() {
}); });
} }
function createLocalItems() { async function createLocalItems() {
return Folder.save({ title: "folder1" }).then((f) => { let folder = await Folder.save({ title: "folder1" });
return Promise.all([ await Note.save({ title: "un", parent_id: folder.id });
Note.save({ title: "un", parent_id: f.id }), await Note.save({ title: "deux", parent_id: folder.id });
Note.save({ title: "deux", parent_id: f.id }),
Note.save({ title: "trois", parent_id: f.id }), folder = await Folder.save({ title: "folder2" });
Note.save({ title: "quatre", parent_id: f.id }), await Note.save({ title: "trois", parent_id: folder.id });
]);
}).then(() => { // let folder = await Folder.save({ title: "folder1" });
return Folder.save({ title: "folder2" }) // await Note.save({ title: "un", parent_id: folder.id });
}).then((f) => { // await Note.save({ title: "deux", parent_id: folder.id });
return Promise.all([ // await Note.save({ title: "trois", parent_id: folder.id });
Note.save({ title: "cinq", parent_id: f.id }), // await Note.save({ title: "quatre", parent_id: folder.id });
]);
}).then(() => { // folder = await Folder.save({ title: "folder2" });
return Folder.save({ title: "folder3" }) // await Note.save({ title: "cinq", parent_id: folder.id });
}).then(() => {
return Folder.save({ title: "folder4" }) // folder = await Folder.save({ title: "folder3" });
}).then((f) => {
return Promise.all([ // folder = await Folder.save({ title: "folder4" });
Note.save({ title: "six", parent_id: f.id }), // await Note.save({ title: "six", parent_id: folder.id });
Note.save({ title: "sept", parent_id: f.id }), // await Note.save({ title: "sept", parent_id: folder.id });
Note.save({ title: "huit", parent_id: f.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(() => { db.open({ name: '/home/laurent/Temp/test-sync.sqlite3' }).then(() => {
BaseModel.db_ = db; BaseModel.db_ = db;
//return clearDatabase(); //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();

View File

@ -4,6 +4,8 @@
"private": true, "private": true,
"dependencies": { "dependencies": {
"app-module-path": "^2.2.0", "app-module-path": "^2.2.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.1.4",
"form-data": "^2.1.4", "form-data": "^2.1.4",
"fs-extra": "^3.0.1", "fs-extra": "^3.0.1",
"jssha": "^2.3.0", "jssha": "^2.3.0",
@ -12,6 +14,7 @@
"moment-timezone": "^0.5.13", "moment-timezone": "^0.5.13",
"node-fetch": "^1.7.1", "node-fetch": "^1.7.1",
"promise": "^7.1.1", "promise": "^7.1.1",
"query-string": "4.3.4",
"react": "16.0.0-alpha.6", "react": "16.0.0-alpha.6",
"sax": "^1.2.2", "sax": "^1.2.2",
"source-map-support": "^0.4.15", "source-map-support": "^0.4.15",
@ -26,8 +29,10 @@
"babel-cli": "^6.24.1", "babel-cli": "^6.24.1",
"babel-preset-env": "^1.5.1", "babel-preset-env": "^1.5.1",
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"jasmine": "^2.6.0", "babel-plugin-syntax-async-functions": "^6.1.4",
"query-string": "4.3.4" "babel-plugin-transform-regenerator": "^6.1.4",
"babel-preset-es2015": "^6.1.4",
"jasmine": "^2.6.0"
}, },
"scripts": { "scripts": {
"babelbuild": "babel app -d build", "babelbuild": "babel app -d build",