From 0c42af004efaaed1ea2e8ad3f62cadb6dfadeeb4 Mon Sep 17 00:00:00 2001 From: Marcin Dziewulski Date: Thu, 18 Apr 2024 23:18:50 +0200 Subject: [PATCH 1/2] fix: ensure that only the relevant signal value is emitted --- lua/nui-components/signal/init.lua | 2 +- lua/nui-components/signal/value.lua | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/nui-components/signal/init.lua b/lua/nui-components/signal/init.lua index 9446bd5..f6cdd92 100644 --- a/lua/nui-components/signal/init.lua +++ b/lua/nui-components/signal/init.lua @@ -47,7 +47,7 @@ function Signal.create(object) end, __newindex = function(t, key, value) t[self.__index][key] = value - self._private.subject(t[self.__index]) + self._private.subject(t[self.__index], key) end, }) diff --git a/lua/nui-components/signal/value.lua b/lua/nui-components/signal/value.lua index 90238ae..646166d 100644 --- a/lua/nui-components/signal/value.lua +++ b/lua/nui-components/signal/value.lua @@ -10,9 +10,13 @@ function SignalValue.create(subject, key) _private = { key = key, subject = subject, - observable = subject:map(function(value) - return value[key] - end), + observable = subject + :filter(function(_, k) + return k == nil or k == key + end) + :map(function(value) + return value[key] + end), }, } From 33955125b9b11fe8e4471ee174f08b6779a4625c Mon Sep 17 00:00:00 2001 From: Marcin Dziewulski Date: Fri, 19 Apr 2024 17:37:35 +0200 Subject: [PATCH 2/2] fix: ensure that only the relevant signal value is emitted (part 2) --- lua/nui-components/signal/init.lua | 2 +- lua/nui-components/signal/value.lua | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/nui-components/signal/init.lua b/lua/nui-components/signal/init.lua index f6cdd92..9446bd5 100644 --- a/lua/nui-components/signal/init.lua +++ b/lua/nui-components/signal/init.lua @@ -47,7 +47,7 @@ function Signal.create(object) end, __newindex = function(t, key, value) t[self.__index][key] = value - self._private.subject(t[self.__index], key) + self._private.subject(t[self.__index]) end, }) diff --git a/lua/nui-components/signal/value.lua b/lua/nui-components/signal/value.lua index 646166d..b177797 100644 --- a/lua/nui-components/signal/value.lua +++ b/lua/nui-components/signal/value.lua @@ -1,3 +1,4 @@ +local Observable = require("nui-components.rx.observable") local fn = require("nui-components.utils.fn") local SignalValue = {} @@ -10,13 +11,13 @@ function SignalValue.create(subject, key) _private = { key = key, subject = subject, - observable = subject - :filter(function(_, k) - return k == nil or k == key - end) - :map(function(value) - return value[key] - end), + observable = Observable.defer(function() + return subject + :map(function(value) + return value[key] + end) + :distinct_until_changed(vim.deep_equal) + end), }, } @@ -32,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)