https://github.com/pothos-dev/redux-action-objects
https://github.com/pothos-dev/redux-action-objects
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pothos-dev/redux-action-objects
- Owner: pothos-dev
- Created: 2018-04-19T12:23:32.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-19T13:40:49.000Z (about 8 years ago)
- Last Synced: 2025-12-12T21:58:09.545Z (6 months ago)
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Yet another Redux Action pattern in Typescript
```typescript
import {defineAction} from 'redux-action-objects';
// define the Application state type
interface AppState {/*...*/}
// create an ActionGroup that works on AppState
const actionGroup = createActionGroup();
// add an action to the ActionGroup
const ClickAction = actionGroup.addAction<{
// define payload here - you can also provide an explicit interface
x: number
y: number
}>({
// We don't actually need to assign a type name - if omitted, the name will be generated randomly.
// However, it is advisable to use human readable type for logging and debugging.
type: 'ClickAction',
// This is the reducer function that should be executed when the action is processed. It takes
// the AppState and the action payload and should return an Appstate again.
// Parameters and return types are already typechecked.
reduce: (state, { x, y }) => {
return { ...state, clicks: [ ...state.clicks, {x, y} ] }
}
})
// Add any number of additional actions to actionGroup...
// create the redux store - using actionGroup.reducer as our reducer function. No switch case required!
const state: AppState = {/*...*/}
const store = createStore(actionGroup.reducer, state);
// create an action using the typesafe action creator, then dispatch it to store
const action = ClickAction.create({x: 23, y: 42})
store.dispatch(action);
```