This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
146cb34
commit b25a063
Showing
8 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,86 @@ | ||
return function() | ||
local Core = require(script.Parent.Core) | ||
local Reconciler = require(script.Parent.Reconciler) | ||
local createRef = require(script.Parent.createRef) | ||
|
||
it("should mount booleans as nil", function() | ||
local booleanReified = Reconciler.mount(false) | ||
expect(booleanReified).to.never.be.ok() | ||
end) | ||
|
||
it("should handle object references properly", function() | ||
local objectRef = createRef() | ||
local element = Core.createElement("StringValue", { | ||
[Core.Ref] = objectRef, | ||
}) | ||
|
||
local handle = Reconciler.mount(element) | ||
expect(objectRef.current).to.be.ok() | ||
Reconciler.unmount(handle) | ||
expect(objectRef.current).to.never.be.ok() | ||
end) | ||
|
||
it("should handle function references properly", function() | ||
local currentRbx | ||
|
||
local function ref(rbx) | ||
currentRbx = rbx | ||
end | ||
|
||
local element = Core.createElement("StringValue", { | ||
[Core.Ref] = ref, | ||
}) | ||
|
||
local handle = Reconciler.mount(element) | ||
expect(currentRbx).to.be.ok() | ||
Reconciler.unmount(handle) | ||
expect(currentRbx).to.never.be.ok() | ||
end) | ||
|
||
it("should handle changing function references", function() | ||
local aValue, bValue | ||
|
||
local function aRef(rbx) | ||
aValue = rbx | ||
end | ||
|
||
local function bRef(rbx) | ||
bValue = rbx | ||
end | ||
|
||
local element = Core.createElement("StringValue", { | ||
[Core.Ref] = aRef, | ||
}) | ||
|
||
local handle = Reconciler.mount(element, game, "Test123") | ||
expect(aValue).to.be.ok() | ||
expect(bValue).to.never.be.ok() | ||
handle = Reconciler.reconcile(handle, Core.createElement("StringValue", { | ||
[Core.Ref] = bRef, | ||
})) | ||
expect(aValue).to.never.be.ok() | ||
expect(bValue).to.be.ok() | ||
Reconciler.unmount(handle) | ||
expect(bValue).to.never.be.ok() | ||
end) | ||
|
||
it("should handle changing object references", function() | ||
local aRef = createRef() | ||
local bRef = createRef() | ||
|
||
local element = Core.createElement("StringValue", { | ||
[Core.Ref] = aRef, | ||
}) | ||
|
||
local handle = Reconciler.mount(element, game, "Test123") | ||
expect(aRef.current).to.be.ok() | ||
expect(bRef.current).to.never.be.ok() | ||
handle = Reconciler.reconcile(handle, Core.createElement("StringValue", { | ||
[Core.Ref] = bRef, | ||
})) | ||
expect(aRef.current).to.never.be.ok() | ||
expect(bRef.current).to.be.ok() | ||
Reconciler.unmount(handle) | ||
expect(bRef.current).to.never.be.ok() | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--[[ | ||
Provides an API for acquiring a reference to a reified object. This | ||
API is designed to mimic React 16.3's createRef API. | ||
See: | ||
* https://reactjs.org/docs/refs-and-the-dom.html | ||
* https://reactjs.org/blog/2018/03/29/react-v-16-3.html#createref-api | ||
]] | ||
|
||
local refMetatable = { | ||
__tostring = function(self) | ||
return ("RoactReference(%s)"):format(tostring(self.current)) | ||
end, | ||
} | ||
|
||
return function() | ||
return setmetatable({ | ||
current = nil, | ||
}, refMetatable) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
return function() | ||
local createRef = require(script.Parent.createRef) | ||
|
||
it("should create refs", function() | ||
expect(createRef()).to.be.ok() | ||
end) | ||
|
||
it("should support tostring on refs", function() | ||
local ref = createRef() | ||
expect(tostring(ref)).to.equal("RoactReference(nil)") | ||
|
||
ref.current = "foo" | ||
expect(tostring(ref)).to.equal("RoactReference(foo)") | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters