-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I got this idea from this issue, dphfox/Fusion#124 This does make working with templates a lot nicer and simple, but I'm still not entirely sure about this design. I've proposed a different method in Instance/Keys/Children.luau.
- Loading branch information
1 parent
62948a5
commit 7da8267
Showing
4 changed files
with
121 additions
and
6 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,19 @@ | ||
local Players = game:GetService 'Players' | ||
local ReplicatedStorage = game:GetService 'ReplicatedStorage' | ||
|
||
local Fusion = require(ReplicatedStorage.Libraries.ConFusion) | ||
local scoped, WithChild = Fusion.scoped, Fusion.WithChild | ||
|
||
local template = ReplicatedStorage:WaitForChild 'Template' | ||
|
||
local scope = scoped(Fusion) | ||
|
||
scope:New(template) { | ||
Parent = Players.LocalPlayer.PlayerGui, | ||
|
||
[WithChild 'Frame'] = { | ||
BackgroundColor3 = Fusion.Clock:map(function(t) | ||
return Color3.fromHSV(t % 1, 1, 1) | ||
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,46 @@ | ||
local package = script.Parent.Parent.Parent | ||
|
||
local External = require(package.External) | ||
local Types = require(package.Types) | ||
|
||
local applyProperties = require(package.Instance.applyProperties) | ||
|
||
local keyCache = {} | ||
|
||
local function WithChild(childName: string): Types.SpecialKey | ||
local key = keyCache[childName] | ||
|
||
if not key then | ||
key = table.freeze { | ||
type = 'children', | ||
kind = 'key', | ||
|
||
apply = function( | ||
scope: Types.Scope, | ||
applyTo: Instance, | ||
properties: Types.Properties | ||
) | ||
local child = applyTo:FindFirstChild(childName) | ||
|
||
if not child then | ||
return External.logErrorNonFatal( | ||
'missingChild', | ||
nil, | ||
childName, | ||
applyTo.Name | ||
) | ||
end | ||
|
||
applyProperties(scope, child, properties) | ||
|
||
return | ||
end, | ||
} | ||
|
||
keyCache[childName] = key | ||
end | ||
|
||
return key | ||
end | ||
|
||
return WithChild |
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