ref(app): move initialization into componentDidMount

componentWillMount is a deprecated lifecycle method;
componentDidMount should be used to kick off things
like ajax. In the case of the _App hierarchy, a promise
chain is used to perform initialization, and it is
first started in the constructor by initializing
storage. However, by the time storage is initialized,
resolving the first promise, _App has already mounted.
So, move it all to the componentDidMount lifecycle.
This commit is contained in:
Leonard Kim
2019-01-01 15:50:11 -08:00
committed by Saúl Ibarra Corretgé
parent d996d51653
commit 9215b1e8b2
4 changed files with 22 additions and 22 deletions

View File

@@ -59,7 +59,14 @@ export default class BaseApp extends Component<*, State> {
// $FlowFixMe
store: undefined
};
}
/**
* Initializes the app.
*
* @inheritdoc
*/
componentDidMount() {
/**
* Make the mobile {@code BaseApp} wait until the {@code AsyncStorage}
* implementation of {@code Storage} initializes fully.
@@ -68,22 +75,15 @@ export default class BaseApp extends Component<*, State> {
* @see {@link #_initStorage}
* @type {Promise}
*/
this._init
= this._initStorage()
.catch(() => { /* AbstractApp should always initialize! */ })
.then(() =>
this.setState({
store: this._createStore()
}));
}
/**
* Initializes the app.
*
* @inheritdoc
*/
componentWillMount() {
this._init.then(() => this.state.store.dispatch(appWillMount(this)));
this._init = this._initStorage()
.catch(() => { /* BaseApp should always initialize! */ })
.then(() => new Promise(resolve => {
this.setState({
store: this._createStore()
}, resolve);
}))
.then(() => this.state.store.dispatch(appWillMount(this)))
.catch(() => { /* BaseApp should always initialize! */ });
}
/**