[fix] Sample should not produce anything before the source has produced any value

master
iTitou 2017-10-03 11:31:23 +02:00
parent 763ab162cd
commit 20ec3b7bef
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()