Need both cond & event to transition when using $.ajax?

15 views
Skip to first unread message

Jeff Chimene

unread,
Oct 24, 2014, 8:50:10 PM10/24/14
to scio...@googlegroups.com
I wonder if I'm doing this right.

Instead of two interpreter.gen("event.sfm.purchase) calls, I had to introduce a variable "postComplete".
Instead of two assignments to "postComplete", I have to use interpreter.gen().

The transition isn't triggered when I set postComplete=true inside the $.ajax.success() function. I must use an interpreter.gen("event.sf.postComplete") call.

SCION throws the
"gen called before previous call to gen could complete. If executed in single-threaded environment, this means it was called recursively, which is illegal, as it would break SCION step semantics."
exception when I use interpreter.gen("event.sfm.postComplete") inside the ELSE branch.

<datamodel>
<data id="postComplete" expr="false" />
</datamodel>
<state id="sfm.sales.post">
        <onentry>
            <script>
            if ('' != getSalesEmail()) {
                $.ajax({type: "POST",
                    url: "URL",
                    data: "some data",
                    success: function(data) {
                        interpreter.gen("event.sfm.postComplete");
                    }});
            } else {
                postComplete=true;
            }
            </script>
        </onentry>
        <transition target="sfm.purchase" event="event.sfm.postComplete" />
        <transition target="sfm.purchase" cond="postComplete" />
    </state>

tia,
jec

Jacob Beard

unread,
Oct 24, 2014, 11:33:20 PM10/24/14
to scio...@googlegroups.com
Hi Jeff,

Rather than calling interpreter.gen() recursively inside of your script, you can instead use the built-in $send function. This is described in the Action Tag Scripting API: 


Note that this is a feature exposed by SCION, but not a part of standard SCXML.

Technically speaking, you could use a $raise in the else clause, and a $send in the body of the $.ajax callback. This is because the else clause would be executed in the current small-step, but the $.ajax is asynchronous, and would be executed after the end of the current big-step. You can see SCION semantics for more info on this: https://github.com/jbeard4/SCION/wiki/Scion-Semantics

Let me know if you have any questions Thanks,

Jake

--
You received this message because you are subscribed to the Google Groups "scion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scion-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Chimene

unread,
Oct 25, 2014, 12:50:26 AM10/25/14
to scio...@googlegroups.com
Thanks, Jacob I will try $send and $raise
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages