local v=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local E=v("\066\097\115\101\079\098\106\101\099\116")local F=v("\086\097\108\117\101\079\098\106\101\099\116")local N=setmetatable({},E)N.ClassName="\066\111\117\110\100\080\097\114\101\110\116\084\114\097\099\107\101\114"N.__index=N function N.new(v,Q)local c=setmetatable(E.new(),N)c._child=Q or error("\078\111 \099\104\105\108\100")c._binder=v or error("\078\111 \098\105\110\100\101\114")c.Class=F.new()c._maid:GiveTask(c.Class)c._maid:GiveTask((c._binder:GetClassRemovingSignal()):Connect(function(v)if v==c.Class.Value then c.Class.Value=nil end end))c._maid:GiveTask((c._child:GetPropertyChangedSignal("\080\097\114\101\110\116")):Connect(function()c:_update()end))c:_update()return c end function N._update(v)local E=v._child.Parent if not E then v.Class.Value=nil return end v.Class.Value=v._binder:Get(E)end return N
--- Tracks a parent bound to a specific binder
-- @classmod BoundParentTracker

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local BaseObject = require("BaseObject")
local ValueObject = require("ValueObject")

local BoundParentTracker = setmetatable({}, BaseObject)
BoundParentTracker.ClassName = "BoundParentTracker"
BoundParentTracker.__index = BoundParentTracker

function BoundParentTracker.new(binder, child)
	local self = setmetatable(BaseObject.new(), BoundParentTracker)

	self._child = child or error("No child")
	self._binder = binder or error("No binder")

	-- Bound value
	self.Class = ValueObject.new()
	self._maid:GiveTask(self.Class)

	-- Handle instance removing
	self._maid:GiveTask(self._binder:GetClassRemovingSignal():Connect(function(class)
		if class == self.Class.Value then
			self.Class.Value = nil
		end
	end))

	-- Perform update
	self._maid:GiveTask(self._child:GetPropertyChangedSignal("Parent"):Connect(function()
		self:_update()
	end))
	self:_update()

	return self
end

function BoundParentTracker:_update()
	local parent = self._child.Parent
	if not parent then
		self.Class.Value = nil
		return
	end

	self.Class.Value = self._binder:Get(parent)
end

return BoundParentTracker