diff --git a/modules/component/init.lua b/modules/component/init.lua index ad0735af..bc27c377 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(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 + tbl._propertyChangedSignal:Fire(key, value) + end + end + end + rawset(tbl, 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..b75cd5ce 100644 --- a/modules/component/wally.toml +++ b/modules/component/wally.toml @@ -1,7 +1,7 @@ [package] name = "sleitnick/component" description = "Component class" -version = "2.4.8" +version = "2.5.0" license = "MIT" authors = ["Stephen Leitnick"] registry = "https://github.com/UpliftGames/wally-index"