ecmascript-2017

ECMAScript: Lexical Grammar vs Syntactic Grammar

陌路散爱 提交于 2019-12-10 11:53:35
问题 I am having some difficulties understanding the specific difference between Lexical Grammar and Syntactic Grammar in the ECMAScript 2017 specification. Excerpts from ECMAScript 2017 5.1.2 The Lexical and RegExp Grammars A lexical grammar for ECMAScript is given in clause 11. This grammar has as its terminal symbols Unicode code points that conform to the rules for SourceCharacter defined in 10.1. It defines a set of productions, starting from the goal symbol InputElementDiv,

Migrating from Generators to Async/Await

戏子无情 提交于 2019-12-10 03:24:18
问题 I just came to the painful realization that generator functions cannot be used with await. Only promises or async functions. My team built an entire application with all modules consisting of generator functions, with one call to the Co module from the main js file. Besides going though hundreds of generator function and changing them from function*(...){ to async function(...){ , how else can generators be made to work with async/await? Makes no sense because yield*/generators and async

Recursively calling an asynchronous API call

点点圈 提交于 2019-12-08 19:44:15
问题 I'm trying to fetch data from an API that only returns 1000 items per call, and I want to do this recursively until I have all the data. I don't know beforehand how many items there are in total, so after every call I have to check If the call was synchronous, I'd use something like this: function fetch(all, start) { const newData = getData(start, 1000); all = all.concat(newData); return (newData.length === 1000) ? fetch(all, all.length) : all; } However, the getData() call here is

Get firebase.auth().currentUser with async/await

此生再无相见时 提交于 2019-12-07 13:23:36
问题 I successfully check user's authentication state with onAuthStateChange observer and redirect user to the Dashboard page (react-native project). However, on the dashboard I already want to show some user specific data, e.g. enrolled programs/statistics. For that I need currentUser object to be initialised and populated, which takes some time (I need uid from there to get some data from Database). Thus, i'm looking for some way to wait until this process finishes successfully. What I'm trying

Await for asynchronous function results in undefined

主宰稳场 提交于 2019-12-07 13:08:51
问题 I'm having trouble with async/await with Node. When I try this: function Read_Json_File() { fs.readFile('import.json','utf-8',(err, data) => { if (err) throw err; json_data = JSON.parse(data); return json_data; }); } async function run_demo() { let get_json_file = await Read_Json_File(); console.log(get_json_file); } run_demo(); It returns undefined instead of the JSON from the file. Why doesn't it wait for the file reading to finish? 回答1: You're not returning anything from Read_Json_File ,

Selenium with async/await in JS, find and click on element

杀马特。学长 韩版系。学妹 提交于 2019-12-06 19:13:26
I'm trying to refactor my tests using Selenium webdriver and Mocha to ES7 with async/await functionality. I have got following piece of code: await loginPage.loginAsAdmin() /* THIS DOES NOT WORK */ //await layout.Elements.routePageButton().click() /* THIS DOES WORK */ let a = await layout.Elements.routePageButton() await a.click() I don't understand why the particular does not work - I get: TypeError: layout.Elements.routePageButton(...).click is not a function Function before click method returns webElement, as you can see: Layout: routePageButton: async () => await findVisibleElement('#route

Why does .catch() not catch reject() within Promise constructor within loop at an async function unless Error is passed?

浪子不回头ぞ 提交于 2019-12-06 08:05:07
问题 Given (async () => { const p = await new Promise((resolve, reject) => setTimeout(() => { reject(new Error(1)) }, Math.floor(Math.random() * 1000))); return p})() .then(data => console.log(data)) .catch(err => console.error(err)); the Error() is logged at .catch() If we extend the pattern to use a loop the Error is logged at .catch() const fn = async(res, ...props) => { for (let prop of props) res.push(await prop()) return res } const arr = [ () => new Promise((resolve, reject) => setTimeout((

Get firebase.auth().currentUser with async/await

北城余情 提交于 2019-12-06 05:17:50
I successfully check user's authentication state with onAuthStateChange observer and redirect user to the Dashboard page (react-native project). However, on the dashboard I already want to show some user specific data, e.g. enrolled programs/statistics. For that I need currentUser object to be initialised and populated, which takes some time (I need uid from there to get some data from Database). Thus, i'm looking for some way to wait until this process finishes successfully. What I'm trying to do it to use async/await syntax in componentDidMount, but the result returned is null. (Same syntax

Async/Await not working as expected with Promise.all and a .map function

 ̄綄美尐妖づ 提交于 2019-12-05 05:42:43
I have a slew of async functions I'm using and I'm having a weird issue. My code, working, looks like: async mainAsyncFunc (metadata) { let files = metadata.map(data => this.anotherAsyncFunc(data.url)); return Promise.all(files); } anotherAsyncFunc function looks like: async anotherAsyncFunc (url) { return await axios({ url, }).then(res => res.data) .catch(err => { throw err; }); } My issue comes when I try to append more data to what the first function ( mainAsyncFunc ) returns. My thoughts are to do that in the map , naturally, and when all is said and done, modified it looks like: async

Why `async/await` doesn't work in my case?

风流意气都作罢 提交于 2019-12-05 02:01:46
问题 I read about async/await , but I've a critical question. At first I explain an old example to show base of my question and then I ask my exact question. Everybody know it: console.log('1'); console.log('2'); console.log('3'); // Ex: 123 It is simple but in below case: console.log('1'); setTimeout(()=>{ console.log('2'); },0); console.log('3'); // Ex: 132 It is simple too, setTimeout function is asynchronous and JavaScript jump from it and after resolve run its function, so we see 2 after 1