サーバーと通信して現在の画面形状などを報告する機能があります。
function sendScreenLayout() {
logElementLocations(exp.getPageCoordinates());
};
私はこの関数を次のようなコード内のいくつかのイベントにサブスクライブします。
viewModel.onLayoutChange.subscribe(sendScreenLayout);
$('#right-splitter > #mainContent').resize(sendScreenLayout);
$(window).resize(sendScreenLayout);
...
setTimeout(sendScreenLayout, 1);
これらのイベントの一部は、サーバーで適切に処理できないほど頻繁に送信される可能性があるため、要求をある程度の適切な速度に抑制したいと思います。
私が思いついた最高のものは次のようなものでした:
var triggerSend = ko.observable();
ko.computed(function() {
triggerSend();
logElementLocations(exp.getPageCoordinates());
}).extend({throttle: 200});
function sendScreenLayout() {
triggerSend.valueHasMutated();
}
このパターンをキャプチャするためのより簡潔な方法はありますか、それともこれが進むべき方法ですか?