mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Implement component lifecycle management in DomLabel. Added isMounted flag to prevent updates after unmounting and ensured proper disconnection of motor step connection during component unmounting, enhancing stability and performance.
This commit is contained in:
parent
5cfc803094
commit
7045c460ab
1 changed files with 14 additions and 1 deletions
|
|
@ -79,6 +79,7 @@ local DomLabel = Roact.Component:extend("DomLabel")
|
|||
function DomLabel:init()
|
||||
local initHeight = self.props.elementHeight:getValue()
|
||||
self.expanded = initHeight > 24
|
||||
self.isMounted = true
|
||||
|
||||
self.motor = Flipper.SingleMotor.new(initHeight)
|
||||
self.binding = bindingUtil.fromMotor(self.motor)
|
||||
|
|
@ -86,7 +87,11 @@ function DomLabel:init()
|
|||
self:setState({
|
||||
renderExpansion = self.expanded,
|
||||
})
|
||||
self.motor:onStep(function(value)
|
||||
self.motorStepConnection = self.motor:onStep(function(value)
|
||||
if not self.isMounted then
|
||||
return
|
||||
end
|
||||
|
||||
local renderExpansion = value > 24
|
||||
|
||||
self.props.setElementHeight(value)
|
||||
|
|
@ -106,6 +111,14 @@ function DomLabel:init()
|
|||
end)
|
||||
end
|
||||
|
||||
function DomLabel:willUnmount()
|
||||
self.isMounted = false
|
||||
if self.motorStepConnection then
|
||||
self.motorStepConnection:disconnect()
|
||||
self.motorStepConnection = nil
|
||||
end
|
||||
end
|
||||
|
||||
function DomLabel:didUpdate(prevProps)
|
||||
if
|
||||
prevProps.instance ~= self.props.instance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue