mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 06:35:39 +00:00
plugin: Switch to Roact refactored bindings branch, with real joinBindings!
This commit is contained in:
@@ -80,8 +80,7 @@ function App:init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function App:render()
|
function App:render()
|
||||||
-- FIXME: https://github.com/Roblox/roact/issues/209
|
local children
|
||||||
local children = {}
|
|
||||||
|
|
||||||
if self.state.sessionStatus == SessionStatus.Connected then
|
if self.state.sessionStatus == SessionStatus.Connected then
|
||||||
children = {
|
children = {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ local Config = require(Plugin.Config)
|
|||||||
local Version = require(Plugin.Version)
|
local Version = require(Plugin.Version)
|
||||||
local Assets = require(Plugin.Assets)
|
local Assets = require(Plugin.Assets)
|
||||||
local Theme = require(Plugin.Theme)
|
local Theme = require(Plugin.Theme)
|
||||||
local joinBindings = require(Plugin.joinBindings)
|
|
||||||
|
|
||||||
local FitList = require(Plugin.Components.FitList)
|
local FitList = require(Plugin.Components.FitList)
|
||||||
local FitText = require(Plugin.Components.FitText)
|
local FitText = require(Plugin.Components.FitText)
|
||||||
@@ -24,19 +23,6 @@ function ConnectPanel:init()
|
|||||||
self.footerSize, self.setFooterSize = Roact.createBinding(Vector2.new())
|
self.footerSize, self.setFooterSize = Roact.createBinding(Vector2.new())
|
||||||
self.footerVersionSize, self.setFooterVersionSize = 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({
|
self:setState({
|
||||||
address = "",
|
address = "",
|
||||||
port = "",
|
port = "",
|
||||||
@@ -230,7 +216,12 @@ function ConnectPanel:render()
|
|||||||
LogoContainer = e("Frame", {
|
LogoContainer = e("Frame", {
|
||||||
BackgroundTransparency = 1,
|
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", {
|
Logo = e("ImageLabel", {
|
||||||
Image = Assets.Images.Logo,
|
Image = Assets.Images.Logo,
|
||||||
|
|||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user