-
Notifications
You must be signed in to change notification settings - Fork 2
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
14 changed files
with
202 additions
and
230 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
File renamed without changes.
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,107 @@ | ||
-- Variables | ||
local Root = script.Parent | ||
local Types = require(Root.Types) | ||
local Debugger = require(Root.Parent.roblox_packages.debugger) | ||
|
||
local Class = {} | ||
|
||
-- Functions | ||
|
||
--[=[ | ||
Gets the current value of a value object for use within the compute. | ||
[Learn More](https://luminlabsdev.github.io/ui-framework/api/computed/#use) | ||
]=] | ||
local function Use(value: Types.State | any) | ||
if type(value) == "table" then | ||
return value:Get() | ||
else | ||
return value | ||
end | ||
end | ||
|
||
local function Listener(self: Types.Computed) | ||
return function() | ||
self._Value = self._Processor(Use) | ||
|
||
if self._Instances ~= nil then | ||
for prop, instance in self._Instances do | ||
(instance :: any)[prop] = self._Value | ||
end | ||
end | ||
end | ||
end | ||
|
||
--[=[ | ||
Gets the current value of the compute object. | ||
[Learn More](https://luminlabsdev.github.io/ui-framework/api/computed/#get) | ||
]=] | ||
function Class.Get(self: Types.Computed): any | ||
return self._Value | ||
end | ||
|
||
function Class._Bind(self: Types.Computed, prop: string, instance: Instance) | ||
if self._Instances == nil then | ||
self._Instances = {} | ||
end | ||
|
||
(self._Instances :: {})[prop] = instance; | ||
(instance :: any)[prop] = self._Value | ||
end | ||
|
||
--[=[ | ||
Destroys the compute object. | ||
[Learn More](https://luminlabsdev.github.io/ui-framework/api/computed/#destroy) | ||
]=] | ||
function Class.Destroy(self: Types.Computed) | ||
if self._Dependencies then | ||
for dependency: any, disconnect: any in self._Dependencies do | ||
disconnect() | ||
self._Dependencies[dependency] = nil | ||
end | ||
end | ||
|
||
table.clear(self :: any) | ||
setmetatable(self :: any, nil) | ||
end | ||
|
||
-- Module | ||
|
||
--[=[ | ||
Creates a new computed value, which changes the final value when a dependency is changed. | ||
[Learn More](https://luminlabsdev.github.io/ui-framework/api/#computed) | ||
]=] | ||
return function( | ||
processor: (use: (value: Types.State | any) -> ()) -> (), | ||
dependencies: { Types.State | Types.Spring }? | ||
): Types.ComputedExport | ||
local self = setmetatable({}, { __index = Class }) | ||
|
||
self._Type = "Computed" | ||
self._Processor = processor | ||
self._Value = processor(Use) | ||
self._Instances = {} | ||
self._Dependencies = nil | ||
|
||
if dependencies then | ||
local Type = type(dependencies) | ||
Debugger.Assert(Type == "table", "InvalidType", "table", Type) | ||
self._Dependencies = {} :: any | ||
for _, dependency in dependencies do | ||
if type(dependency) == "table" then | ||
if dependency._Type == "Spring" then | ||
(self._Dependencies :: any)[dependency] = (dependency :: any)._Goal:Listen(Listener(self :: any)) | ||
elseif dependency._Type == "State" then | ||
(self._Dependencies :: any)[dependency] = (dependency :: any):Listen(Listener(self :: any)) | ||
else | ||
Debugger.Fatal("InvalidType", "state or spring", type(dependency)) | ||
end | ||
end | ||
end | ||
end | ||
|
||
return self :: any | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.