Serialized partial refresh calls V1.0.1

if (!XSP._inheritedPartialRefresh) {
	XSP._inheritedPartialRefresh = XSP._partialRefresh;
	XSP._partialRefreshQueue= [];
	XSP._canSubmit= XSP.canSubmit;

	XSP.canSubmit= function() {
		return true; // can always submit
	};

	XSP._partialRefresh = function(method, form, refreshId, options) {
		this._partialRefreshQueue.push([method, form, refreshId, options]);
		if(XSP._partialRefreshQueue.length<=1)
			setTimeout(XSP._partialRefreshProcess, 100);
	};
	
	XSP._partialRefreshProcess= function() {
		if(XSP._partialRefreshQueue.length==0)
			return;
		var arguments= XSP._partialRefreshQueue[0];
		// Publish init
		dojo.publish('partialrefresh-init', arguments);
		XSP._inheritedPartialRefresh.apply(XSP, arguments);
		XSP.allowSubmit();
	};

	dojo.subscribe('partialrefresh-end', function() {
		XSP._partialRefreshQueue.shift();
		if(XSP._partialRefreshQueue.length)
			setTimeout(XSP._partialRefreshProcess, 100);
	})
}





This is an attempt to serialize all partial refresh calls. The advantages are: code that's easier to read, smooth execution, easier debugging sometimes, and one can add a partial refresh when one needs it, without worrying about refresh calls that are already active.

I didn't find any problems yet, but I cannot guarantee that there aren't any. Your comments are welcome!

The "standard" way is still possible, i.e. using cascading calls through onComplete.

Based on and making use of: http://dontpanic82.blogspot.fr/2010/01/xpages-hijackingpublishing-partial.html

Release History
V1.0.1: solved a rare condition when Process() is called with an empty queue.

JavaScript (Client)
Sjef Bosman
February 7, 2018 12:59 PM
Rating
0

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



1 comment(s)Login first to comment...
Fredrik Norling
(at 14:26 on 12.08.2018)
It might be a conflict if one is using my standby dialog snippet because this is also using http://dontpanic82.blogspot.fr/2010/01/xpages-hijackingpublishing-partial.html