Closed devinus closed 13 years ago
Hmm, ya. From a purity perspective there's nothing mentioned about passing args; however, passing arguments when going through a state transition process needs to be looked at carefully.
When you go to a state and pass args what does that mean? How does that affect all states that are being entered during the state transition process? What about parallel states?
Could you provide some more detail about what you are trying to do?
Yes--and just as an example--you wanted to pass along parameters from SC.Routes into your state transition, e.g.:
_detailRoute: function (params) {
this.gotoState('READY.DETAIL', this, { id: params.id });
}
We've run into a few frustrating scenarios where being able to pass along a context would greatly simplify things.
gotoState(state, fromCurrentState, context, useHistory) as a bonus would resemble the function signature for sendEvent. :)
Okay. Let me put together an experimental branch that will allow you pass args to the enterState function.
Great, I'll begin testing it as soon as it's available!
The changes are up on the experimental enter-state-args branch. I'm still debating the implementation, but let me know how this is working out for you in the mean time.
We've started using the branch, and it really is working great. Now instead of using events to pass a context after we enter states, which is essentially what we wanted to do when we entered the state, we can simply pass it on enter. Really awesome.
Glad to hear it's working out for you. I'm thinking about refactoring the implementation. The reason is because the context
argument must be supplied when calling the statechart's gotoState
whenever you supply the useHistory
argument. In such cases the value someone would likely set on the context
arg would be null
, but null
is a legitimate value one might expect when entering a state. Rather, if the context
argument is not intended to be used then the context
value passed to the enterState
should be the undefined
value.
Right now our gotoStates look like this:
this.gotoState('READY.DETAILS', null, { id: params.id })
Are you proposing:
this.gotoState('READY.DETAILS', null, NO, { id: params.id });
Have you thought any more about your proposal?
Sorry. I've been so side tracked with other stuff that I have neglected to give my full attention to the matter. Regarding my proposal, ya, I was thinking of:
this.gotoState('READY.DETAILS', null, NO, { id: params.id });
Therefore if the user does not want to supply a context value then undefined
will be supplied to the enterState
function. The value null
can be considered a legit value, so I rather avoid passing null
as a default value.
That makes sense.
Is there any chance to see this in sproutcore now that KI is the official statechart ? I'm having a similar issue. My state need to have a context to pass an id.
Yep. Updates are coming soon for both Ki frameworks (on my github account and on the SproutCore account).
implemented
Are there philosophical objections to sending along a context with gotoState that enterState could use? E.g.:
Becomes:
Then:
This would help us simplify a lot of things.