joelhooks / parsley-utilities-Chain

Simple Parsley Command Chaining

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This utility is a way to create a Finite State Machine (FSM) for a Parsley Context. The FSM documents and manages a series of N-Branching commands in a chain. The Chain is created either declaratively through MXML configuration or via actionscript. It will respond dynamically to messages within a Context and trigger Parsley style Commands. The logic from moving from state to state is left up to the developer. The Chain will move to a different link based on events and mapped connections to other links within the Chain.

This is currently a proof of concept project and should not be used for production.

Example Usage

This is an example of how the chain can be declared in a Parsley MXML configuration:

 <?xml version="1.0"?>
<!-- Parsley Configuration -->
<mx:Object xmlns:mx="http://www.adobe.com/2006/mxml"
           xmlns:chain="http://spicefactory.org/parsley/chain">

    <mx:Script><![CDATA[
        import events.*
        import commands.*;
        ]]>
    </mx:Script>

    <chain:Chain firstLink="{startup}">

        <chain:Link id="startup" commandClass="{StartupCommand}">
            <chain:LinkConnection onMessage="{LoadDefaultEnvironmentEvent.LOAD}" toLink="{loadDefaultEnvironment}"/>
            <chain:LinkConnection onMessage="{LoadSpecialEnvironmentEvent.LOAD}" toLink="{loadSpecialEnvironment}"/>
            <chain:LinkConnection onMessage="{StartupErrorEvent.ERROR}" toLink="{startupError}"/>
        </chain:Link>

        <chain:Link id="loadDefaultEnvironment" commandClass="{LoadDefaultEnvironmentModuleCommand}">
            <chain:LinkConnection onMessage="{EnvironmentLoadedEvent.LOADED}" toLink="{loadLocalConfiguration}"/>
            <chain:LinkConnection onMessage="{StartupErrorEvent.ERROR}" toLink="{startupError}"/>
        </chain:Link>

        <chain:Link id="loadSpecialEnvironment" commandClass="{LoadSpecialEnvironmentModuleCommand}">
            <chain:LinkConnection onMessage="{EnvironmentLoadedEvent.LOADED}" toLink="{loadLocalConfiguration}"/>
            <chain:LinkConnection onMessage="{StartupErrorEvent.ERROR}" toLink="{startupError}"/>
        </chain:Link>

        <chain:Link id="initializeServices" commandClass="{InitializeServicesCommand}">
            <chain:LinkConnection onMessage="{ServicesInitializedEvent.INITIALIZED}" toLink="{startupComplete}"/>
            <chain:LinkConnection onMessage="{StartupErrorEvent.ERROR}" toLink="{startupError}"/>
        </chain:Link>

        <chain:Link id="startupComplete" commandClass="{StartupCompleteCommand}"/>
        
        <chain:Link id="startupError" commandClass="{StartupErrorCommand}"/>

    </chain:Chain>

</mx:Object>

Building

You will need to link to the manifest.xml to take advantage of the declarative style shown above.
Requires Parsley 2.3

About

Simple Parsley Command Chaining


Languages

Language:ActionScript 100.0%