1 // ==========================================================================
  2 // Project:   SC.Statechart - A Statechart Framework for SproutCore
  3 // Copyright: ©2010, 2011 Michael Cohen, and contributors.
  4 //            Portions @2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 
  8 /*globals SC */
  9 
 10 /**
 11   @class
 12 
 13   Represents contextual information for whenever a state handles a triggered
 14   route. In additional to retaining contextual information, you can also
 15   use the object to retry trigging the state's route handler. Useful in cases
 16   where you need to defer the handling of the route for a later time.
 17 
 18   @see SC.State
 19 
 20   @extends SC.Object
 21   @author Michael Cohen
 22 */
 23 SC.StateRouteHandlerContext = SC.Object.extend(
 24   /** @scope SC.StateRouteContext.prototype */{
 25 
 26   /**
 27     The state that constructed this context object.
 28 
 29     @property {SC.State}
 30   */
 31   state: null,
 32 
 33   /**
 34     The location that caused the state's route to be
 35     triggered.
 36 
 37     @type String
 38   */
 39   location: null,
 40 
 41   /**
 42     The parameters that were supplied to the state's
 43     handler when the state's route was triggered.
 44 
 45     @type Hash
 46   */
 47   params: null,
 48 
 49   /**
 50     The handler that got invoked when the state's
 51     route was triggered. This can either be a reference
 52     to the actual method or a name of the method.
 53 
 54     @property {Function|String}
 55   */
 56   handler: null,
 57 
 58   /**
 59     Used to retry invoking the state's handler for when
 60     the state's route gets triggered. When called this will
 61     essentially perform the same call as when the handler
 62     was originally triggered on state.
 63   */
 64   retry: function() {
 65     var state = this.get('state'),
 66         params = this.get('params'),
 67         handler = this.get('handler');
 68 
 69     if (SC.typeOf(handler) === SC.T_STRING) {
 70       handler = state[handler];
 71     }
 72 
 73     if (SC.typeOf(handler) === SC.T_FUNCTION) {
 74       handler.apply(state, [params]);
 75     }
 76   }
 77 
 78 });
 79