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

Commit

Permalink
Merge 3ddc49c into f55538b
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoteTheMighty committed Apr 23, 2020
2 parents f55538b + 3ddc49c commit b1f251c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/createContext.lua
Expand Up @@ -91,7 +91,9 @@ local function createConsumer(context)
-- Store the value that we most recently updated with.
--
-- This value is compared in the contextEntry onUpdate hook below.
self.lastValue = self.contextEntry.value
if self.contextEntry ~= nil then
self.lastValue = self.contextEntry.value
end
end

function Consumer:didMount()
Expand Down
21 changes: 21 additions & 0 deletions src/createContext.spec.lua
Expand Up @@ -173,6 +173,27 @@ return function()

noopReconciler.unmountVirtualTree(tree)
end)

it("should behave correctly when the default value is nil", function()
local context = createContext(nil)

local valueSpy = createSpy()
local function Listener()
return createElement(context.Consumer, {
render = valueSpy.value,
})
end

local tree = noopReconciler.mountVirtualTree(createElement(Listener), nil, "Provide Tree")
expect(valueSpy.callCount).to.equal(1)
valueSpy:assertCalledWith(nil)

tree = noopReconciler.updateVirtualTree(tree, createElement(Listener))
noopReconciler.unmountVirtualTree(tree)

expect(valueSpy.callCount).to.equal(2)
valueSpy:assertCalledWith(nil)
end)
end)

describe("Update order", function()
Expand Down

0 comments on commit b1f251c

Please sign in to comment.