1414
1515import React , { Component , PropTypes } from 'react' ;
1616import { createMemoryHistory } from 'history' ;
17+ import fixPath from '../utils' ;
1718
1819class Wizard extends Component {
1920 state = {
@@ -26,15 +27,15 @@ class Wizard extends Component {
2627 getChildContext ( ) {
2728 return {
2829 wizard : {
29- _setSteps : this . setSteps ,
3030 step : this . state . step ,
3131 steps : this . steps ,
3232 next : this . next ,
33- previous : this . previous ,
33+ previous : this . props . history . goBack ,
3434 push : this . push ,
35- go : this . go ,
35+ go : this . props . history . go ,
3636 history : this . props . history ,
3737 } ,
38+ wizardInit : this . init ,
3839 } ;
3940 }
4041
@@ -54,37 +55,30 @@ class Wizard extends Component {
5455 this . unlisten ( ) ;
5556 }
5657
57- setInitialStep ( ) {
58+ init = ( steps ) => {
59+ this . steps = steps ;
60+
5861 if ( this . props . onNext ) {
5962 this . props . onNext ( { path : null , name : null } , this . steps , this . replace ) ;
6063 } else {
6164 this . replace ( ) ;
6265 }
6366 }
6467
65- setSteps = ( steps ) => {
66- this . steps = steps ;
67- this . setInitialStep ( ) ;
68- }
69-
7068 steps = [ ] ;
71- previous = this . props . history . goBack ;
72- go = this . props . history . go ;
7369
7470 get paths ( ) {
7571 return this . steps . map ( s => s . path ) ;
7672 }
7773
78- fixPath = pathname => pathname . replace ( / \/ \/ + / g, '/' ) ;
79-
8074 push = ( step ) => {
8175 const nextStep = step || this . paths [ this . paths . indexOf ( this . state . step . path ) + 1 ] ;
82- this . props . history . push ( this . fixPath ( `${ this . props . basename } /${ nextStep } ` ) ) ;
76+ this . props . history . push ( fixPath ( `${ this . props . basename } /${ nextStep } ` ) ) ;
8377 }
8478
8579 replace = ( step ) => {
8680 const nextStep = step || this . paths [ 0 ] ;
87- this . props . history . replace ( this . fixPath ( `${ this . props . basename } /${ nextStep } ` ) ) ;
81+ this . props . history . replace ( fixPath ( `${ this . props . basename } /${ nextStep } ` ) ) ;
8882 }
8983
9084 next = ( ) => {
@@ -131,6 +125,7 @@ Wizard.defaultProps = {
131125
132126Wizard . childContextTypes = {
133127 wizard : PropTypes . object ,
128+ wizardInit : PropTypes . func ,
134129} ;
135130
136131export default Wizard ;
0 commit comments