Skip to main content

Component

Used to declare a module as a Seam component class.

TypeSinceScoped
Declaration0.3.0No

Usage

Components in Seam are modified modules that are converted from functional dictionaries to a mock-OOP setup.

Somewhere in your script, declare Component as a variable:

local Component = Seam.Component

All components require Init() and Construct() methods (both passing in scope and properties, respectively), and then returns Component(Module). Init() can be used to initialize the object of the class, while Construct() returns the class instance.

Below is an example of a button component module:

local ButtonComponent = {}

local Seam = require(Path.To.Seam)
local Component = Seam.Component
local New = Seam.New
local OnEvent = Seam.OnEvent

function ButtonComponent:Init(Scope, Properties)
self.Clicks = 0
end

function ButtonComponent:Construct(Scope, Properties)
return Scope:New("TextButton", {
-- Other properties, etc...
Text = Properties.Text,

[OnEvent "Activated"] = function()
self:Click()
end,
})
end

function ButtonComponent:Click()
self.Clicks += 1
print("Clicked! Total clicks: " .. self.Clicks)
end

return Component(ButtonComponent)