Created
January 31, 2018 20:50
-
-
Save andeplane/517a73caf1886eab20d6aa94a5db2f38 to your computer and use it in GitHub Desktop.
async await fetch
This file contains 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
import test from './test.txt' | |
class A { | |
constructor() { } | |
async loadFile(filename) { | |
let data = await (await fetch(filename)) | |
return data | |
} | |
} | |
class B extends A { | |
constructor() { | |
super() | |
this.contents = '' | |
} | |
async loadFile(filename) { | |
let data = await super.loadFile(filename) | |
data.text().then( text => { | |
console.log('Text: ', text) | |
this.parse(text) | |
}).catch( error => { | |
console.log('Error: ', error) | |
}) | |
} | |
parse (data) { | |
this.contents = data | |
console.log('Parsing data: ', data) | |
} | |
} | |
let b = new B() | |
b.loadFile(test).then( () => { | |
console.log('Got data now: ', b.contents) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment