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
|
||||
*/
|
||||
componentWillMount() {
|
||||
super.componentWillMount();
|
||||
componentDidMount() {
|
||||
super.componentDidMount();
|
||||
|
||||
this._init.then(() => {
|
||||
// If a URL was explicitly specified to this React Component, then
|
||||
|
|
|
@ -93,8 +93,8 @@ export class App extends AbstractApp {
|
|||
* @returns {void}
|
||||
* @see https://facebook.github.io/react-native/docs/linking.html
|
||||
*/
|
||||
componentWillMount() {
|
||||
super.componentWillMount();
|
||||
componentDidMount() {
|
||||
super.componentDidMount();
|
||||
|
||||
Linking.addEventListener('url', this._onLinkingURL);
|
||||
}
|
||||
|
|
|
@ -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._init = this._initStorage()
|
||||
.catch(() => { /* BaseApp should always initialize! */ })
|
||||
.then(() => new Promise(resolve => {
|
||||
this.setState({
|
||||
store: this._createStore()
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the app.
|
||||
*
|
||||
* @inheritdoc
|
||||
*/
|
||||
componentWillMount() {
|
||||
this._init.then(() => this.state.store.dispatch(appWillMount(this)));
|
||||
}, resolve);
|
||||
}))
|
||||
.then(() => this.state.store.dispatch(appWillMount(this)))
|
||||
.catch(() => { /* BaseApp should always initialize! */ });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,8 +43,8 @@ export default class IncomingCallApp extends BaseApp<Props> {
|
|||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
componentWillMount() {
|
||||
super.componentWillMount();
|
||||
componentDidMount() {
|
||||
super.componentDidMount();
|
||||
|
||||
this._init.then(() => {
|
||||
const { dispatch } = this.state.store;
|
||||
|
|
Loading…
Reference in New Issue