Afrous CoreOverviewTo accomplish easy manipulation of asynchronous operations in Ajax-style applications, Afrous introduced the notion of declarative process configuration in process cordination. Afrous Core JavaScript engine deals with pre-defined operation objects with same interface. We call them Unit Action. Unit Action is encapsulated and accessible only via its input and output. The output is notified by callback function when the action operation has finished, but process developers shouldn't know which was synchronous or asynchronous. Unit Action becomes an instance when included in process definition, which we call it Action Instance, or simply Action. Action input can be explicit static values or references which are mapped to other action's output. All evaluation order of Actions are determined by the engine, considering the dependencies of inputs and outputs between the Actions, not in procedual manner. Class Diagram
Process Config Element ReferenceProcess| Property Name | Data Type | Description | | name | String | The name of process | | requires | Hash<String, String> | The pair of package namespace and its script URL which should be loaded before process evaluation | | params | Object[] | The array of process parameters | | output | String | Definition of the process output value. Action output and parameter values can be refered by "${ ... }" notation | | actions | Object[] | The array of action definitions |
Parameter| Property Name | Data Type | Description | | name | String | Name of the parameter | | type | String | Data type of the parameter. Acceptable data type is String, Integer, Float and array form of those types. | | default | String | Default value of the parameter if not specified. |
Action| Property Name | Data Type | Description | | name | String | Name of the action | | type | String | The type name of Unit Action. Should be fully qualified name including package. | | inputs | Hash<String,String> | Values assigned to the action's input. Action output and parameter values can be refered by "${ ... }" notation. | | innerProcess | Object | (Option) Inner process definition. Some unit actions (e.g. "iterate") require this. |
Sample Process Configuration var config = {
name : "process1",
params : [
{ name : 'username', type : 'string', 'default' : 'stomita' },
{ name : 'count', type : 'integer', 'default' : 5 }
],
output : "${networkPosts}",
actions : [
{ name : "delnetwork",
type : "Ajax.Jsonp",
inputs : {
"url" : "http://del.icio.us/feeds/json/network/${username}"
}
}
,
{ name : "networkPosts",
type : "Array.Iterate",
inputs : {
"array" : "${delnetwork}"
},
innerProcess : {
output : "${posts}",
actions : [
{ name : "posts",
type : "Ajax.Jsonp",
inputs : {
"url" : "http://del.icio.us/feeds/json/${element}"
}
}
]
}
}
]
}Sample JavaScript<script type="text/javascript" src="http://sandbox.afrous.com/js/afrous/afrous-core.js"></script>
<script type="text/javascript" src="http://sandbox.afrous.com/js/afrous/afrous-package.js"></script>
<script type="text/javascript">
var config = { ... }; // afrous config in JSON
var procdef = new afrous.ProcessDef(config);
var proc = new afrous.ProcessInstance(procdef);
proc.start({
onSuccess : function(result) { ... } // write handler to handle process output
onFailure : function(error) { ... }
});
</script>
|
How to write the handler to handle process output?