From 78ecde4b8715275a58bc68e5002cd6f4e778bd46 Mon Sep 17 00:00:00 2001 From: Lily Brown Date: Fri, 1 Mar 2019 14:26:13 -0800 Subject: [PATCH 1/3] set up rojo 0.5.x --- .gitignore | 3 ++- roblox-project.json | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 roblox-project.json diff --git a/.gitignore b/.gitignore index a96d1d78..4cd5846a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /luacov.* -/site \ No newline at end of file +/site +*.rbxlx \ No newline at end of file diff --git a/roblox-project.json b/roblox-project.json new file mode 100644 index 00000000..affa91ee --- /dev/null +++ b/roblox-project.json @@ -0,0 +1,45 @@ +{ + "name": "roact", + "tree": { + "$className": "DataModel", + "ReplicatedStorage": { + "$className": "ReplicatedStorage", + "Roact": { + "$path": "lib" + }, + "TestEZ": { + "$path": "modules/testez/lib" + } + }, + "ServerScriptService": { + "$className": "ServerScriptService", + "RoactBenchmark": { + "$path": "benchmarks" + }, + "RoactTests": { + "$path": "bin/run-tests.server.lua" + } + }, + "StarterPlayer": { + "$className": "StarterPlayer", + "StarterPlayerScripts": { + "$className": "StarterPlayerScripts", + "RoactTestClient": { + "$path": "client" + }, + "RoactExamples": { + "$path": "examples" + } + } + }, + "HttpService": { + "$className": "HttpService", + "$properties": { + "HttpEnabled": { + "Type": "Bool", + "Value": true + } + } + } + } +} \ No newline at end of file From 1aa49e2b9074e8a9f40f618948f33aa98844fc35 Mon Sep 17 00:00:00 2001 From: Lily Brown Date: Fri, 1 Mar 2019 14:26:23 -0800 Subject: [PATCH 2/3] tag attribute --- lib/PropMarkers/Tag.lua | 5 ++++ lib/RobloxRenderer.lua | 21 ++++++++++++++-- lib/RobloxRenderer.spec.lua | 48 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 lib/PropMarkers/Tag.lua diff --git a/lib/PropMarkers/Tag.lua b/lib/PropMarkers/Tag.lua new file mode 100644 index 00000000..0e2fd857 --- /dev/null +++ b/lib/PropMarkers/Tag.lua @@ -0,0 +1,5 @@ +local Symbol = require(script.Parent.Parent.Symbol) + +local Tag = Symbol.named("Tag") + +return Tag \ No newline at end of file diff --git a/lib/RobloxRenderer.lua b/lib/RobloxRenderer.lua index 339a6158..6f62837e 100644 --- a/lib/RobloxRenderer.lua +++ b/lib/RobloxRenderer.lua @@ -4,12 +4,15 @@ renderer that does anything. ]] +local CollectionService = game:GetService("CollectionService") + local Binding = require(script.Parent.Binding) local Children = require(script.Parent.PropMarkers.Children) local ElementKind = require(script.Parent.ElementKind) local SingleEventManager = require(script.Parent.SingleEventManager) local getDefaultInstanceProperty = require(script.Parent.getDefaultInstanceProperty) local Ref = require(script.Parent.PropMarkers.Ref) +local Tag = require(script.Parent.PropMarkers.Tag) local Type = require(script.Parent.Type) local applyPropsError = [[ @@ -90,8 +93,8 @@ local function applyProp(virtualNode, key, newValue, oldValue) return end - if key == Ref or key == Children then - -- Refs and children are handled in a separate pass + if key == Ref or key == Children or key == Tag then + -- Refs, children, and tags are handled in a separate pass return end @@ -194,6 +197,10 @@ function RobloxRenderer.mountHostNode(reconciler, virtualNode) virtualNode.hostObject = instance applyRef(element.props[Ref], instance) + + if element.props[Tag] ~= nil then + CollectionService:AddTag(instance, element.props[Tag]) + end end function RobloxRenderer.unmountHostNode(reconciler, virtualNode) @@ -220,6 +227,16 @@ function RobloxRenderer.updateHostNode(reconciler, virtualNode, newElement) applyRef(newProps[Ref], virtualNode.hostObject) end + if oldProps[Tag] ~= newProps[Tag] then + if oldProps[Tag] ~= nil then + CollectionService:RemoveTag(virtualNode.hostObject, oldProps[Tag]) + end + + if newProps[Tag] ~= nil then + CollectionService:AddTag(virtualNode.hostObject, newProps[Tag]) + end + end + local success, errorMessage = pcall(updateProps, virtualNode, oldProps, newProps) if not success then diff --git a/lib/RobloxRenderer.spec.lua b/lib/RobloxRenderer.spec.lua index 15d51764..fe25a245 100644 --- a/lib/RobloxRenderer.spec.lua +++ b/lib/RobloxRenderer.spec.lua @@ -1,4 +1,6 @@ return function() + local CollectionService = game:GetService("CollectionService") + local assertDeepEqual = require(script.Parent.assertDeepEqual) local Binding = require(script.Parent.Binding) local Children = require(script.Parent.PropMarkers.Children) @@ -11,6 +13,7 @@ return function() local Logging = require(script.Parent.Logging) local Portal = require(script.Parent.Portal) local Ref = require(script.Parent.PropMarkers.Ref) + local Tag = require(script.Parent.PropMarkers.Tag) local RobloxRenderer = require(script.Parent.RobloxRenderer) @@ -736,4 +739,49 @@ return function() }) end) end) + + describe("Tags", function() + it("should be assigned on mount", function() + local parent = Instance.new("Folder") + local ref = createRef() + local tag = "TestTag" + + local element = createElement("Frame", { + [Tag] = tag, + [Ref] = ref, + }) + + local node = reconciler.createVirtualNode(element, parent, "Test") + RobloxRenderer.mountHostNode(reconciler, node) + + expect(CollectionService:HasTag(ref.current, tag)).to.equal(true) + end) + + it("should update properly", function() + local parent = Instance.new("Folder") + local ref = createRef() + local tagA = "TestTag" + local tagB = "OtherTag" + + local element = createElement("Frame", { + [Tag] = tagA, + [Ref] = ref, + }) + + local node = reconciler.createVirtualNode(element, parent, "Test") + RobloxRenderer.mountHostNode(reconciler, node) + + expect(CollectionService:HasTag(ref.current, tagA)).to.equal(true) + + local newElement = createElement("Frame", { + [Tag] = tagB, + [Ref] = ref, + }) + + RobloxRenderer.updateHostNode(reconciler, node, newElement) + + expect(CollectionService:HasTag(ref.current, tagA)).to.equal(false) + expect(CollectionService:HasTag(ref.current, tagB)).to.equal(true) + end) + end) end \ No newline at end of file From 8942711b450f876873fdc4283cfdf628ed03efe7 Mon Sep 17 00:00:00 2001 From: Lily Brown Date: Fri, 1 Mar 2019 14:27:36 -0800 Subject: [PATCH 3/3] move to updated project.json naming scheme --- roblox-project.json => default.project.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename roblox-project.json => default.project.json (100%) diff --git a/roblox-project.json b/default.project.json similarity index 100% rename from roblox-project.json rename to default.project.json