-
-
Notifications
You must be signed in to change notification settings - Fork 121
[Tag] #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[Tag] #423
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
54da7d9
Tag
znotfireman 35cffc3
update file comment
znotfireman 938da36
checkLifetime.formatters.boundTag
znotfireman b4a27f3
minor fixes
znotfireman 51f98ea
check for true not truthiness
znotfireman cd6e903
Add Tag tests
dgxo f3199bc
Merge pull request #1 from dgxo/main
znotfireman be0efe5
Merge branch 'main' into main
znotfireman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,61 @@ | ||
| --!strict | ||
| --!nolint LocalUnused | ||
| --!nolint LocalShadow | ||
| local task = nil -- Disable usage of Roblox's task scheduler | ||
|
|
||
| --[[ | ||
| A special key for property tables, which allows users to apply custom | ||
| CollectionService tags to instances | ||
| ]] | ||
|
|
||
| local Package = script.Parent.Parent | ||
| local Types = require(Package.Types) | ||
| -- Memory | ||
| local checkLifetime = require(Package.Memory.checkLifetime) | ||
| -- Graph | ||
| local Observer = require(Package.Graph.Observer) | ||
| -- State | ||
| local castToState = require(Package.State.castToState) | ||
| local peek = require(Package.State.peek) | ||
|
|
||
| local keyCache: { [string]: Types.SpecialKey } = {} | ||
|
|
||
| -- TODO: should this accept tagName: UsedAs<string>? | ||
| local function Tag(tagName: string): Types.SpecialKey | ||
| local key = keyCache[tagName] | ||
| if key == nil then | ||
| key = { | ||
| type = "SpecialKey", | ||
| kind = "Tag", | ||
| stage = "self", | ||
| apply = function(self: Types.SpecialKey, scope: Types.Scope<unknown>, value: unknown, applyTo: Instance) | ||
| if castToState(value) then | ||
| local value = value :: Types.StateObject<unknown> | ||
| checkLifetime.bOutlivesA( | ||
| scope, | ||
| applyTo, | ||
| value.scope, | ||
| value.oldestTask, | ||
| checkLifetime.formatters.boundTag, | ||
| tagName | ||
| ) | ||
| Observer(scope, value :: any):onBind(function() | ||
| if peek(value) == true then | ||
| applyTo:AddTag(tagName) | ||
| elseif applyTo:HasTag(tagName) then | ||
| applyTo:RemoveTag(tagName) | ||
| end | ||
| end) | ||
| else | ||
| if value == true then | ||
| applyTo:AddTag(tagName) | ||
| end | ||
| end | ||
| end, | ||
| } | ||
| keyCache[tagName] = key | ||
| end | ||
| return key | ||
| end | ||
|
|
||
| return Tag |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,51 @@ | ||
| --!strict | ||
| --!nolint LocalUnused | ||
| local task = nil -- Disable usage of Roblox's task scheduler | ||
|
|
||
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
| local Fusion = ReplicatedStorage.Fusion | ||
|
|
||
| local New = require(Fusion.Instances.New) | ||
| local Tag = require(Fusion.Instances.Tag) | ||
| local Value = require(Fusion.State.Value) | ||
| local doCleanup = require(Fusion.Memory.doCleanup) | ||
|
|
||
| return function() | ||
| local it = getfenv().it | ||
|
|
||
| it("adds tags (constant)", function() | ||
| local expect = getfenv().expect | ||
|
|
||
| local scope = {} | ||
| local child = New(scope, "Folder") { | ||
| [Tag "Foo"] = true | ||
| } | ||
| expect(child:HasTag("Foo")).to.equal(true) | ||
| doCleanup(scope) | ||
| end) | ||
|
|
||
| it("adds tags (state)", function() | ||
| local expect = getfenv().expect | ||
|
|
||
| local scope = {} | ||
| local addTag = Value(scope, true) | ||
| local child = New(scope, "Folder") { | ||
| [Tag "Foo"] = addTag | ||
| } | ||
| expect(child:HasTag("Foo")).to.equal(true) | ||
| end) | ||
|
|
||
| it("adds/removes tag when state objects are updated", function() | ||
| local expect = getfenv().expect | ||
|
|
||
| local scope = {} | ||
| local tagExists = Value(scope, true) | ||
| local child = New(scope, "Folder") { | ||
| [Tag "Foo"] = tagExists | ||
| } | ||
| expect(child:HasTag("Foo")).to.equal(true) | ||
| tagExists:set(false) | ||
| expect(child:HasTag("Foo")).to.equal(false) | ||
| doCleanup(scope) | ||
| end) | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.