From 5bd88dc82fd5b5eba97e63fdd21f5594f755a524 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 31 May 2019 13:23:17 -0700 Subject: [PATCH] plugin: Switch to Roact refactored bindings branch, with real joinBindings! --- plugin/src/Components/App.lua | 3 +-- plugin/src/Components/ConnectPanel.lua | 21 +++++----------- plugin/src/joinBindings.lua | 34 -------------------------- 3 files changed, 7 insertions(+), 51 deletions(-) delete mode 100644 plugin/src/joinBindings.lua diff --git a/plugin/src/Components/App.lua b/plugin/src/Components/App.lua index ef561c85..79436972 100644 --- a/plugin/src/Components/App.lua +++ b/plugin/src/Components/App.lua @@ -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 = { diff --git a/plugin/src/Components/ConnectPanel.lua b/plugin/src/Components/ConnectPanel.lua index f1ec4280..9d26215f 100644 --- a/plugin/src/Components/ConnectPanel.lua +++ b/plugin/src/Components/ConnectPanel.lua @@ -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, diff --git a/plugin/src/joinBindings.lua b/plugin/src/joinBindings.lua deleted file mode 100644 index 1dca84a6..00000000 --- a/plugin/src/joinBindings.lua +++ /dev/null @@ -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 \ No newline at end of file