From 5b2674e89b7a45ac6217084488efb94731e4ddcf Mon Sep 17 00:00:00 2001 From: Colin Miller Date: Sat, 27 Apr 2024 23:50:09 -0500 Subject: [PATCH 1/3] Added Component:GetPropertyChangedSignal() --- modules/component/init.lua | 25 +++++++++++++++++++++++++ modules/component/wally.toml | 6 +++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/modules/component/init.lua b/modules/component/init.lua index ad0735af..66fd5ece 100644 --- a/modules/component/init.lua +++ b/modules/component/init.lua @@ -318,6 +318,17 @@ function Component.new(config: ComponentConfig) end function Component:_instantiate(instance: Instance) + self.__newindex = function(_, key, value) + if self._propertyChangedSignal then + if type(key) == "string" then + local firstChar = string.sub(key, 1, 1) + if firstChar ~= "_" and firstChar == string.upper(firstChar) then + self._propertyChangedSignal:Fire(key, value) + end + end + end + rawset(self, key, value) + end local component = setmetatable({}, self) component.Instance = instance component[KEY_ACTIVE_EXTENSIONS] = GetActiveExtensions(component, self[KEY_EXTENSIONS]) @@ -340,6 +351,8 @@ function Component:_setup() InvokeExtensionFn(component, "Starting") + component._propertyChangedSignal = Signal.new() + component:Start() if component[KEY_STARTING] == nil then -- Component's Start method stopped the component @@ -415,6 +428,8 @@ function Component:_setup() RunService:UnbindFromRenderStep(component._renderName) end + component._propertyChangedSignal:Destroy() + InvokeExtensionFn(component, "Stopping") component:Stop() InvokeExtensionFn(component, "Stopped") @@ -752,6 +767,16 @@ end ``` ]=] +function Component:GetPropertyChangedSignal(propertyName: string) + local signal = Signal.new() + self._propertyChangedSignal:Connect(function(key, value) + if key == propertyName then + signal:Fire(value) + end + end) + return signal +end + function Component:Destroy() self[KEY_TROVE]:Destroy() end diff --git a/modules/component/wally.toml b/modules/component/wally.toml index 3c745b3a..0bc6f5d6 100644 --- a/modules/component/wally.toml +++ b/modules/component/wally.toml @@ -1,9 +1,9 @@ [package] -name = "sleitnick/component" +name = "snarlyzoo/component" description = "Component class" -version = "2.4.8" +version = "2.5.1" license = "MIT" -authors = ["Stephen Leitnick"] +authors = ["Stephen Leitnick", "Colin Miller"] registry = "https://github.com/UpliftGames/wally-index" realm = "shared" From 2488ccc9f689b7959bf707dbf8b4493f2ad3697c Mon Sep 17 00:00:00 2001 From: Colin Miller Date: Sat, 27 Apr 2024 23:52:18 -0500 Subject: [PATCH 2/3] Don't give me credit --- modules/component/wally.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/component/wally.toml b/modules/component/wally.toml index 0bc6f5d6..b75cd5ce 100644 --- a/modules/component/wally.toml +++ b/modules/component/wally.toml @@ -1,9 +1,9 @@ [package] -name = "snarlyzoo/component" +name = "sleitnick/component" description = "Component class" -version = "2.5.1" +version = "2.5.0" license = "MIT" -authors = ["Stephen Leitnick", "Colin Miller"] +authors = ["Stephen Leitnick"] registry = "https://github.com/UpliftGames/wally-index" realm = "shared" From 717a98ff763980248ca885044fe0024cdb10d3e9 Mon Sep 17 00:00:00 2001 From: Colin Miller <70069885+SnarlyZoo@users.noreply.github.com> Date: Sun, 28 Apr 2024 01:19:52 -0500 Subject: [PATCH 3/3] Fixed __newindex issue --- modules/component/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/component/init.lua b/modules/component/init.lua index 66fd5ece..bc27c377 100644 --- a/modules/component/init.lua +++ b/modules/component/init.lua @@ -318,16 +318,16 @@ function Component.new(config: ComponentConfig) end function Component:_instantiate(instance: Instance) - self.__newindex = function(_, key, value) - if self._propertyChangedSignal then + self.__newindex = function(tbl, key, value) + if tbl._propertyChangedSignal then if type(key) == "string" then local firstChar = string.sub(key, 1, 1) if firstChar ~= "_" and firstChar == string.upper(firstChar) then - self._propertyChangedSignal:Fire(key, value) + tbl._propertyChangedSignal:Fire(key, value) end end end - rawset(self, key, value) + rawset(tbl, key, value) end local component = setmetatable({}, self) component.Instance = instance