@@ -93,7 +93,11 @@ GlobalStateManager.prototype = {
9393 {
9494 if ( ! key ) { key = 'default' ; }
9595
96- if ( stateConfig instanceof State )
96+ if ( typeof stateConfig === 'function' )
97+ {
98+ return key ;
99+ }
100+ else if ( stateConfig instanceof State )
97101 {
98102 key = stateConfig . settings . key ;
99103 }
@@ -138,7 +142,7 @@ GlobalStateManager.prototype = {
138142 autoStart : autoStart
139143 } ) ;
140144
141- console . log ( 'GlobalStateManager not yet booted, adding to list' , this . _pending . length ) ;
145+ // console.log('GlobalStateManager not yet booted, adding to list', this._pending.length);
142146
143147 return ;
144148 }
@@ -152,6 +156,7 @@ GlobalStateManager.prototype = {
152156 if ( stateConfig instanceof State )
153157 {
154158 // console.log('GlobalStateManager.add from instance:', key);
159+
155160 newState = this . createStateFromInstance ( key , stateConfig ) ;
156161 }
157162 else if ( typeof stateConfig === 'object' )
@@ -169,6 +174,9 @@ GlobalStateManager.prototype = {
169174 newState = this . createStateFromFunction ( key , stateConfig ) ;
170175 }
171176
177+ // Replace key incase the state changed it
178+ key = newState . settings . key ;
179+
172180 this . keys [ key ] = newState ;
173181
174182 this . states . push ( newState ) ;
@@ -216,6 +224,13 @@ GlobalStateManager.prototype = {
216224
217225 if ( newState instanceof State )
218226 {
227+ key = newState . sys . settings . key ;
228+
229+ if ( this . keys . hasOwnProperty ( key ) )
230+ {
231+ throw new Error ( 'Cannot add a State with duplicate key: ' + key ) ;
232+ }
233+
219234 return this . createStateFromInstance ( key , newState ) ;
220235 }
221236 else
@@ -382,6 +397,8 @@ GlobalStateManager.prototype = {
382397
383398 var state = this . getState ( key ) ;
384399
400+ // console.log(state);
401+
385402 if ( state )
386403 {
387404 // Already started? Nothing more to do here ...
0 commit comments