From b2c4522f4a3852fa18c2bb8da6be53febc81f176 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 29 Jan 2019 02:59:33 -0800 Subject: [PATCH] Add debounce docs; --- doc/README.md | 12 ++++++++++++ rx.lua | 6 ++++++ src/operators/debounce.lua | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/doc/README.md b/doc/README.md index 6516bd4..1b631d3 100644 --- a/doc/README.md +++ b/doc/README.md @@ -33,6 +33,7 @@ RxLua - [concat](#concatsources) - [contains](#containsvalue) - [count](#countpredicate) + - [debounce](#debouncetime-scheduler) - [defaultIfEmpty](#defaultifemptyvalues) - [delay](#delaytime-scheduler) - [distinct](#distinct) @@ -395,6 +396,17 @@ Returns an Observable that produces a single value representing the number of va --- +#### `:debounce(time, scheduler)` + +Returns a new throttled Observable that waits to produce values until a timeout has expired, at which point it produces the latest value from the source Observable. Whenever the source Observable produces a value, the timeout is reset. + +| Name | Type | Default | Description | +|------|------|---------|-------------| +| `time` | number or function | | An amount in milliseconds to wait before producing the last value. | +| `scheduler` | Scheduler | | The scheduler to run the Observable on. | + +--- + #### `:defaultIfEmpty(values)` Returns a new Observable that produces a default set of items if the source Observable produces no values. diff --git a/rx.lua b/rx.lua index 133b550..115f4a1 100644 --- a/rx.lua +++ b/rx.lua @@ -635,6 +635,12 @@ function Observable:count(predicate) end) end +--- Returns a new throttled Observable that waits to produce values until a timeout has expired, at +-- which point it produces the latest value from the source Observable. Whenever the source +-- Observable produces a value, the timeout is reset. +-- @arg {number|function} time - An amount in milliseconds to wait before producing the last value. +-- @arg {Scheduler} scheduler - The scheduler to run the Observable on. +-- @returns {Observable} function Observable:debounce(time, scheduler) time = time or 0 diff --git a/src/operators/debounce.lua b/src/operators/debounce.lua index 4577796..0710b25 100644 --- a/src/operators/debounce.lua +++ b/src/operators/debounce.lua @@ -2,6 +2,12 @@ local Observable = require 'observable' local Subscription = require 'subscription' local util = require 'util' +--- Returns a new throttled Observable that waits to produce values until a timeout has expired, at +-- which point it produces the latest value from the source Observable. Whenever the source +-- Observable produces a value, the timeout is reset. +-- @arg {number|function} time - An amount in milliseconds to wait before producing the last value. +-- @arg {Scheduler} scheduler - The scheduler to run the Observable on. +-- @returns {Observable} function Observable:debounce(time, scheduler) time = time or 0