nschello / rodux Goto Github PK
View Code? Open in Web Editor NEWThis project forked from roblox/rodux
A state management library for Roblox Lua inspired by Redux
Home Page: https://roblox.github.io/rodux
License: Apache License 2.0
This project forked from roblox/rodux
A state management library for Roblox Lua inspired by Redux
Home Page: https://roblox.github.io/rodux
License: Apache License 2.0
Title: Customizable ACTION_LOG_LENGTH and Store Action Log Clearing Method
Issue:
At present, the Rodux store maintains an action log of a fixed length, which is not exposed for customization by the end-users. This restricts the developers from setting the log retention based on their use case requirements (e.g., for debugging, analytics, etc.). Additionally, there is no way to clear the action log programmatically, making it difficult for developers to manage the log lifecycle, especially in long-running applications where memory consumption and performance could be a concern.
Acceptance Criteria:
:clearLog
, should be added to allow users to clear the store's action log at any moment.Proposed Code Changes:
in Store.lua
:
-- Add a new parameter for action log length in the store initializer.
function Store.new(reducer, initialState, middlewares, actionLogLength)
local self = {
_reducer = reducer,
_state = initialState or reducer(nil, {type = Rodux.None}),
_subscribers = {},
-- Set default action log length if not provided
_actionLogLength = actionLogLength or DEFAULT_ACTION_LOG_LENGTH,
_actions = {},
_middlewares = {},
}
-- Other initialization code ...
return setmetatable(self, Store)
end
-- Update the `dispatch` method to respect the custom action log length.
function Store:dispatch(action)
assert(typeof(action) == "table", "Actions must be tables")
assert(typeof(action.type) == "string", "Action type must be a string")
-- Other dispatch code ...
-- Truncate the log if it exceeds the specified length
while #self._actions > self._actionLogLength do
table.remove(self._actions, 1)
end
return action
end
-- New `:clearLog` method to clear the action log.
function Store:clearLog()
self._actions = {}
end
Unit Test Case Example:
describe("Store action log", function()
it("should enforce the specified maximum action log length", function()
local store = Store.new(reducer, nil, nil, 10) -- log length set to 10
for i = 1, 15 do
store:dispatch({type = "test_action"})
end
local log = store:getActions() -- assuming there's a method to retrieve the action log, otherwise expose this functionality too.
assert(#log == 10, "Action log should only contain the last 10 dispatched actions.")
end)
it("should clear the action log when :clearLog is called", function()
local store = Store.new(reducer)
store:dispatch({type = "test_action"})
assert(#store:getActions() > 0, "Action log should contain at least one action.")
store:clearLog()
assert(#store:getActions() == 0, "Action log should be empty after clearLog is called.")
end)
end)
Documentation:
Store
constructor now accepts an optional parameter actionLogLength
to specify the maximum length of the action log.:clearLog
has been added to the Store
class to allow users to clear the action log.After implementing the code changes, ensure to update the relevant documentation and create test cases to cover the new functionality.
created by [email protected] using Prodops
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.