RegisterListener in 3.0 branch

9 views
Skip to first unread message

Jeff Chimene

unread,
Jul 2, 2018, 7:06:47 PM7/2/18
to scion-dev
Hi,
I'm wondering how to register listeners for general tracing.
The invocation of registerListener() call throws an error: "this is not defined"
I'm using the 3.1.5 tag
 
<script src="SCION/dist/scxml.js" type="text/javascript"></script>
scxml.urlToModel("sfm-coach.xml", function(err, model) {
                if (err) { throw err; }

                // instantiate the interpreter
                var interpreter = new scxml.scion.Statechart(model);
               
                interpreter.registerListener(listeners);

                // start the interpreter
                interpreter.start();

                interpreter.gen({
                    name : "init",
                    data : api
                });
            });

Thanks!

Jacob Beard

unread,
Jul 3, 2018, 3:11:44 AM7/3/18
to scio...@googlegroups.com
Hi Jeff,

Can you please post the initialization of the variable listeners? 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.

Jeff Chimene

unread,
Jul 3, 2018, 5:50:55 AM7/3/18
to scion-dev
Hi Jacob,
Here's the entire function. Thank you for your support!

        $(document).ready(function()
       
{
           
var $wnd = window;
           
var api = null;

           
var listeners = {
                    onEntry
: function(stateId) { console.log('entering state ' + stateId); },
                    onExit
: function(stateId) { console.log('exiting state ' + stateId); },
                    onTransition
: function(sourceStateId, targetIds) {
                       
if (targetIds && targetIds.length) {
                            console
.log('transitioning from ' + sourceStateId + ' to ' + targetIds.join(','));
                       
} else {
                            console
.log('executing target-less transition in ' + sourceStateId);
                       
}
                   
},
                    onError
: function(err) {
                        console
.log('ERROR:' + JSON.stringify(err));
                   
}
               
};


            scxml
.urlToModel("sfm-coach.xml", function(err, model)
           
{
               
if (err)
               
{
                   
throw err;
               
}


                api
= {
                    jQuery
: function()
                   
{
                       
return jQuery;
                   
},
                    window
: function()
                   
{
                       
return window;
                   
}
               
};


               
// instantiate the interpreter
               
var interpreter = new scxml.scion.Statechart(model);
               
               
interpreter.registerListener(listeners);

               
// start the interpreter
                interpreter
.start();
                interpreter
.gen({
                    name
: "init",
                    data
: api
               
});
           
});

       
});



Jacob Beard

unread,
Jul 3, 2018, 7:40:56 AM7/3/18
to scio...@googlegroups.com
Can you please post a stack trace? Thank you,

Jake

Jeff Chimene

unread,
Jul 3, 2018, 11:13:07 AM7/3/18
to scion-dev
Hi Jacob,

It looks like the /this/ is now passed as the 2nd argument to on() when using

<script src="https://cdnjs.cloudflare.com/ajax/libs/scion/4.3.1/scxml.js"></script>

{
    key
: 'registerListener',
    value
: function registerListener(listener) {
     
BaseInterpreter.EVENTS.forEach(function (event) {
       
if (listener[event]) this.on(event, listener[event]);
     
}, this);
   
}

This is not the case with the 3.1.5 tag on GitHub

/** @expose */registerListener:
   
function registerListener(listener){BaseInterpreter.EVENTS.forEach(function(event){
       
if(listener[event])this.on(event,listener[event]);});}
,



Jeff Chimene

unread,
Jul 3, 2018, 11:16:04 AM7/3/18
to scion-dev


On Tuesday, July 3, 2018 at 8:13:07 AM UTC-7, Jeff Chimene wrote:
Hi Jacob,

It looks like the /this/ is now passed as the 2nd argument to FOREACH() when using

Jacob Beard

unread,
Jul 3, 2018, 11:26:17 AM7/3/18
to scio...@googlegroups.com
It looks like this might have been a bug in 3.1.5 that got fixed in 4.3.1. Any chance you would be able to upgrade to 4.3.1?

Thanks,

Jake
Reply all
Reply to author
Forward
0 new messages