Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
add config.scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorGriffin37 committed May 24, 2021
1 parent d251a1b commit 4b69643
Showing 1 changed file with 52 additions and 46 deletions.
98 changes: 52 additions & 46 deletions src/RobloxRenderer.spec.lua
Expand Up @@ -951,73 +951,79 @@ return function()

describe("Integration Tests", function()
it("should not allow re-entrancy in updateChildren", function()
local ChildComponent = Component:extend("ChildComponent")

function ChildComponent:init()
self:setState({
firstTime = true
})
end
local configValues = {
tempFixUpdateChildrenReEntrancy = true,
}

local childCoroutine
GlobalConfig.scoped(configValues, function()
local ChildComponent = Component:extend("ChildComponent")

function ChildComponent:render()
if self.state.firstTime then
return createElement("Frame")
function ChildComponent:init()
self:setState({
firstTime = true
})
end

return createElement("TextLabel")
end
local childCoroutine

function ChildComponent:didMount()
childCoroutine = coroutine.create(function()
self:setState({
firstTime = false
})
end)
end
function ChildComponent:render()
if self.state.firstTime then
return createElement("Frame")
end

local ParentComponent = Component:extend("ParentComponent")
return createElement("TextLabel")
end

function ParentComponent:init()
self:setState({
count = 1
})
function ChildComponent:didMount()
childCoroutine = coroutine.create(function()
self:setState({
firstTime = false
})
end)
end

local ParentComponent = Component:extend("ParentComponent")

self.childAdded = function()
function ParentComponent:init()
self:setState({
count = self.state.count + 1,
count = 1
})

self.childAdded = function()
self:setState({
count = self.state.count + 1,
})
end
end
end

function ParentComponent:render()
return createElement("Frame", {
[Event.ChildAdded] = self.childAdded,
}, {
ChildComponent = createElement(ChildComponent, {
count = self.state.count
function ParentComponent:render()
return createElement("Frame", {
[Event.ChildAdded] = self.childAdded,
}, {
ChildComponent = createElement(ChildComponent, {
count = self.state.count
})
})
})
end
end

local parent = Instance.new("ScreenGui")
parent.Parent = game.CoreGui
local parent = Instance.new("ScreenGui")
parent.Parent = game.CoreGui

local tree = createElement(ParentComponent)
local tree = createElement(ParentComponent)

local hostKey = "Some Key"
local instance = reconciler.mountVirtualNode(tree, parent, hostKey)
local hostKey = "Some Key"
local instance = reconciler.mountVirtualNode(tree, parent, hostKey)

coroutine.resume(childCoroutine)
coroutine.resume(childCoroutine)

expect(#parent:GetChildren()).to.equal(1)
expect(#parent:GetChildren()).to.equal(1)

local frame = parent:GetChildren()[1]
local frame = parent:GetChildren()[1]

expect(#frame:GetChildren()).to.equal(1)
expect(#frame:GetChildren()).to.equal(1)

reconciler.unmountVirtualNode(instance)
reconciler.unmountVirtualNode(instance)
end)
end)
end)
end

0 comments on commit 4b69643

Please sign in to comment.