[Xsltforms-support] Evaluating long calculations asynchronously in background
Brought to you by:
alain-couthures
From: Mats E. <mat...@li...> - 2015-08-26 14:45:15
|
Hi, I am looking at options for performing time-consuming operations, like... <xf:setvalue ref="mynode" value="digest(transform(instance('my-very-large-instance-document')),'SHA-1')"/> ...in my form as background operations that don't cause freezing of the form's UI. Obviously, if my form had access to a web-server, such calculations could be posted to the server using an xf:submission, however, in my case, the form should work completely offline. In HTML 5 there is the Web Worker object, and it should be possible to leverage this to perform the calculation in a background thread client-side. I guess it is possible to implement the long running calculation in a javascript function that may be called via xf:load and where the result is returned via call to XForms DOM API (model.getInstanceDocument(), model.recalculate()...). However, it would be nice if the operation could be kept more "XFormy" and as declarative as in the "non-async" example above. I'm currently considering two possible options: 1) XForms extension attribute, like so: <xf:setvalue ref="mynode" value="..." @ext:async="true"/> 2) Implementing the operation as an xf:submission, but proxying the underlying XMLHttpRequest object to intercept selected submission URLs and handle them client-side: <xf:submission resource="http://client/myfunction?param1=..." serialization="...".../> and XMLHttpRequest.registerHandler("http://client/myfunction", myhandler) Both options seem to have their unique merits and possible usages. While the second option is probably quite straight-forward to implement, the second option may require some more work, like: 1) Porting XSLTForms XPath implementation, as well as some other objects (XSLTTransform), to work in a Web Worker context.2) Finding a way to efficiently transfer relevant data (XForms instances) to the Worker context2) Making modifications to the relevant action implementations in XSLTForms to handle asynchronous execution of the action Seems doable to me, but would be interested to hear if someone has experience to tell whether that'a crazy idea or not. Obviously, would be cool if such features could become native features of XSLTForms! Welcoming your feedback! Mats |