-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
145 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local Vinum = require(game.ReplicatedStorage.Vinum) | ||
|
||
local Hold = Vinum.Hold | ||
local Mirror = Vinum.Mirror | ||
local JustOk = Vinum.JustOk | ||
|
||
return { | ||
{ | ||
name = "creating a mirror object", | ||
calls = 50000, | ||
|
||
preRun = function() | ||
return Hold(true, JustOk), Hold(false, JustOk) | ||
end, | ||
|
||
run = function(x, y) | ||
Mirror(x, { | ||
["default"] = y | ||
}) | ||
end | ||
}, | ||
{ | ||
name = "updating a mirror object", | ||
calls = 50000, | ||
|
||
|
||
preRun = function() | ||
local x = Hold(true, JustOk) | ||
local y = Hold(false, JustOk) | ||
|
||
local miObj = Mirror(x, { | ||
["default"] = y | ||
}) | ||
|
||
miObj._currentCaseDependency = Hold("hi", JustOk) | ||
return miObj | ||
end, | ||
|
||
run = function(miObj) | ||
miObj:_update() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
local graph = require(script.Parent.utils.graph) | ||
local Symbols = require(script.Parent.utils.Symbols) | ||
|
||
local class = { type = "state", kind = "mirror" } | ||
local meta = { __index = class } | ||
|
||
function class:_update() | ||
local cases = self._cases | ||
local chosenArm = cases[self._inputState:get()] or cases["default"] | ||
local currentCaseDependency = self._currentCaseDependency | ||
|
||
if currentCaseDependency ~= chosenArm then | ||
local myGraph = self._graph | ||
|
||
if currentCaseDependency then | ||
local currenGraph = currentCaseDependency._graph | ||
currenGraph._dependentSet[myGraph] = nil | ||
myGraph._dependencySet[currenGraph] = nil | ||
end | ||
|
||
local chosenGraph = chosenArm._graph | ||
chosenGraph._dependentSet[myGraph] = true | ||
myGraph._dependencySet[chosenGraph] = true | ||
|
||
self._currentCaseDependency = chosenArm | ||
end | ||
|
||
self._value = chosenArm:get() | ||
return self._value | ||
end | ||
|
||
function class:get() | ||
return self._value | ||
end | ||
|
||
return function(inputState, cases: { [any]: any }) | ||
local self = setmetatable({ | ||
_isSelfContained = true, | ||
_isStaticDependency = false, | ||
_cases = cases, | ||
_value = Symbols.None, | ||
_inputState = inputState, | ||
_currentCaseDependency = false, | ||
}, meta) | ||
|
||
self._graph = graph(self) | ||
local myGraph = self._graph | ||
|
||
inputState._graph._dependentSet[myGraph] = true | ||
|
||
myGraph:update() | ||
return self | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
local Vinum = require(game.ReplicatedStorage.Vinum) | ||
|
||
local Mirror = Vinum.Mirror | ||
local Hold = Vinum.Hold | ||
local JustOk = Vinum.JustOk | ||
|
||
return { | ||
["Should construct a Mirror object"] = function(tester) | ||
local expect = tester.expect | ||
local miObj = Mirror(Hold(true, JustOk), { | ||
[true] = Hold(20), | ||
["default"] = Hold("doesn'tExist", JustOk), | ||
}) | ||
|
||
expect(miObj.type).to.equal("state") | ||
expect(miObj).to.be.a("table") | ||
expect(miObj.kind).to.equal("mirror") | ||
end, | ||
["Should change once InputState fires"] = function(tester) | ||
local expect = tester.expect | ||
|
||
local root = Hold(true, JustOk) | ||
local miObj = Mirror(root, { | ||
[true] = Hold(20), | ||
["default"] = Hold("doesn'tExist", JustOk), | ||
}) | ||
|
||
expect(miObj:get()).to.equal(20) | ||
root:set(false) | ||
expect(miObj:get()).to.equal("doesn'tExist") | ||
end, | ||
["Should change once a Case Object changes"] = function(tester) | ||
local expect = tester.expect | ||
|
||
local root = Hold(true, JustOk) | ||
local trueCase = Hold(20, JustOk) | ||
local miObj = Mirror(root, { | ||
[true] = trueCase, | ||
["default"] = Hold("doesn'tExist", JustOk), | ||
}) | ||
|
||
expect(miObj:get()).to.equal(20) | ||
trueCase:set(30) | ||
expect(miObj:get()).to.equal(30) | ||
|
||
end | ||
} |