Giter Site home page Giter Site logo

nschello / rodux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from roblox/rodux

0.0 0.0 0.0 1.54 MB

A state management library for Roblox Lua inspired by Redux

Home Page: https://roblox.github.io/rodux

License: Apache License 2.0

Lua 100.00%

rodux's People

Contributors

amaranthinecodices avatar benbrimeyer avatar cliffchapmanrbx avatar ghostnaps avatar jaguar-515 avatar jkelaty-rbx avatar lpghatguy avatar matthargett avatar michaelmcdonnell avatar ok-nick avatar overhash avatar quenty avatar rgychiu avatar slartibartfastfjords avatar tonycuadra avatar zotethemighty avatar zovits avatar

rodux's Issues

Adjustable Action Log and Clear Method for Rodux

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:

  1. Users should be able to specify the maximum length of the action log upon store creation.
  2. A new method, :clearLog, should be added to allow users to clear the store's action log at any moment.
  3. If the specified log length is exceeded, the oldest actions should be discarded to maintain the log length.
  4. If no log length is specified, the store should maintain the current fixed length as the default behavior.
  5. Ensure backward compatibility such that existing functionality is not impacted by these changes.
  6. New functionality must be documented and covered by unit tests to verify that actions are properly added to and cleared from the log, and that the log maintains the correct length as per the user-defined parameter.

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:

  • The Store constructor now accepts an optional parameter actionLogLength to specify the maximum length of the action log.
  • A new method :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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.