Skip to content

crishushu/scion-x

Repository files navigation

scion-x

Simple extension of SCION by Jacob Beard

Documentation

This SCION wrapper provides some additional functionalities with respect to the original implementation.

Those includes:

  • UMD enabled
  • Loader uses jQuery Deferreds
  • Convenient getter functions such as getActiveEvents() which returns all accepted events at a current configuration including those subsumed by valid parent states
  • The SCION interpreter takes account for the attribute "name" of the state that can be obtained by the function getStateName()
  • The SCION interpreter takes account for the attribute "type" of the state that can be obtained by the function getStateType()
  • Additional tweaks during runtime behavior such as a toggle switching on/off script execution inside SCXML: ignoreScript() and evaluateScript()

Getting Started

Install the module with: npm install scion-x

Define the configuration:
var config = {
        doc: 'http://localhost:9995/scxml.xml', // url locates the SCXML document
        evalScript: true, // default value for script execution
        // using SCION inbuilt listener to report engine activities
        scionListener: {
            statesActive: [],
            onEntry: function(stateName) {               
                console.debug('entry', stateName);
                // some additional code
            },
            onExit: function(stateName) {
                console.debug('exit', stateName);
                // some additional code
            },
            onTransition: function(sourceState, targetStates) {
                console.debug(sourceState, 'transits to', targetStates);
                // some additional code
            }
        },
        // using scion-x to report engine activities
        onraise: function(e) {
            console.debug('current state:', this.getState());
            console.debug('active states:', this.getActiveStates());
            console.debug('active events:', this.getActiveEvents());
        }
    };
Start the SCION interpreter using known UMD pattern:
(function(global, factory) {
    if (typeof module === 'object') {
        module.exports = factory(require('scionx'));
    } else if (typeof define === 'function' && define.amd) {
        define(['scionx'], factory);
    } else {
        factory(scionx);
    }
})(this, function(scion) {
    scion(config).init(function(_engine) {
        _engine.start();
        // some additional code
    });
});
To test the implementation using node
  1. Set the path to your node_modules containing the required grunt plugins (see package.json) inside Gruntfile.js
  2. Type in your command line: grunt

You can also just execute with node usage. Though, before you need to start the file server that serves the SCXML document. To this end you go to the folder scxml and type in your terminal: node file-server

To test the implementation using globals
  1. Set the path to your node_modules containing the required grunt plugins (see package.json) inside Gruntfile.js
  2. Adapt comment as below
  3. Type in your command line: grunt serve:browser
<script type="text/javascript" src="lib/scionWrapper.js"></script>
<script type="text/javascript" src="node_modules/umd-logger/lib/umd-logger.js"></script>
<script type="text/javascript" src="usage.js"></script>
To test the implementation using AMD
  1. Set the path to your node_modules containing the required grunt plugins (see package.json) inside Gruntfile.js
  2. Adapt index.html as below
  3. Type in your command line: grunt serve:browser
<script type="text/javascript">
  var require = {
    paths: {
        'umd-logger': './node_modules/umd-logger/lib/umd-logger',
        'scionx': './lib/scionLoader',
        'scionWrapper': './lib/scionWrapper',
        'scion': './node_modules/scion/dist/scion'
    },
    deps: ['usage']
  }
</script>
<script type="text/javascript" src="require.js"></script>

License

Copyright (c) 2014 Christian H. Schulz
Licensed under the MIT license.

Releases

No releases published

Packages

No packages published