# @pacote/flux-actions

> Typed actions and reducers for Flux and Flux-like architectures.

Latest version **4.0.1** (published 2026-04-01) · 65 weekly downloads

## Install

```sh
npm install @pacote/flux-actions
pnpm add @pacote/flux-actions
yarn add @pacote/flux-actions
bun add @pacote/flux-actions
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2026-04-01 |
| First published | 2018-11-08 |
| Weekly downloads | 65 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Luís Rodrigues |
| Maintainers | goblindegook |
| Keywords | flux, redux, actions, reducers |

## Links

- npm: https://www.npmjs.com/package/@pacote/flux-actions
- Repository: https://github.com/PacoteJS/pacote
- Homepage: https://github.com/PacoteJS/pacote#readme
- Issues: https://github.com/PacoteJS/pacote/issues
- npm.io page: https://npm.io/package/@pacote/flux-actions

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads
- [xmodel-svelte](https://npm.io/package/xmodel-svelte.md) — 4 weekly downloads

## Recent versions

- 4.0.1 (latest) — 2026-04-01
- 4.0.0 — 2026-03-31
- 3.1.1 — 2025-10-24
- 3.0.4 — 2025-02-25
- 3.0.3 — 2024-10-05
- 3.0.2 — 2023-08-25
- 3.0.1 — 2023-04-22
- 3.0.0 — 2023-04-13
- 2.1.13 — 2022-12-13
- 2.1.12 — 2021-08-13
- 2.1.11 — 2021-04-18
- 2.1.10 — 2021-01-25
- 2.1.9 — 2020-11-27
- 2.1.8 — 2020-11-14
- 2.1.7 — 2020-09-23
- … 20 more at https://npm.io/package/@pacote/flux-actions/versions

## README

# @pacote/flux-actions

[![Redux Demo](https://badgen.net/badge/codesandbox/redux%20demo/yellow)](https://codesandbox.io/s/xv62o57r3z)
[![React Hooks API Demo](https://badgen.net/badge/codesandbox/react%20hooks%20api%20demo/yellow)](https://codesandbox.io/s/2wx6n5zlj0)
![version](https://badgen.net/npm/v/@pacote/flux-actions)
![minified](https://badgen.net/bundlephobia/min/@pacote/flux-actions)
![minified + gzip](https://badgen.net/bundlephobia/minzip/@pacote/flux-actions)

Typed actions and reducers for Flux and Flux-like architectures, including the [`useReducer` React hook](https://reactjs.org/docs/hooks-reference.html#usereducer).

## Demos

- [Counter using Redux](https://codesandbox.io/s/xv62o57r3z)
- [Counter using React Hooks](https://codesandbox.io/s/2wx6n5zlj0)

## Installation

```bash
yarn add @pacote/flux-actions
```

## Usage

### `createAction<Payload>(type: string)`

#### Action payloads

```typescript
import { createAction } from '@pacote/flux-actions'
const changeYear = createAction<number>('CHANGE_YEAR')
```

Calling `changeYear(1955)` will generate the following action object:

```javascript
{
  type: 'CHANGE_YEAR',
  payload: 1955
}
```

#### Action metadata

The action creator supports an optional metadata parameter. For example, `changeYear(1955, { test: true })` will create:

```javascript
{
  type: 'CHANGE_YEAR',
  payload: 1955,
  meta: {
    test: true
  }
}
```

#### Actions with errors

Unlike Flux Standard Actions, the action creator does not handle errors. Instead, consider using monadic objects like `Either` to wrap error conditions:

```typescript
import { createAction } from '@pacote/flux-actions'
import { Either, tryCatch } from 'fp-ts/lib/Either'

const changeYear = createAction<Either<Error, number>>('CHANGE_YEAR')

changeYear(tryCatch(...))
```

### `isType<Payload>(creator: ActionCreator<Payload>, action: Action<Payload>)`

Checks whether an action matches the provided type. This ensures the action is properly typed inside the guard block.

```typescript
import { createAction, isType } from '@pacote/flux-actions'

const changeYear = createAction<number>('CHANGE_YEAR')
const action = changeYear(1985)

if (isType(changeYear, action)) {
  // action.payload is a number inside the guard
  console.log(action.payload)
}
```

### `reduceFromState(initialState: State)`

Creates a reducer which matches action handlers to appropriate types.

```typescript
import { createAction, reduceFromState } from '@pacote/flux-actions'

const person = createAction<{ name: string }>('PERSON')
const dog = createAction<{ name: string }>('DOG')
const car = createAction<{ brand: string }>('CAR')

const reducer = reducerFromState({ now: 'None', then: '' })
  // Matches multiple actions:
  .on([person, dog], (s, a) => ({ now: a.payload.name, then: s.now }))
  // Matches a single action:
  .on(car, (s, a) => ({ now: a.payload.brand, then: s.now }))

const s2 = reducer(undefined, person({ name: 'Marty McFly' }))
// { now: 'Marty McFly', then: 'None' })

const s3 = reducer(s2, dog({ name: 'Einstein' }))
// { now: 'Einstein', then: 'Marty McFly' })

const s4 = reducer(s3, car({ brand: 'DeLorean' }))
// { now: 'DeLorean', then: 'Einstein' })
```

Reducing actions with errors wrapped in `Either` could look something like this:

```typescript
import { createAction, reduceFromState } from '@pacote/flux-actions'
import { Either, tryCatch } from 'fp-ts/lib/Either'

type State = {
  year: number
  error?: Error
}

const changeYear = createAction<Either<Error, number>>('CHANGE_YEAR')

const reducer = reducerFromState<State>({ year: 1985 })
  .on(changeYear, (state, { payload } ) => payload.fold<State>(
    error => ({ ...state, error }),
    year => ({ year, error: undefined })
  ))

reducer(undefined, changeYear(tryCatch(...)))
```

## License

MIT © [Luís Rodrigues](https://goblindegook.com).

---
_Source: https://npm.io/package/@pacote/flux-actions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
