Skip to content

Commit

Permalink
Merge pull request #24 from grapp-dev/fix/combine-latest
Browse files Browse the repository at this point in the history
fix: ensure that the `signal_values` provided are resolved correctly when using `combine_latest`
  • Loading branch information
mobily authored Apr 14, 2024
2 parents 67cb2f7 + 2a9559b commit 013409d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/pages/docs/signal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ And here's the final result:
name="combine_latest"
args={[
['...', 'SignalValue[]'],
['combinator_fn', 'fun(...): T']
]}
returns="SignalValue"
/>
Expand Down
13 changes: 12 additions & 1 deletion lua/nui-components/signal/value.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,18 @@ function SignalValue:skip(n)
end

function SignalValue:combine_latest(...)
self._private.observable = self._private.observable:combine_latest(...)
local signal_values = { ... }

local sources = fn.imap(signal_values, function(signal_value, index)
if type(signal_value) ~= "function" and not (index == #signal_values) then
return signal_value:get_observable()
end

return signal_value
end)

self._private.observable = self._private.observable:combine_latest(fn.unpack(sources))

return self
end

Expand Down

0 comments on commit 013409d

Please sign in to comment.