UNPKG

@rbxts/rodux

Version:

Rodux for Roblox TypeScript

63 lines (61 loc) 1.5 kB
import Rodux from "./index"; /** * A helper function that can be used to make action creators. * * Action creators are helper objects that will generate actions from provided data and automatically populate the type field. * * Actions often have a structure that looks like this: * * ```ts * const myAction = { * type: "SetFoo", * value: 1, * } * ``` * * They are often generated by functions that take the action's data as arguments: * * ```ts * function SetFoo(value) { * return { * type: "SetFoo", * value, * } * } * ``` * * `makeActionCreator` looks similar, but it automatically populates the action's type * with the action creator's name. * This makes it easier to keep track of which actions your reducers are responding to: * * Make an action creator in `SetFoo.ts` * ```ts * const SetFoo = makeActionCreator("SetFoo", (value) => { * return { * value, * } * }); * export = SetFoo; * ``` * * Then check for that action name in `FooReducer.ts`: * ```ts * import SetFoo from "./SetFoo"; * ... * if (action.type == SetFoo.name) { * // change some state! * } * ``` * * @param name * @param actionGeneratorFunction */ declare function makeActionCreator< TName extends string, TParams extends unknown[], TActionProps extends Record<string, {}> >( name: TName, actionGeneratorFunction: (...args: TParams) => TActionProps ): Rodux.ActionCreator<TName, TParams, TActionProps>; export = makeActionCreator;