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:
parent
d996d51653
commit
9215b1e8b2
|
@ -45,8 +45,8 @@ export class AbstractApp extends BaseApp<Props, *> {
|
||||||
*
|
*
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
componentWillMount() {
|
componentDidMount() {
|
||||||
super.componentWillMount();
|
super.componentDidMount();
|
||||||
|
|
||||||
this._init.then(() => {
|
this._init.then(() => {
|
||||||
// If a URL was explicitly specified to this React Component, then
|
// If a URL was explicitly specified to this React Component, then
|
||||||
|
|
|
@ -93,8 +93,8 @@ export class App extends AbstractApp {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
* @see https://facebook.github.io/react-native/docs/linking.html
|
* @see https://facebook.github.io/react-native/docs/linking.html
|
||||||
*/
|
*/
|
||||||
componentWillMount() {
|
componentDidMount() {
|
||||||
super.componentWillMount();
|
super.componentDidMount();
|
||||||
|
|
||||||
Linking.addEventListener('url', this._onLinkingURL);
|
Linking.addEventListener('url', this._onLinkingURL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,14 @@ export default class BaseApp extends Component<*, State> {
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
store: undefined
|
store: undefined
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the app.
|
||||||
|
*
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
componentDidMount() {
|
||||||
/**
|
/**
|
||||||
* Make the mobile {@code BaseApp} wait until the {@code AsyncStorage}
|
* Make the mobile {@code BaseApp} wait until the {@code AsyncStorage}
|
||||||
* implementation of {@code Storage} initializes fully.
|
* implementation of {@code Storage} initializes fully.
|
||||||
|
@ -68,22 +75,15 @@ export default class BaseApp extends Component<*, State> {
|
||||||
* @see {@link #_initStorage}
|
* @see {@link #_initStorage}
|
||||||
* @type {Promise}
|
* @type {Promise}
|
||||||
*/
|
*/
|
||||||
this._init
|
this._init = this._initStorage()
|
||||||
= this._initStorage()
|
.catch(() => { /* BaseApp should always initialize! */ })
|
||||||
.catch(() => { /* AbstractApp should always initialize! */ })
|
.then(() => new Promise(resolve => {
|
||||||
.then(() =>
|
|
||||||
this.setState({
|
this.setState({
|
||||||
store: this._createStore()
|
store: this._createStore()
|
||||||
}));
|
}, resolve);
|
||||||
}
|
}))
|
||||||
|
.then(() => this.state.store.dispatch(appWillMount(this)))
|
||||||
/**
|
.catch(() => { /* BaseApp should always initialize! */ });
|
||||||
* Initializes the app.
|
|
||||||
*
|
|
||||||
* @inheritdoc
|
|
||||||
*/
|
|
||||||
componentWillMount() {
|
|
||||||
this._init.then(() => this.state.store.dispatch(appWillMount(this)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,8 +43,8 @@ export default class IncomingCallApp extends BaseApp<Props> {
|
||||||
*
|
*
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
componentWillMount() {
|
componentDidMount() {
|
||||||
super.componentWillMount();
|
super.componentDidMount();
|
||||||
|
|
||||||
this._init.then(() => {
|
this._init.then(() => {
|
||||||
const { dispatch } = this.state.store;
|
const { dispatch } = this.state.store;
|
||||||
|
|
Loading…
Reference in New Issue