11import { Component } from 'react' ;
22import isEqual from 'shallowequal' ;
33
4- function shallowCompare ( instance , nextProps , nextState ) {
5- return ! isEqual ( instance . props , nextProps ) || ! isEqual ( instance . state , nextState ) ;
6- }
7-
84export default class AsyncComponent extends Component {
95 constructor ( props , context ) {
106 super ( props , context ) ;
@@ -14,6 +10,7 @@ export default class AsyncComponent extends Component {
1410 this . forceUpdateHelper = this . forceUpdate . bind ( this ) ;
1511 this . isComponentMounted = false ;
1612 this . asyncFunction = props . co ;
13+ this . getVariables = props . getVariables || ( ( ) => props . variables || { } ) ;
1714 }
1815
1916 forceUpdate ( variables = this . state . variables , props = this . props ) {
@@ -52,14 +49,15 @@ export default class AsyncComponent extends Component {
5249 return this . forceUpdate ( ) ;
5350 }
5451
55- componentWillReceiveProps ( nextProps ) {
56- if ( shallowCompare ( this , nextProps ) ) {
52+ componentWillReceiveProps ( nextProps , nextContext ) {
53+ if ( ! isEqual ( this , nextProps ) ) {
5754 if ( this . iterator && this . iterator . return ) {
5855 this . iterator . return ( ) ;
5956 }
6057
6158 if ( this . isComponentMounted ) {
62- this . forceUpdate ( this . state . variables , nextProps ) ;
59+ const variables = this . getVariables ( nextProps , nextContext ) ;
60+ this . forceUpdate ( variables , nextProps ) ;
6361 }
6462 }
6563 }
0 commit comments