Skip to content

Commit 3395512

Browse files
committed
fix: ensure that only the relevant signal value is emitted (part 2)
1 parent 0c42af0 commit 3395512

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

lua/nui-components/signal/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Signal.create(object)
4747
end,
4848
__newindex = function(t, key, value)
4949
t[self.__index][key] = value
50-
self._private.subject(t[self.__index], key)
50+
self._private.subject(t[self.__index])
5151
end,
5252
})
5353

lua/nui-components/signal/value.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local Observable = require("nui-components.rx.observable")
12
local fn = require("nui-components.utils.fn")
23

34
local SignalValue = {}
@@ -10,13 +11,13 @@ function SignalValue.create(subject, key)
1011
_private = {
1112
key = key,
1213
subject = subject,
13-
observable = subject
14-
:filter(function(_, k)
15-
return k == nil or k == key
16-
end)
17-
:map(function(value)
18-
return value[key]
19-
end),
14+
observable = Observable.defer(function()
15+
return subject
16+
:map(function(value)
17+
return value[key]
18+
end)
19+
:distinct_until_changed(vim.deep_equal)
20+
end),
2021
},
2122
}
2223

@@ -32,7 +33,7 @@ function SignalValue:get_observer_value()
3233
end
3334

3435
function SignalValue:get_observable()
35-
return self._private.observable:distinct_until_changed(vim.deep_equal)
36+
return self._private.observable
3637
end
3738

3839
function SignalValue:map(map_fn)

0 commit comments

Comments
 (0)