--[=[
	Runs the given callback once an instance has been parented to the DataModel.

	This is used in particular for adding Gamepad support because Setting
	[GuiService.SelectedObject] requires that an instance be fully parented to
	the DM, which isn't always a guarantee with Roact.

	@within Modules
]=]

local function onInstanceLoaded(instance: Instance, callback: () -> ())
	task.spawn(function()
		while not instance:IsDescendantOf(game) do
			instance.AncestryChanged:Wait()
		end

		callback()
	end)
end

return onInstanceLoaded
