Skip to content

Commit

Permalink
Add debounce docs;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed Jan 29, 2019
1 parent 132e8e8 commit b2c4522
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RxLua
- [concat](#concatsources)
- [contains](#containsvalue)
- [count](#countpredicate)
- [debounce](#debouncetime-scheduler)
- [defaultIfEmpty](#defaultifemptyvalues)
- [delay](#delaytime-scheduler)
- [distinct](#distinct)
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions rx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/operators/debounce.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b2c4522

Please sign in to comment.