roact
roact copied to clipboard
Allow Roact Bindings to skip property updates
Currently it's not possible to skip a binding property update as Roact does not check what the return is. This eliminates optimization possibilities when ex. sharing a Binding across 500 components, where not all components may need to update their properties depending on what the new data is.
An alternative solution would be to create a binding for each component, but this would increase memory and force further changing of code to make sure bindings are only created once for each unique component.
A proposition to this would be to allow Binding:map to return a unique value which lets Roact know that the property should not be updated, e.g:
Roact.createElement("Frame", {
Size = props.Binding:map(function(Data)
if not Data.Visible then
return Roact.Constant.SkipBindingUpdate
end
return Data.Size
end),
Visible = props.Binding:map(function(Data)
return Data.Visible
end)
})
Of course this is not a final proposition nor am I aware of the design choices which Roact may want to adhere to, so I'm fine with any solutions so long it allows for skipping unnecessary property updates in performance-critical code.
I created a fork and introduced the proposed solution in the commit below: https://github.com/PysephWasntAvailable/roact-constant-fork/commit/53272efd80b1f7e362887418ac68bc1ea8cb3adc