-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from Elttob/pr-820hydrate
Implement instance hydration
- Loading branch information
Showing
5 changed files
with
60 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--!strict | ||
|
||
--[[ | ||
Processes and returns an existing instance, with options for setting | ||
properties, event handlers and other attributes on the instance. | ||
]] | ||
|
||
local Package = script.Parent.Parent | ||
local PubTypes = require(Package.PubTypes) | ||
local semiWeakRef = require(Package.Instances.semiWeakRef) | ||
local applyInstanceProps = require(Package.Instances.applyInstanceProps) | ||
|
||
local function Hydrate(target: Instance) | ||
return function(props: PubTypes.PropertyTable): Instance | ||
applyInstanceProps(props, semiWeakRef(target)) | ||
return target | ||
end | ||
end | ||
|
||
return Hydrate |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local Package = game:GetService("ReplicatedStorage").Fusion | ||
local Hydrate = require(Package.Instances.Hydrate) | ||
|
||
return function() | ||
it("should return the instance it was passed", function() | ||
local ins = Instance.new("Folder") | ||
|
||
expect(Hydrate(ins) {}).to.equal(ins) | ||
end) | ||
|
||
it("should apply properties to the instance", function() | ||
local ins = Instance.new("Folder") | ||
|
||
Hydrate(ins) { | ||
Name = "Jeremy" | ||
} | ||
|
||
expect(ins.Name).to.equal("Jeremy") | ||
end) | ||
|
||
it("should not inhibit garbage collection", function() | ||
local ref = setmetatable({}, {__mode = "v"}) | ||
do | ||
ref[1] = Hydrate(Instance.new("Folder")) {} | ||
end | ||
|
||
local startTime = os.clock() | ||
repeat | ||
task.wait() | ||
until ref[1] == nil or os.clock() > startTime + 5 | ||
expect(ref[1]).to.equal(nil) | ||
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