[Async] Enable async/await and update UIExplorer and tests

Summary:
- Enables async/await in .babelrc and transformer.js
- Adds regenerator to package.json. Users still need to explicitly require the regenerator runtime -- this is so that you only pay for what you use.
- Update AsyncStorage examples in UIExplorer to use async/await
- Update promise tests in UIExplorer to use async/await in addition to the promise API

Closes https://github.com/facebook/react-native/pull/1765
Github Author: James Ide <ide@jameside.com>
This commit is contained in:
James Ide
2015-08-04 05:23:31 -07:00
parent 18452940f0
commit 47e1d1aef8
7 changed files with 68 additions and 28 deletions

View File

@@ -17,13 +17,18 @@ var PromiseTest = React.createClass({
shouldResolve: false,
shouldReject: false,
shouldSucceedAsync: false,
shouldThrowAsync: false,
componentDidMount() {
Promise.all([
this.testShouldResolve(),
this.testShouldReject(),
this.testShouldSucceedAsync(),
this.testShouldThrowAsync(),
]).then(() => RCTTestModule.markTestPassed(
this.shouldResolve && this.shouldReject
this.shouldResolve && this.shouldReject &&
this.shouldSucceedAsync && this.shouldThrowAsync
));
},
@@ -41,6 +46,24 @@ var PromiseTest = React.createClass({
.catch(() => this.shouldReject = true);
},
async testShouldSucceedAsync() {
try {
await RCTTestModule.shouldResolve();
this.shouldSucceedAsync = true;
} catch (e) {
this.shouldSucceedAsync = false;
}
},
async testShouldThrowAsync() {
try {
await RCTTestModule.shouldReject();
this.shouldThrowAsync = false;
} catch (e) {
this.shouldThrowAsync = true;
}
},
render() {
return <React.View />;
}