forked from rojo-rbx/rojo
plugin: Migrate 'merge' utility into Dictionary module
This commit is contained in:
@@ -1,23 +1,9 @@
|
||||
local Roact = require(script:FindFirstAncestor("Rojo").Roact)
|
||||
|
||||
local Dictionary = require(script.Parent.Parent.Dictionary)
|
||||
|
||||
local e = Roact.createElement
|
||||
|
||||
local function merge(...)
|
||||
local output = {}
|
||||
|
||||
for i = 1, select("#", ...) do
|
||||
local source = select(i, ...)
|
||||
|
||||
if source ~= nil then
|
||||
for key, value in pairs(source) do
|
||||
output[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return output
|
||||
end
|
||||
|
||||
local FitList = Roact.Component:extend("FitList")
|
||||
|
||||
function FitList:init()
|
||||
@@ -34,8 +20,8 @@ function FitList:render()
|
||||
padding = e("UIPadding", paddingProps)
|
||||
end
|
||||
|
||||
local children = merge(self.props[Roact.Children], {
|
||||
["$Layout"] = e("UIListLayout", merge({
|
||||
local children = Dictionary.merge(self.props[Roact.Children], {
|
||||
["$Layout"] = e("UIListLayout", Dictionary.merge({
|
||||
SortOrder = Enum.SortOrder.LayoutOrder,
|
||||
[Roact.Change.AbsoluteContentSize] = function(instance)
|
||||
local size = instance.AbsoluteContentSize
|
||||
@@ -53,7 +39,7 @@ function FitList:render()
|
||||
["$Padding"] = padding,
|
||||
})
|
||||
|
||||
local fullContainerProps = merge(containerProps, {
|
||||
local fullContainerProps = Dictionary.merge(containerProps, {
|
||||
Size = self.sizeBinding,
|
||||
})
|
||||
|
||||
|
||||
@@ -2,29 +2,10 @@ local TextService = game:GetService("TextService")
|
||||
|
||||
local Roact = require(script:FindFirstAncestor("Rojo").Roact)
|
||||
|
||||
local Dictionary = require(script.Parent.Parent.Dictionary)
|
||||
|
||||
local e = Roact.createElement
|
||||
|
||||
local None = newproxy(false)
|
||||
local function merge(...)
|
||||
local output = {}
|
||||
|
||||
for i = 1, select("#", ...) do
|
||||
local source = select(i, ...)
|
||||
|
||||
if source ~= nil then
|
||||
for key, value in pairs(source) do
|
||||
if value == None then
|
||||
output[key] = nil
|
||||
else
|
||||
output[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return output
|
||||
end
|
||||
|
||||
local FitText = Roact.Component:extend("FitText")
|
||||
|
||||
function FitText:init()
|
||||
@@ -34,9 +15,9 @@ end
|
||||
function FitText:render()
|
||||
local kind = self.props.Kind
|
||||
|
||||
local containerProps = merge(self.props, {
|
||||
Kind = None,
|
||||
Padding = None,
|
||||
local containerProps = Dictionary.merge(self.props, {
|
||||
Kind = Dictionary.None,
|
||||
Padding = Dictionary.None,
|
||||
Size = self.sizeBinding
|
||||
})
|
||||
|
||||
|
||||
33
plugin/src/Dictionary.lua
Normal file
33
plugin/src/Dictionary.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
--[[
|
||||
This is a placeholder module waiting for Cryo to become available.
|
||||
]]
|
||||
|
||||
local None = newproxy(true)
|
||||
getmetatable(None).__tostring = function()
|
||||
return "None"
|
||||
end
|
||||
|
||||
local function merge(...)
|
||||
local output = {}
|
||||
|
||||
for i = 1, select("#", ...) do
|
||||
local source = select(i, ...)
|
||||
|
||||
if source ~= nil then
|
||||
for key, value in pairs(source) do
|
||||
if value == None then
|
||||
output[key] = nil
|
||||
else
|
||||
output[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return output
|
||||
end
|
||||
|
||||
return {
|
||||
None = None,
|
||||
merge = merge,
|
||||
}
|
||||
Reference in New Issue
Block a user