Skip to content

Commit

Permalink
Merge pull request #34 from grapp-dev/fix/signal-value-emission
Browse files Browse the repository at this point in the history
fix: ensure that only the relevant signal value is emitted
  • Loading branch information
mobily authored Apr 20, 2024
2 parents 1169083 + 3395512 commit dd9bb07
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lua/nui-components/signal/value.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local Observable = require("nui-components.rx.observable")
local fn = require("nui-components.utils.fn")

local SignalValue = {}
Expand All @@ -10,8 +11,12 @@ function SignalValue.create(subject, key)
_private = {
key = key,
subject = subject,
observable = subject:map(function(value)
return value[key]
observable = Observable.defer(function()
return subject
:map(function(value)
return value[key]
end)
:distinct_until_changed(vim.deep_equal)
end),
},
}
Expand All @@ -28,7 +33,7 @@ function SignalValue:get_observer_value()
end

function SignalValue:get_observable()
return self._private.observable:distinct_until_changed(vim.deep_equal)
return self._private.observable
end

function SignalValue:map(map_fn)
Expand Down

0 comments on commit dd9bb07

Please sign in to comment.