Skip to content

Commit

Permalink
Added Entries
Browse files Browse the repository at this point in the history
  • Loading branch information
creepersaur committed Oct 14, 2024
1 parent 041a48e commit 4aa4f1c
Show file tree
Hide file tree
Showing 7 changed files with 641 additions and 12 deletions.
20 changes: 20 additions & 0 deletions src/examples/Stories/Entries.story/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Quark = require(ReplicatedStorage.Shared.Quark)
local New = Quark.New
local Entries = Quark.Entries

return function(parent: Instance)
New "Frame" {
Parent = parent,
children = Entries(10, function(i: number)
return New "TextLabel" {
Position = UDim2.fromOffset(0, 50 * i - 50),
Size = UDim2.fromOffset(200, 50),
Text = `Label: {i}`
}
end)
}

return Quark.Cleanup
end
13 changes: 5 additions & 8 deletions src/shared/Quark/Components/New.luau
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Types = require(ReplicatedStorage.Shared.Quark.Types)
local Reactive = require(script.Parent.Parent.Reactive)
local Created = {}

Expand Down Expand Up @@ -46,13 +49,7 @@ local function AddChildren(self, list)
end
end

export type New = {
PushChildren: ({ any }) -> (),
Push: (child: any) -> (),
PushClass: (class: string) -> (),
}

local New = function(ClassName: string | Instance): ({ [string]: any }) -> Instance & New
local New = function(ClassName: string | Instance): ({ [string]: any }) -> Instance & Types.New
local obj: any = ClassName
if typeof(obj) == "string" then
obj = Instance.new(ClassName::string)
Expand Down Expand Up @@ -111,7 +108,7 @@ local New = function(ClassName: string | Instance): ({ [string]: any }) -> Insta
__newindex = function(self, idx, value)
self.Object[idx] = value
end,
__call = function(self, Properties: { [string]: any }): Instance & New
__call = function(self, Properties: { [string]: any }): Instance & Types.New
for i, v in Properties do
if i == "children" then
if v._is_state then
Expand Down
18 changes: 18 additions & 0 deletions src/shared/Quark/Entries/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local Types = require(script.Parent.Types)
local Entries = {
Created = {}
}

function Entries.new(n: number, func: (i: number) -> Instance | Types.New)
local children = {}

for i = 1, n do
local object = func(i)
table.insert(children, object)
table.insert(Entries.Created, object)
end

return children
end

return Entries
6 changes: 6 additions & 0 deletions src/shared/Quark/Types.luau
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export type Style = {
Push: (self: Style, name: string) -> (Properties: { [string]: any }) -> (),
}

export type New = {
PushChildren: ({ any }) -> (),
Push: (child: any) -> (),
PushClass: (class: string) -> (),
}

export type Spring<T> = {
Start: CanBeState<T>,
Value: State<T?>,
Expand Down
20 changes: 17 additions & 3 deletions src/shared/Quark/init.luau
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
local Quark = {}

--[[ REACTIVE ]]
local Reactive = require(script.Reactive)
Quark.State = Reactive.State
Quark.Signal = Reactive.Signal

--[[ NEW ]]
local New = require(script.Components.New)
Quark.New = New.New

--[[ ANIMATIONS ]]
local Animations = require(script.Animations)
Quark.Animations = Animations

--[[ Styles ]]
local Styles = require(script.Styles)
local StyleSheet = Styles.StyleSheet
Quark.StyleSheet = StyleSheet.new
Quark.GetStyle = StyleSheet.GetStyle
Quark.Class = StyleSheet.Class

--[[ ENTRIES ]]
local Entries = require(script.Entries)
Quark.Entries = Entries.new

--[[ CLEANUP ]]
local Cleanup = require(script.Components.Cleanup)
Quark.Cleanup = Cleanup[1]
Cleanup[2](New.Created, Animations._Created, Reactive.Created)
Cleanup[2](New.Created, Animations._Created, Reactive.Created, Entries.Created)

--[[ QUICKLIST ]]
local QuickList = require(script.quicklist)
Quark.QuickList = QuickList

-- TYPES
--[[ TYPES ]]
local Types = require(script.Types)

export type Quark = typeof(Quark)
Expand All @@ -29,5 +42,6 @@ export type Signal<T = unknown> = Types.Signal<T>
export type Style = Types.Style
export type CanBeState<T> = Types.CanBeState<T>
export type Spring<T> = Types.Spring<T>
export type New = Types.New

return Quark
return Quark
Loading

0 comments on commit 4aa4f1c

Please sign in to comment.