-- Compiled with roblox-ts v2.0.4 local TS = _G[script] local _rodux = TS.import(script, TS.getModule(script, "@rbxts", "rodux").src) local createReducer = _rodux.createReducer local makeActionCreator = _rodux.makeActionCreator local entries = TS.import(script, script.Parent, "utils", "object").entries --[[ * * Shared ActionCreator generator function rather than creating a new one for each action. * Autistic optimisation. ]] local payloadGenerator = function(payload) return { payload = payload, } end --[[ * * * @param options * @returns ]] local function createSlice(options) local actionCreators = {} local sliceCaseReducersByName = {} for name, caseReducer in entries(options.reducers) do local actionName = options.name .. ("/" .. name) actionCreators[name] = makeActionCreator(actionName, payloadGenerator) sliceCaseReducersByName[actionName] = caseReducer end -- TODO: Make this immutable local _initialState = options.initialState local initialState = if type(_initialState) == "function" then options.initialState() else options.initialState local sliceReducer = createReducer(initialState, sliceCaseReducersByName) return { name = options.name, actions = actionCreators, reducer = sliceReducer, caseReducers = options.reducers, } end return { createSlice = createSlice, }