I have a function that performs some communication with a server to report the current screen geometry, etc.
function sendScreenLayout() {
logElementLocations(exp.getPageCoordinates());
};
I subscribe this function to some events in my code like this:
viewModel.onLayoutChange.subscribe(sendScreenLayout);
$('#right-splitter > #mainContent').resize(sendScreenLayout);
$(window).resize(sendScreenLayout);
...
setTimeout(sendScreenLayout, 1);
Some of these events may get sent too frequently to be usefully handled by the server, and I would like to throttle the requests to some reasonable rate.
The best I could come up with was something like this:
var triggerSend = ko.observable();
ko.computed(function() {
triggerSend();
logElementLocations(exp.getPageCoordinates());
}).extend({throttle: 200});
function sendScreenLayout() {
triggerSend.valueHasMutated();
}
Is there a more succinct way of capturing this pattern, or is this the way to go?