@xmlaspect/reactive-xml
Asynchronous execution chain based on collections API with wrappers around DHTML DOM API, jQuery and XML+XSLT+XPATH
JS module is published in NPM
Contents
DefineScenario
DefineScenario( arr ).a().b()
Is used for scenario creation which could be triggered with own dataset more than once later via .start(data) method.
- wraps methods of given object/collection elements
- wrapper on call saves the CallDeclaration into call list of previous call
CallDeclaration
is a signature of method call with CallParameters. In dot call chain each method with parameters saved as CallDeclaration.
It holds wrappers in prototype for all methods of object given to DefineScenario( dataDefinition ), which is used for sub-scenario creation.
let subA = DefineScenario( dataDefinition ).a(); subA.b().c().d(); subA.x().y().z();
In given sample subA is split into two sub-chains which will be run in parallel.
.b().c().d() DefineScenario( dataDefinition ).a() .x().y().z()
Each method( a,b,c,x,y,z ) wrapper in sample returns own CallDeclaration allowing further call chain(s) creation.
First in chain
DefineScenario( dataDefinition )
DefineScenario() returns CallDeclaration object which does not have other attributes except of list of following CallDeclarations.
CallParameter
During scenario execution the method is called for each wrapped object with parameters defined during declaration or computed in run time:
- usual parameters are passed in run time by value
- the named or back reference in Call Graph
- computed by callback for each wrapped object at runtime
let abc = i=> ({ v: ()=>i, a: x=> x+i,b: x=> x+i,c: (x,y,z)=> x+y+z+i }) // returns object with v, a(), b(), c() members , arr = [ abc(1), abc(2), abc(3) ]; DefineScenario( arr ).a(10).b(20); DefineScenario( arr ).a(10).b(20).c( CallRef(-1), CallRef(-2), CallRef(1) ); // arr[i].c( 20+i, 10+i, 10+i ) const cb = ( el, index, collection, callTree )=> index ; // callback evaluates last call as c(i) DefineScenario( arr ).a(10).b(20).c( CallRef( cb ) ); // arr[i].a(10).b(20).c( i )
Method name
In CallDeclaration used for invoking the wrapped object method.
Call Graph
DefineScenario( arr ).a(10).b(20).set();
In the sample above array elements are served in parallel:
/ abc(1) » a(10) == 11 » b(20) == 21 \ [ abc(1), abc(2), abc(3) ] - abc(2) » a(10) == 12 » b(20) == 22 - [21,22,23] \ abc(3) » a(10) == 13 » b(20) == 23 /
The .set() method wait for all chains finished before result of last call saved into new collection. Further collection objects are numbers so it does not make a
CallStack
DefineScenario does not run the chain itself, it needs to be executed either by direct invoking of .start(data) or via AsyncChain helper API.
const scenario= DefineScenario( arr ); scenario.a(10).b(20); const callStack1 = scenario.start( arr );// same data is used as for declaration as for execution const callStack2 = scenario.start( arr2 ); // another data set
While CallStack became available immediately upon start(), it executed asynchronously and could be interrupted or destroyed at any time. It supports the activation( pause,start,restart ) and debug( break, pause, resume,callstack ) APIs.
AsyncChain
combines declaration and execution in single call:
AsyncChain( arr ).a(10).b(10);
is same as two calls:
const scenario= DefineScenario( arr ).a(10).b(20); scenario.start( arr );