@@ -13,6 +13,7 @@ import emptyObject from 'fbjs/lib/emptyObject';
1313import  invariant  from  'fbjs/lib/invariant' ; 
1414import  shallowEqual  from  'fbjs/lib/shallowEqual' ; 
1515import  checkPropTypes  from  'prop-types/checkPropTypes' ; 
16+ import  warning  from  'fbjs/lib/warning' ; 
1617
1718class  ReactShallowRenderer  { 
1819  static  createRenderer  =  function ( )  { 
@@ -73,7 +74,7 @@ class ReactShallowRenderer {
7374    this . _context  =  getMaskedContext ( element . type . contextTypes ,  context ) ; 
7475
7576    if  ( this . _instance )  { 
76-       this . _updateClassComponent ( element . type ,   element . props ,  this . _context ) ; 
77+       this . _updateClassComponent ( element ,  this . _context ) ; 
7778    }  else  { 
7879      if  ( shouldConstruct ( element . type ) )  { 
7980        this . _instance  =  new  element . type ( 
@@ -96,7 +97,7 @@ class ReactShallowRenderer {
9697          currentlyValidatingElement  =  null ; 
9798        } 
9899
99-         this . _mountClassComponent ( element . props ,  this . _context ) ; 
100+         this . _mountClassComponent ( element ,  this . _context ) ; 
100101      }  else  { 
101102        this . _rendered  =  element . type ( element . props ,  this . _context ) ; 
102103      } 
@@ -122,16 +123,31 @@ class ReactShallowRenderer {
122123    this . _instance  =  null ; 
123124  } 
124125
125-   _mountClassComponent ( props ,  context )  { 
126+   _mountClassComponent ( element ,  context )  { 
126127    this . _instance . context  =  context ; 
127-     this . _instance . props  =  props ; 
128+     this . _instance . props  =  element . props ; 
128129    this . _instance . state  =  this . _instance . state  ||  null ; 
129130    this . _instance . updater  =  this . _updater ; 
130131
131-     if  ( typeof  this . _instance . componentWillMount  ===  'function' )  { 
132+     if  ( 
133+       typeof  this . _instance . unsafe_componentWillMount  ===  'function'  || 
134+       typeof  this . _instance . componentWillMount  ===  'function' 
135+     )  { 
132136      const  beforeState  =  this . _newState ; 
133137
134-       this . _instance . componentWillMount ( ) ; 
138+       if  ( typeof  this . _instance . componentWillMount  ===  'function' )  { 
139+         if  ( __DEV__ )  { 
140+           warning ( 
141+             false , 
142+             '%s: componentWillMount() is deprecated and will be removed in the '  + 
143+               'next major version. Please use unsafe_componentWillMount() instead.' , 
144+             getName ( element . type ,  this . _instance ) , 
145+           ) ; 
146+         } 
147+         this . _instance . componentWillMount ( ) ; 
148+       }  else  { 
149+         this . _instance . unsafe_componentWillMount ( ) ; 
150+       } 
135151
136152      // setState may have been called during cWM 
137153      if  ( beforeState  !==  this . _newState )  { 
@@ -144,15 +160,28 @@ class ReactShallowRenderer {
144160    // because DOM refs are not available. 
145161  } 
146162
147-   _updateClassComponent ( type ,  props ,  context )  { 
163+   _updateClassComponent ( element ,  context )  { 
164+     const  { props,  type}  =  element ; 
165+ 
148166    const  oldState  =  this . _instance . state  ||  emptyObject ; 
149167    const  oldProps  =  this . _instance . props ; 
150168
151-     if  ( 
152-       oldProps  !==  props  && 
153-       typeof  this . _instance . componentWillReceiveProps  ===  'function' 
154-     )  { 
155-       this . _instance . componentWillReceiveProps ( props ,  context ) ; 
169+     if  ( oldProps  !==  props )  { 
170+       if  ( typeof  this . _instance . componentWillReceiveProps  ===  'function' )  { 
171+         if  ( __DEV__ )  { 
172+           warning ( 
173+             false , 
174+             '%s: componentWillReceiveProps() is deprecated and will be removed in the '  + 
175+               'next major version. Please use unsafe_componentWillReceiveProps() instead.' , 
176+             getName ( element . type ,  this . _instance ) , 
177+           ) ; 
178+         } 
179+         this . _instance . componentWillReceiveProps ( props ,  context ) ; 
180+       }  else  if  ( 
181+         typeof  this . _instance . unsafe_componentWillReceiveProps  ===  'function' 
182+       )  { 
183+         this . _instance . unsafe_componentWillReceiveProps ( props ,  context ) ; 
184+       } 
156185    } 
157186    // Read state after cWRP in case it calls setState 
158187    const  state  =  this . _newState  ||  oldState ; 
@@ -174,7 +203,20 @@ class ReactShallowRenderer {
174203
175204    if  ( shouldUpdate )  { 
176205      if  ( typeof  this . _instance . componentWillUpdate  ===  'function' )  { 
206+         if  ( __DEV__ )  { 
207+           warning ( 
208+             false , 
209+             '%s: componentWillUpdate() is deprecated and will be removed in the '  + 
210+               'next major version. Please use unsafe_componentWillUpdate() instead.' , 
211+             getName ( element . type ,  this . _instance ) , 
212+           ) ; 
213+         } 
214+ 
177215        this . _instance . componentWillUpdate ( props ,  state ,  context ) ; 
216+       }  else  if  ( 
217+         typeof  this . _instance . unsafe_componentWillUpdate  ===  'function' 
218+       )  { 
219+         this . _instance . unsafe_componentWillUpdate ( props ,  state ,  context ) ; 
178220      } 
179221    } 
180222
0 commit comments