Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcing state #96

Closed
insonifi opened this issue Jun 22, 2015 · 3 comments
Closed

Forcing state #96

insonifi opened this issue Jun 22, 2015 · 3 comments

Comments

@insonifi
Copy link

Is there a way to force state. Why I need this: app is keeping track of object states that are fetched from server first, and states are hardly initial states. Which means it also needs to be able to define composite state as well.
I explored the source, and haven't found anything like that. So came up with an extremely dirty hack to achieve that, still hoping to hear it possible.

Just so you know of my crime.

forceFsmState.call(fsm, 'armed.alarmed');

function forceFsmState (stateStr) {
    var stateList = stateStr.split('.');
    var len = stateList.length;
    var i;
    var child;
    var state;
    var instance = this;
    for (i = 0; i < len; i += 1) {
        state = stateList[i];
        instance.state = state;
        child = instance.states[state]._child;
        if (child) {
            child.instance.initClient();
            instance = child.instance;
        }
    }
}
@ifandelse
Copy link
Owner

Hi @insonifi - with BehavioralFsm instances, loading previously stored/serialized FSM clients should work without an issue (since those clients get stamped with the relevant machina FSM state(s), etc.). However, I'm inferring from your example above that you're probably using the Fsm constructor rather than BehavioralFsm - is that correct? I need to think through it a bit once I've had some sleep, but since the Fsm constructor is effectively a Behavioral instance that uses itself as the client, I should be able to write a prototype helper (or something similar) to load previously-stored state(s). I will keep you posted, thanks!

@insonifi
Copy link
Author

Indeed, I use Fsm constructor, same as in issue #92. I had a closer look at BehavioralFsm, and found it mgiht actually fit better. Since a lot of fsm's will be issued in my app (easily several hundreds). Possibly I can replace client when current state is fetched from server. But I'm not sure how to follow hierarchy.

@ifandelse
Copy link
Owner

In some upcoming updates to this repo, I hope to include some examples of fetching a client of a BehavioralFsm from storage to better explain this issue...thanks, and sorry for the huge delay! (#146 has some explanation as to why I've been quiet!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants