plugin: Switch to Roact refactored bindings branch, with real joinBindings!

This commit is contained in:
Lucien Greathouse
2019-05-31 13:23:17 -07:00
parent 51bbab803f
commit 5bd88dc82f
3 changed files with 7 additions and 51 deletions

View File

@@ -80,8 +80,7 @@ function App:init()
end
function App:render()
-- FIXME: https://github.com/Roblox/roact/issues/209
local children = {}
local children
if self.state.sessionStatus == SessionStatus.Connected then
children = {

View File

@@ -7,7 +7,6 @@ local Config = require(Plugin.Config)
local Version = require(Plugin.Version)
local Assets = require(Plugin.Assets)
local Theme = require(Plugin.Theme)
local joinBindings = require(Plugin.joinBindings)
local FitList = require(Plugin.Components.FitList)
local FitText = require(Plugin.Components.FitText)
@@ -24,19 +23,6 @@ function ConnectPanel:init()
self.footerSize, self.setFooterSize = Roact.createBinding(Vector2.new())
self.footerVersionSize, self.setFooterVersionSize = Roact.createBinding(Vector2.new())
-- This is constructed in init because 'joinBindings' is a hack and we'd
-- leak memory constructing it every render. When this kind of feature lands
-- in Roact properly, we can do this inline in render without fear.
self.footerRestSize = joinBindings(
{
self.footerSize,
self.footerVersionSize,
},
function(container, other)
return UDim2.new(0, container.X - other.X - 16, 0, 32)
end
)
self:setState({
address = "",
port = "",
@@ -230,7 +216,12 @@ function ConnectPanel:render()
LogoContainer = e("Frame", {
BackgroundTransparency = 1,
Size = self.footerRestSize,
Size = Roact.joinBindings({
container = self.footerSize,
other = self.footerVersionSize
}):map(function(values)
return UDim2.new(0, values.container.X - values.other.X - 16, 0, 32)
end),
}, {
Logo = e("ImageLabel", {
Image = Assets.Images.Logo,

View File

@@ -1,34 +0,0 @@
--[[
joinBindings is a crazy hack that allows combining multiple Roact bindings
in the same spirit as `map`.
It's implemented in terms of Roact internals that will probably break at
some point; please don't do that or use this module in your own code!
]]
local Binding = require(script:FindFirstAncestor("Rojo").Roact.Binding)
local function evaluate(fun, bindings)
local input = {}
for index, binding in ipairs(bindings) do
input[index] = binding:getValue()
end
return fun(unpack(input, 1, #bindings))
end
local function joinBindings(bindings, joinFunction)
local initialValue = evaluate(joinFunction, bindings)
local binding, setValue = Binding.create(initialValue)
for _, binding in ipairs(bindings) do
Binding.subscribe(binding, function()
setValue(evaluate(joinFunction, bindings))
end)
end
return binding
end
return joinBindings