Skip to main content

ReducerBuilder

Types

Cases

type Cases = {[string]Reducer}

Matchers

type Matchers = {{
matcher(Action) → boolean,
reducerReducer
}}

Functions

addCase

ReducerBuilder:addCase(
actionActionCreator | string,--

The action creator or type name

reducerReducer
) → ()

Adds a case reducer. Can only be called before addMatcher and addDefaultCase.

Case reducers are reducers that handle one type of action. They are the standard way of writing reducers in Rodux.

addMatcher

ReducerBuilder:addMatcher(
matcher(actionAction) → boolean,
reducerReducer
) → ()

Adds a matcher. Cannot be called after addDefaultCase.

Matchers can be used to handle actions based on your own custom logic rather than only matching the type.

addDefaultCase

ReducerBuilder:addDefaultCase(reducerReducer) → ()

Adds a fallback reducer. This will be invoked if no case reducers or matchers were executed for an action.

After adding a default case you cannot modify the reducer anymore, so this should be reserved for the very last part of the chain.

Show raw api
{
    "functions": [
        {
            "name": "addCase",
            "desc": "Adds a case reducer. Can only be called before `addMatcher` and\n`addDefaultCase`.\n\nCase reducers are reducers that handle one type of action. They are the\nstandard way of writing reducers in Rodux.",
            "params": [
                {
                    "name": "action",
                    "desc": "The action creator or type name",
                    "lua_type": "ActionCreator | string"
                },
                {
                    "name": "reducer",
                    "desc": "",
                    "lua_type": "Reducer"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 139,
                "path": "src/ReducerBuilder.luau"
            }
        },
        {
            "name": "addMatcher",
            "desc": "Adds a matcher. Cannot be called after `addDefaultCase`.\n\nMatchers can be used to handle actions based on your own custom logic\nrather than only matching the type.",
            "params": [
                {
                    "name": "matcher",
                    "desc": "",
                    "lua_type": "(action: Action) -> boolean"
                },
                {
                    "name": "reducer",
                    "desc": "",
                    "lua_type": "Reducer"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 159,
                "path": "src/ReducerBuilder.luau"
            }
        },
        {
            "name": "addDefaultCase",
            "desc": "Adds a fallback reducer. This will be invoked if no case reducers or\nmatchers were executed for an action.\n\nAfter adding a default case you cannot modify the reducer anymore, so this\nshould be reserved for the very last part of the chain.",
            "params": [
                {
                    "name": "reducer",
                    "desc": "",
                    "lua_type": "Reducer"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 184,
                "path": "src/ReducerBuilder.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "Cases",
            "desc": "",
            "lua_type": "{ [string]: Reducer }",
            "source": {
                "line": 12,
                "path": "src/ReducerBuilder.luau"
            }
        },
        {
            "name": "Matchers",
            "desc": "",
            "lua_type": "{ { matcher: (Action) -> boolean, reducer: Reducer } }",
            "source": {
                "line": 20,
                "path": "src/ReducerBuilder.luau"
            }
        }
    ],
    "name": "ReducerBuilder",
    "desc": "",
    "source": {
        "line": 67,
        "path": "src/ReducerBuilder.luau"
    }
}