Skip to content

Commit

Permalink
Merge pull request #518 from Quenty/users/quenty/sorted_list_improvem…
Browse files Browse the repository at this point in the history
…ents

feat: Sorted list improvements
  • Loading branch information
Quenty authored Nov 12, 2024
2 parents 00e6f71 + d1dc66d commit c9049e8
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 45 deletions.
6 changes: 2 additions & 4 deletions src/actionmanager/src/Client/ActionManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ function ActionManager.new()
self._maid = Maid.new()
self._actions = {}

self.ActiveAction = ValueObject.new()
self._maid:GiveTask(self.ActiveAction)

self.ActionAdded = Signal.new() -- :Fire(action)
self.ActiveAction = self._maid:Add(ValueObject.new())
self.ActionAdded = self._maid:Add(Signal.new()) -- :Fire(action)

-- Stop actions while tool is in play
self._maid.ToolEquipped = ContextActionService.LocalToolEquipped:Connect(function(_)
Expand Down
7 changes: 2 additions & 5 deletions src/actionmanager/src/Client/BaseAction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ function BaseAction.new(actionData)
self._contextActionKey = string.format("%s_ContextAction", tostring(self._name))
self._activateData = nil -- Data to be fired with the Activated event

self.Activated = Signal.new() -- :Fire(actionMaid, ... (activateData))
self._maid:GiveTask(self.Activated)

self.Deactivated = Signal.new() -- :Fire()
self._maid:GiveTask(self.Deactivated)
self.Activated = self._maid:Add(Signal.new()) -- :Fire(actionMaid, ... (activateData))
self.Deactivated = self._maid:Add(Signal.new()) -- :Fire()

self.IsActivatedValue = Instance.new("BoolValue")
self.IsActivatedValue.Value = false
Expand Down
10 changes: 4 additions & 6 deletions src/binder/src/Shared/Binder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ function Binder:GetClassAddedSignal()
return self._classAddedSignal
end

self._classAddedSignal = Signal.new() -- :fire(class, inst)
self._maid:GiveTask(self._classAddedSignal)
self._classAddedSignal = self._maid:Add(Signal.new()) -- :fire(class, inst)

return self._classAddedSignal
end

Expand All @@ -360,8 +360,7 @@ function Binder:GetClassRemovingSignal()
return self._classRemovingSignal
end

self._classRemovingSignal = Signal.new() -- :fire(class, inst)
self._maid:GiveTask(self._classRemovingSignal)
self._classRemovingSignal = self._maid:Add(Signal.new()) -- :fire(class, inst)

return self._classRemovingSignal
end
Expand All @@ -376,8 +375,7 @@ function Binder:GetClassRemovedSignal()
return self._classRemovedSignal
end

self._classRemovedSignal = Signal.new() -- :fire(class, inst)
self._maid:GiveTask(self._classRemovedSignal)
self._classRemovedSignal = self._maid:Add(Signal.new()) -- :fire(class, inst)

return self._classRemovedSignal
end
Expand Down
6 changes: 2 additions & 4 deletions src/binder/src/Shared/Collection/BoundChildCollection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ function BoundChildCollection.new(binder, parent)
@prop ClassAdded Signal<T>
@within BoundChildCollection
]=]
self.ClassAdded = Signal.new() -- :Fire(class)
self._maid:GiveTask(self.ClassAdded)
self.ClassAdded = self._maid:Add(Signal.new()) -- :Fire(class)

--[=[
Fires on class removal
@prop ClassRemoved Signal<T>
@within BoundChildCollection
]=]
self.ClassRemoved = Signal.new() -- :Fire(class)
self._maid:GiveTask(self.ClassRemoved)
self.ClassRemoved = self._maid:Add(Signal.new()) -- :Fire(class)

self._classes = {} -- [class] = true
self._size = 0
Expand Down
4 changes: 2 additions & 2 deletions src/boundlinkutils/src/Shared/BoundLinkCollection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function BoundLinkCollection.new(binder, linkName, parent)
self._linkName = linkName or error("No linkName")
self._binder = binder or error("No binder")

self.ClassAdded = Signal.new() -- :Fire(class)
self.ClassRemoved = Signal.new() -- :Fire(class)
self.ClassAdded = self._maid:Add(Signal.new()) -- :Fire(class)
self.ClassRemoved = self._maid:Add(Signal.new()) -- :Fire(class)

self._classes = {} -- [class] = true
self._canidates = {} -- [inst] = { [objValue] = true }
Expand Down
7 changes: 7 additions & 0 deletions src/datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ This system is a reliable datastore system designed with promises and asyncronio
## Executive overiew
This datastore prevents data loss by being explicit about what we're writing to, and only modifying the data that exists there instead of modifying the whole structure.

## Comparison to other solutions

* Not specifically locked to players
* Native substore support for decoupled code
* Very performant and battle tested
* Native Rx and Promise implementation

## How syncing works
Sometimes datastores (like a global game data store) need to be synced live instead of upon server or player start. This is if we expect multiple servers to write to the same datastore at once we can use thie sync method to

Expand Down
11 changes: 4 additions & 7 deletions src/deathreport/src/Client/DeathReportServiceClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@ DeathReportServiceClient.ServiceName = "DeathReportServiceClient"
@param serviceBag ServiceBag
]=]
function DeathReportServiceClient:Init(serviceBag)
assert(not self.HumanoidDied, "Already initialized")

assert(not self._serviceBag, "Already initialized")
self._serviceBag = assert(serviceBag, "No serviceBag")
self._maid = Maid.new()

-- Internal
self._serviceBag:GetService(require("DeathReportBindersClient"))

self.NewDeathReport = Signal.new()
self._maid:GiveTask(self.NewDeathReport)

self._reportProcessor = DeathReportProcessor.new()
self._maid:GiveTask(self._reportProcessor)
-- State
self.NewDeathReport = self._maid:Add(Signal.new())

self._reportProcessor = self._maid:Add(DeathReportProcessor.new())
self._lastDeathReports = {}

-- Setup remote Event
Expand Down
3 changes: 1 addition & 2 deletions src/ik/src/Shared/Torso/TorsoIKBase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function TorsoIKBase.new(humanoid)

self._humanoid = humanoid or error("No humanoid")

self.Pointed = Signal.new() -- :Fire(position | nil)
self._maid:GiveTask(self.Pointed)
self.Pointed = self._maid:Add(Signal.new()) -- :Fire(position | nil)

self._resources = IKResource.new(IKResourceUtils.createResource({
name = "Character";
Expand Down
3 changes: 1 addition & 2 deletions src/inputkeymaputils/src/Client/InputKeyMapListUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ function InputKeyMapListUtils.observeActiveInputModeType(inputKeyMapList, servic
return Observable.new(function(sub)
local maid = Maid.new()

local selector = InputKeyMapListUtils.getNewInputModeTypeSelector(inputKeyMapList, serviceBag)
maid:GiveTask(selector)
local selector = maid:Add(InputKeyMapListUtils.getNewInputModeTypeSelector(inputKeyMapList, serviceBag))

maid:GiveTask(selector.Changed:Connect(function()
sub:Fire(selector.Value)
Expand Down
10 changes: 10 additions & 0 deletions src/metricutils/src/Shared/MetricUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ function MetricUtils.studsPerSecondToKph(studsPerSecond)
return studsPerSecond/STUDS_PER_METER/1000*SECONDS_PER_HOUR
end

--[=[
Convert from studs per a second to meters per a second
@param studsPerSecond number
@return number -- kph
]=]
function MetricUtils.studsPerSecondToMetersPerSecond(studsPerSecond)
return studsPerSecond/STUDS_PER_METER
end

--[=[
Convert from studs per a second (Roblox in-game units) to mph
@param studsPerSecond number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function ObservableSortedList.new(isReversed, compare)
@prop ItemRemoved Signal<T, Symbol>
@within ObservableSortedList
]=]
self.ItemRemoved = Signal.new()
self.ItemRemoved = self._maid:Add(Signal.new())

--[=[
Fires when the order could have changed
Expand Down Expand Up @@ -497,31 +497,41 @@ function ObservableSortedList:_fireEvents()
self._countValue.Value = 0
end

if not self.Destroy then return end

-- TODO: Prevent Rx.of(itemAdded) stuff in our UI
for node in nodesAdded do
-- TODO: Prevent query slow here...?
local index = node:GetIndex()
self.ItemAdded:Fire(node.data, index, node)
end

if not self.Destroy then return end

for node in nodesRemoved do
self.ItemRemoved:Fire(node.data, node)
end

if not self.Destroy then return end

self.OrderChanged:Fire()

if not self.Destroy then return end

do
for index, node in self:_iterateNodesRange(lowestIndexChanged) do
-- TODO: Handle negative observations to avoid refiring upon insertion
-- TODO: Handle our state changing while we're firing
-- TODO: Avoid looping over nodes if we don't need to (track observations in node itself?)
local negative = ListIndexUtils.toNegativeIndex(self._root.descendantCount, index)
self._nodeIndexObservables:Fire(node, index)
self._indexObservers:Fire(index, node)
self._indexObservers:Fire(negative, node)
self._indexObservers:Fire(index, node.data, node)
self._indexObservers:Fire(negative, node.data, node)
end
end

if not self.Destroy then return end

if self._mainObservables:HasSubscriptions("list") then
-- TODO: Reuse list
local list = self:GetList()
Expand Down
2 changes: 1 addition & 1 deletion src/radial-image/src/Client/RadialImage.story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ return function(target)
-- radialImage:SetPercent((os.clock()/5) % 1)

local scale = (1 + math.sin((os.clock()/5)*math.pi*2))/2
radialImage.Gui.Size = UDim2.fromOffset(scale*90, scale*90)
radialImage.Gui.Size = UDim2.fromOffset(math.round(scale*90), math.round(scale*90))
end))

radialImage.Gui.Parent = target
Expand Down
13 changes: 4 additions & 9 deletions src/tie/test/modules/Server/Window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ Window.__index = Window
function Window.new(obj)
local self = setmetatable(BaseObject.new(obj), Window)

self.Opening = Signal.new()
self._maid:GiveTask(self.Opening)
self.Opening = self._maid:Add(Signal.new())
self.Closing = self._maid:Add(Signal.new())

self.Closing = Signal.new()
self._maid:GiveTask(self.Closing)

self.IsOpen = Instance.new("BoolValue")
self.IsOpen = self._maid:Add(Instance.new("BoolValue"))
self.IsOpen.Value = false
self._maid:GiveTask(self.IsOpen)

self.LastPromise = ValueObject.new()
self._maid:GiveTask(self.LastPromise)
self.LastPromise = self._maid:Add(ValueObject.new())

self._maid:GiveTask(OpenableInterface:Implement(self._obj, self))

Expand Down

0 comments on commit c9049e8

Please sign in to comment.