--[[
	Wrapper component that provides the ConfigurationContext to the child components.
]]

local ConfigurationProvider = Roact.Component:extend("ConfigurationProvider")
function ConfigurationProvider:init()
	assert(
		typeof(self.props.config) == "table",
		"ConfigurationContext requires the `config` prop to be an instance of Configuration"
	)

	self.state = self.props.config.getValues()
	self:_connectUpdateEvent()
end

function ConfigurationProvider:render()
	return Roact.createElement(context.Provider, {
		value = self.state,
	}, self.props[Roact.Children])
end

function ConfigurationProvider:didMount()
	self:_connectUpdateEvent()
end

function ConfigurationProvider:willUnmount()
	if self.changedConn then
		self.changedConn:Disconnect()
		self.changedConn = nil
	end
end
