Created
August 16, 2017 14:29
-
-
Save qleguennec/d117189c987db26252517d859a588b4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!_.has(this.cache, page)) { | |
const requestWithAttributes = | |
_.reduce( | |
_.toPairs(requestAttributes) | |
, (acc, [a, b]) => acc + a + "=" + b + "&" | |
, request(userInfo) + "?"); | |
fetch(requestWithAttributes) | |
.then((resp) => resp.json()) | |
.then((result) => this.cache[page] = result); | |
console.log(this.cache); | |
/* Object | |
* 0 : Array[30]*/ | |
console.log(this.cache[page]); | |
/* undefined*/ | |
} |
avec async / await :
const maFonction = async () => {
const resp = await fetch('./data')
const result = await resp.json()
this.cache[page] = result
console.log(this.cache);
console.log(this.cache[page]);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
le code est asynchrone dans ton fetch :