Merge pull request #23 from titouanc/fit-sample-spec
Sample should not produce anything before the source has produced a valuemaster
commit
e56cf8917e
4
rx.lua
4
rx.lua
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue