Skip to content
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

Inconsistent lifecycles of Components bound to the same Instance with "slow" Construct method #127

Open
saintech opened this issue Jan 10, 2023 · 0 comments

Comments

@saintech
Copy link

Documentation of the Start method says:

At this point in time, it is safe to grab other components also bound to the same instance.

And it works perfectly when we use multiple components bound to the same Instance. I like this feature, it looks like Knit's Services/Controllers, but with a focus on game entities. All lifecycles are synchronized.

But it is not true if some components yelds the Construct method (for receiving some data for example):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local Component = require(ReplicatedStorage.Packages.Component)


local Component1 = Component.new({ Tag = "SomeTag" })
local Component2 = Component.new({ Tag = "SomeTag" })
local Component3 = Component.new({ Tag = "SomeTag" })
local Component4 = Component.new({ Tag = "SomeTag" })
local Component5 = Component.new({ Tag = "SomeTag" })

function Component1:Construct()
	wait(0.1)
	print("*** Component1 constructed")
end
function Component1:Start()
	print("*** Component1 started")
	print("Component2:", self:GetComponent(Component2))
	print("Component3:", self:GetComponent(Component3))
	print("Component4:", self:GetComponent(Component4))
	print("Component5:", self:GetComponent(Component5))
end

function Component2:Construct()
	print("*** Component2 constructed")
end
function Component2:Start()
	print("*** Component2 started")
	print("Component1:", self:GetComponent(Component1))
	print("Component3:", self:GetComponent(Component3))
	print("Component4:", self:GetComponent(Component4))
	print("Component5:", self:GetComponent(Component5))
end

function Component3:Construct()
	print("*** Component3 constructed")
end
function Component3:Start()
	print("*** Component3 started")
	print("Component1:", self:GetComponent(Component1))
	print("Component2:", self:GetComponent(Component2))
	print("Component4:", self:GetComponent(Component4))
	print("Component5:", self:GetComponent(Component5))
end

function Component4:Construct()
	print("*** Component4 constructed")
end
function Component4:Start()
	print("*** Component4 started")
	print("Component1:", self:GetComponent(Component1))
	print("Component2:", self:GetComponent(Component2))
	print("Component3:", self:GetComponent(Component3))
	print("Component5:", self:GetComponent(Component5))
end

function Component5:Construct()
	print("*** Component5 constructed")
end
function Component5:Start()
	print("*** Component5 started")
	print("Component1:", self:GetComponent(Component1))
	print("Component2:", self:GetComponent(Component2))
	print("Component3:", self:GetComponent(Component3))
	print("Component4:", self:GetComponent(Component4))
end

CollectionService:AddTag(workspace:GetChildren()[1], "SomeTag")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant