BaseComponent
Properties#
ClassName#
BaseComponent.ClassName: stringThe Component's ClassName, which is assigned from the first argument of Component.Extend.
Destroyed#
BaseComponent.Destroyed: Signal<>?The Destroyed signal which is called after everything in the Component is destroyed. This only exists if you explicitly state you want it in the Component.Extend function.
Destroying#
BaseComponent.Destroying: Signal<>?The Destroying signal which is called immediately after :Destroy is. This only exists if you explicitly state you want it in the Component.Extend function.
DidRedraw#
BaseComponent.DidRedraw: Signal<...RedrawArguments>?The DidRedraw signal which is called immediately after Component:Redraw is. This only exists if you explicitly state you want it in the Component.Extend function.
GetReducedState#
BaseComponent.GetReducedState: () → {[string]: string}This function returns the reduced state of the component's store.
Janitor#
BaseComponent.Janitor: JanitorThe component's Janitor. You can add whatever you want cleaned up on :Destroy() to this.
local PrintOnDestroy = Helium.Component.Extend("PrintOnDestroy")
function PrintOnDestroy:Constructor(Message: string)
self.Janitor:Add(function()
print(Message)
end, true)
end
PrintOnDestroy.new("I was destroyed!"):Destroy() -- Prints "I was destroyed!"
QueueRedraw#
BaseComponent.QueueRedraw: () → ()This function queues a redraw of the component.
local CoinsDisplay = Helium.Component.Extend("CoinsDisplay")
function CoinsDisplay:Constructor(Parent: Instance)
self.Coins = 0
self.Gui = self.Janitor:Add(Helium.Make("TextLabel", {
AnchorPoint = Vector2.new(0.5, 0.5);
BackgroundTransparency = 1;
Position = UDim2.fromScale(0.5, 0.5);
Size = UDim2.fromScale(0.5, 0.5);
Font = Enum.Font.Gotham;
Text = "Coins: 0";
TextColor3 = Color3.new(1, 1, 1);
TextSize = 24;
Parent = Parent;
}), "Destroy")
end
function CoinsDisplay:AddCoin()
self.Coins += 1
self.QueueRedraw() -- Queues the Component to be redrawn.
end
CoinsDisplay.RedrawBinding = Helium.RedrawBinding.Heartbeat
function CoinsDisplay:Redraw()
self.Gui.Text = "Coins: " .. self.Coins
end
local MyCoinsDisplay = CoinsDisplay.new(Parent) -- Shows a TextLabel with the Text == "Coins: 0".
MyCoinsDisplay:AddCoin() -- Now it says "Coins: 1"
RedrawBinding#
BaseComponent.RedrawBinding: RedrawBindingThe Component's RedrawBinding. This is used to determine when the Component's :Redraw() function is called.
Reduction#
BaseComponent.Reduction: {[string]:Â string}?The reduction of the store. If this exists, it'll be passed as the first argument of :Redraw().
WillRedraw#
BaseComponent.WillRedraw: Signal<...RedrawArguments>?The WillRedraw signal which is called immediately before Component:Redraw is. This only exists if you explicitly state you want it in the Component.Extend function.
Functions#
new#
BaseComponent.new(...:Â any?--
The arguments you want to pass to the Component's constructor.
) → Component<T>The constructor of the Component. This version is for store-less components.
local ValuePrinter = Helium.Component.Extend("ValuePrinter")
function ValuePrinter:Constructor(Value: any)
print("ValuePrinter:Constructor was constructed with:", Value)
end
ValuePrinter.new(1):Destroy() -- prints "ValuePrinter:Constructor was constructed with: 1"
new#
BaseComponent.new(Store:Â Store?,--
The store to use for this component.
...:Â any?--
The extra arguments you want to pass to the Component's constructor.
) → Component<T>The constructor of the Component.
local ValuePrinterWithStore = Helium.Component.Extend("ValuePrinterWithStore")
function ValuePrinterWithStore:Constructor(Store, Value: any)
self.Store = Store
print("ValuePrinterWithStore:Constructor was constructed with:", Value)
end
ValuePrinterWithStore.new(Helium.Store.new(function() end, {}), 1):Destroy() -- prints "ValuePrinterWithStore:Constructor was constructed with: 1"
Constructor#
BaseComponent:Constructor(...:Â any?--
The arguments you are creating the Component with.
) → ()The Component's Constructor function. This version is for store-less components. This should be overwritten.
local CoinsDisplay = Helium.Component.Extend("CoinsDisplay")
function CoinsDisplay:Constructor(Parent: Instance)
self.Gui = self.Janitor:Add(Helium.Make("TextLabel", {
AnchorPoint = Vector2.new(0.5, 0.5);
BackgroundTransparency = 1;
Position = UDim2.fromScale(0.5, 0.5);
Size = UDim2.fromScale(0.5, 0.5);
Font = Enum.Font.Gotham;
Text = "Coins: 1";
TextColor3 = Color3.new(1, 1, 1);
TextSize = 24;
Parent = Parent;
}), "Destroy")
end
CoinsDisplay.new(Parent) -- Shows a TextLabel with the Text == "Coins: 1".
Constructor#
BaseComponent:Constructor(Store:Â Store?,--
The store to use for this component.
...:Â any?--
The arguments you are creating the Component with.
) → ()The Component's Constructor function. This should be overwritten.
local CoinsDisplay = Helium.Component.Extend("CoinsDisplay")
function CoinsDisplay:Constructor(Store, Parent: Instance)
self.Store = Store
self.Gui = self.Janitor:Add(Helium.Make("TextLabel", {
AnchorPoint = Vector2.new(0.5, 0.5);
BackgroundTransparency = 1;
Position = UDim2.fromScale(0.5, 0.5);
Size = UDim2.fromScale(0.5, 0.5);
Font = Enum.Font.Gotham;
Text = "Coins: 0";
TextColor3 = Color3.new(1, 1, 1);
TextSize = 24;
Parent = Parent;
}), "Destroy")
end
type CoinsReduction = {Coins: number}
CoinsDisplay.Reduction = {Coins = "GuiData.Coins"}
CoinsDisplay.RedrawBinding = Helium.RedrawBinding.Heartbeat
function CoinsDisplay:Redraw(CoinsReduction: CoinsReduction)
self.Gui.Text = "Coins: " .. CoinsReduction.Coins
end
local CoinsStore = Helium.Store.new(function(Action, GetState, SetState)
if Action.Type == "AddCoin" then
local Coins = GetState("GuiData", "Coins")
SetState("GuiData", "Coins", Coins + 1)
end
end, {GuiData = {Coins = 0}})
local MyCoinsDisplay = CoinsDisplay.new(CoinsStore, Parent) -- Shows a TextLabel with the Text == "Coins: 0".
for _ = 1, 10 do
task.wait(1)
CoinsStore:Fire({Type = "AddCoin"})
end
MyCoinsDisplay:Destroy()
Destroy#
BaseComponent:Destroy() → ()Destroys the Component and its Janitor.
warning
This renders the component completely unusable. You wont' be able to call any further methods on it.
Redraw#
BaseComponent:Redraw(ReducedState:Â {[any]:Â any}?,--
The reduced state if BaseComponent.Reduction exists.
DeltaTime:Â number,--
The DeltaTime since the last frame.
WorldDeltaTime:Â number?--
The world delta time since the last frame. This only exists when RedrawBinding == Stepped.
) → ()The Component's Redraw function. This can be overwritten if you need it to be.
local CoinsDisplay = Helium.Component.Extend("CoinsDisplay")
function CoinsDisplay:Constructor(Parent: Instance)
self.Coins = 0
self.Gui = self.Janitor:Add(Helium.Make("TextLabel", {
AnchorPoint = Vector2.new(0.5, 0.5);
BackgroundTransparency = 1;
Position = UDim2.fromScale(0.5, 0.5);
Size = UDim2.fromScale(0.5, 0.5);
Font = Enum.Font.Gotham;
Text = "Coins: 0";
TextColor3 = Color3.new(1, 1, 1);
TextSize = 24;
Parent = Parent;
}), "Destroy")
end
function CoinsDisplay:AddCoin()
self.Coins += 1
self.QueueRedraw()
end
CoinsDisplay.RedrawBinding = Helium.RedrawBinding.Heartbeat
function CoinsDisplay:Redraw()
self.Gui.Text = "Coins: " .. self.Coins
end
local MyCoinsDisplay = CoinsDisplay.new(Parent) -- Creates a TextLabel under Parent with the Text saying "Coins: 0"
MyCoinsDisplay:AddCoin() -- Calls :Redraw() and now the TextLabel says "Coins: 1"