Merge pull request #23 from titouanc/fit-sample-spec

Sample should not produce anything before the source has produced a value
master
Bjorn Swenson 2017-10-03 09:49:04 -07:00 committed by GitHub
commit e56cf8917e
3 changed files with 7 additions and 6 deletions

4
rx.lua
View File

@ -1229,7 +1229,9 @@ function Observable:sample(sampler)
end
local function onNext()
return observer:onNext(util.unpack(latest))
if #latest > 0 then
return observer:onNext(util.unpack(latest))
end
end
local function onError(message)

View File

@ -16,7 +16,9 @@ function Observable:sample(sampler)
end
local function onNext()
return observer:onNext(util.unpack(latest))
if #latest > 0 then
return observer:onNext(util.unpack(latest))
end
end
local function onError(message)

View File

@ -6,10 +6,7 @@ describe('sample', function()
it('produces nil values if the sampler fires before the source does', function()
local sampler = Rx.Observable.fromRange(3)
local onNext, onError, onCompleted = observableSpy(Rx.Observable.empty():sample(sampler))
expect(#onNext).to.equal(3)
expect(next(onNext[1])).to_not.exist()
expect(next(onNext[2])).to_not.exist()
expect(next(onNext[3])).to_not.exist()
expect(#onNext).to.equal(0)
end)
it('produces the latest value produced by the source when the sampler fires', function()