Skip to content

Instantly share code, notes, and snippets.

@DotNetNerd
Created May 8, 2013 08:15
Show Gist options
  • Save DotNetNerd/5539002 to your computer and use it in GitHub Desktop.
Save DotNetNerd/5539002 to your computer and use it in GitHub Desktop.
Shows buffering of clicks using Reactive extentions in JavaScript
.Add("/scripts/libs/rx.min.js")
.Add("/scripts/libs/rx.time.min.js")
.Add("/scripts/libs/rx.jquery.min.js")
var observer = $(e.target).clickAsObservable().bufferWithTime(200)
.subscribe(function (events) {
console.log(events.length);
var $item = $(e.target).closest('.productItem');
var quantity = parseInt($.trim($item.find('.qty').html())) + events.length + 1;
Basket.UpdateQuantity({ LineProductId: $item.attr('data-productId'), Quantity: quantity }, Basket.ShowQuantity);
observer.dispose();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment