浏览代码

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 年前
父节点
当前提交
9215b1e8b2

+ 2
- 2
react/features/app/components/AbstractApp.js 查看文件

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

+ 2
- 2
react/features/app/components/App.native.js 查看文件

93
      * @returns {void}
93
      * @returns {void}
94
      * @see https://facebook.github.io/react-native/docs/linking.html
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
         Linking.addEventListener('url', this._onLinkingURL);
99
         Linking.addEventListener('url', this._onLinkingURL);
100
     }
100
     }

+ 16
- 16
react/features/base/app/components/BaseApp.js 查看文件

59
             // $FlowFixMe
59
             // $FlowFixMe
60
             store: undefined
60
             store: undefined
61
         };
61
         };
62
+    }
62
 
63
 
64
+    /**
65
+     * Initializes the app.
66
+     *
67
+     * @inheritdoc
68
+     */
69
+    componentDidMount() {
63
         /**
70
         /**
64
          * Make the mobile {@code BaseApp} wait until the {@code AsyncStorage}
71
          * Make the mobile {@code BaseApp} wait until the {@code AsyncStorage}
65
          * implementation of {@code Storage} initializes fully.
72
          * implementation of {@code Storage} initializes fully.
68
          * @see {@link #_initStorage}
75
          * @see {@link #_initStorage}
69
          * @type {Promise}
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 查看文件

43
      *
43
      *
44
      * @returns {void}
44
      * @returns {void}
45
      */
45
      */
46
-    componentWillMount() {
47
-        super.componentWillMount();
46
+    componentDidMount() {
47
+        super.componentDidMount();
48
 
48
 
49
         this._init.then(() => {
49
         this._init.then(() => {
50
             const { dispatch } = this.state.store;
50
             const { dispatch } = this.state.store;

正在加载...
取消
保存