Ver código fonte

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.
master
Leonard Kim 7 anos atrás
pai
commit
9215b1e8b2

+ 2
- 2
react/features/app/components/AbstractApp.js Ver arquivo

@@ -45,8 +45,8 @@ export class AbstractApp extends BaseApp<Props, *> {
45 45
      *
46 46
      * @inheritdoc
47 47
      */
48
-    componentWillMount() {
49
-        super.componentWillMount();
48
+    componentDidMount() {
49
+        super.componentDidMount();
50 50
 
51 51
         this._init.then(() => {
52 52
             // If a URL was explicitly specified to this React Component, then

+ 2
- 2
react/features/app/components/App.native.js Ver arquivo

@@ -93,8 +93,8 @@ export class App extends AbstractApp {
93 93
      * @returns {void}
94 94
      * @see https://facebook.github.io/react-native/docs/linking.html
95 95
      */
96
-    componentWillMount() {
97
-        super.componentWillMount();
96
+    componentDidMount() {
97
+        super.componentDidMount();
98 98
 
99 99
         Linking.addEventListener('url', this._onLinkingURL);
100 100
     }

+ 16
- 16
react/features/base/app/components/BaseApp.js Ver arquivo

@@ -59,7 +59,14 @@ export default class BaseApp extends Component<*, State> {
59 59
             // $FlowFixMe
60 60
             store: undefined
61 61
         };
62
+    }
62 63
 
64
+    /**
65
+     * Initializes the app.
66
+     *
67
+     * @inheritdoc
68
+     */
69
+    componentDidMount() {
63 70
         /**
64 71
          * Make the mobile {@code BaseApp} wait until the {@code AsyncStorage}
65 72
          * implementation of {@code Storage} initializes fully.
@@ -68,22 +75,15 @@ export default class BaseApp extends Component<*, State> {
68 75
          * @see {@link #_initStorage}
69 76
          * @type {Promise}
70 77
          */
71
-        this._init
72
-            = this._initStorage()
73
-                .catch(() => { /* AbstractApp should always initialize! */ })
74
-                .then(() =>
75
-                    this.setState({
76
-                        store: this._createStore()
77
-                    }));
78
-    }
79
-
80
-    /**
81
-     * Initializes the app.
82
-     *
83
-     * @inheritdoc
84
-     */
85
-    componentWillMount() {
86
-        this._init.then(() => this.state.store.dispatch(appWillMount(this)));
78
+        this._init = this._initStorage()
79
+            .catch(() => { /* BaseApp should always initialize! */ })
80
+            .then(() => new Promise(resolve => {
81
+                this.setState({
82
+                    store: this._createStore()
83
+                }, resolve);
84
+            }))
85
+            .then(() => this.state.store.dispatch(appWillMount(this)))
86
+            .catch(() => { /* BaseApp should always initialize! */ });
87 87
     }
88 88
 
89 89
     /**

+ 2
- 2
react/features/mobile/incoming-call/components/IncomingCallApp.js Ver arquivo

@@ -43,8 +43,8 @@ export default class IncomingCallApp extends BaseApp<Props> {
43 43
      *
44 44
      * @returns {void}
45 45
      */
46
-    componentWillMount() {
47
-        super.componentWillMount();
46
+    componentDidMount() {
47
+        super.componentDidMount();
48 48
 
49 49
         this._init.then(() => {
50 50
             const { dispatch } = this.state.store;

Carregando…
Cancelar
Salvar