@@ -57,11 +57,44 @@ const StyledTransition = styled(ReactTransitionGroup)({
5757 transformStyle : 'flat'
5858} ) ;
5959
60- // TODO(540): Refactor to non-deprecated lifecycle methods.
61- // https://github.com/FormidableLabs/spectacle/issues/540
62- // - componentWillMount
63- // - componentWillReceiveProps
64- // eslint-disable-next-line react/no-deprecated
60+ function buildSlideReference ( props ) {
61+ const slideReference = [ ] ;
62+ Children . toArray ( props . children ) . forEach ( ( child , rootIndex ) => {
63+ if ( child . type === Magic ) {
64+ Children . toArray ( child . props . children ) . forEach ( ( setSlide , magicIndex ) => {
65+ const reference = {
66+ id : setSlide . props . id || slideReference . length ,
67+ magicIndex,
68+ rootIndex
69+ } ;
70+ slideReference . push ( reference ) ;
71+ } ) ;
72+ } else if ( ! child . props . hasSlideChildren ) {
73+ const reference = {
74+ id : child . props . id || slideReference . length ,
75+ rootIndex
76+ } ;
77+ if ( child . props . goTo ) {
78+ reference . goTo = child . props . goTo ;
79+ }
80+ slideReference . push ( reference ) ;
81+ } else {
82+ child . props . children . forEach ( ( setSlide , setIndex ) => {
83+ const reference = {
84+ id : setSlide . props . id || slideReference . length ,
85+ setIndex,
86+ rootIndex
87+ } ;
88+ if ( child . props . goTo ) {
89+ reference . goTo = child . props . goTo ;
90+ }
91+ slideReference . push ( reference ) ;
92+ } ) ;
93+ }
94+ } ) ;
95+ return slideReference ;
96+ }
97+
6598export class Manager extends Component {
6699 static displayName = 'Manager' ;
67100
@@ -146,10 +179,8 @@ export class Manager extends Component {
146179 } ;
147180 }
148181
149- componentWillMount ( ) {
150- this . setState ( {
151- slideReference : this . _buildSlideReference ( this . props )
152- } ) ;
182+ static getDerivedStateFromProps ( nextProps ) {
183+ return { slideReference : buildSlideReference ( nextProps ) } ;
153184 }
154185
155186 componentDidMount ( ) {
@@ -163,12 +194,6 @@ export class Manager extends Component {
163194 }
164195 }
165196
166- componentWillReceiveProps ( nextProps ) {
167- this . setState ( {
168- slideReference : this . _buildSlideReference ( nextProps )
169- } ) ;
170- }
171-
172197 componentDidUpdate ( ) {
173198 if (
174199 this . props . globalStyles &&
@@ -177,6 +202,7 @@ export class Manager extends Component {
177202 this . props . dispatch ( setGlobalStyle ( ) ) ;
178203 }
179204 }
205+
180206 componentWillUnmount ( ) {
181207 this . _detachEvents ( ) ;
182208 }
@@ -670,45 +696,7 @@ export class Manager extends Component {
670696
671697 return 0 ;
672698 }
673- _buildSlideReference ( props ) {
674- const slideReference = [ ] ;
675- Children . toArray ( props . children ) . forEach ( ( child , rootIndex ) => {
676- if ( child . type === Magic ) {
677- Children . toArray ( child . props . children ) . forEach (
678- ( setSlide , magicIndex ) => {
679- const reference = {
680- id : setSlide . props . id || slideReference . length ,
681- magicIndex,
682- rootIndex
683- } ;
684- slideReference . push ( reference ) ;
685- }
686- ) ;
687- } else if ( ! child . props . hasSlideChildren ) {
688- const reference = {
689- id : child . props . id || slideReference . length ,
690- rootIndex
691- } ;
692- if ( child . props . goTo ) {
693- reference . goTo = child . props . goTo ;
694- }
695- slideReference . push ( reference ) ;
696- } else {
697- child . props . children . forEach ( ( setSlide , setIndex ) => {
698- const reference = {
699- id : setSlide . props . id || slideReference . length ,
700- setIndex,
701- rootIndex
702- } ;
703- if ( child . props . goTo ) {
704- reference . goTo = child . props . goTo ;
705- }
706- slideReference . push ( reference ) ;
707- } ) ;
708- }
709- } ) ;
710- return slideReference ;
711- }
699+
712700 _getSlideIndex ( ) {
713701 let index = parseInt ( this . props . route . slide ) ;
714702 if ( ! Number . isFinite ( index ) ) {
0 commit comments