# redux-zero-single-action

> Redux-zero single action

Latest version **2.0.4** (published 2022-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-zero-single-action
pnpm add redux-zero-single-action
yarn add redux-zero-single-action
bun add redux-zero-single-action
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2022-01-29 |
| First published | 2021-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Christian Carestia |
| Maintainers | engiwebhq |
| Keywords | redux-zero, state management, single action |

## Links

- npm: https://www.npmjs.com/package/redux-zero-single-action
- Repository: https://github.com/Engiweb/redux-zero-single-action
- Issues: https://github.com/Engiweb/redux-zero-single-action/issues
- npm.io page: https://npm.io/package/redux-zero-single-action

## 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
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 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

## Recent versions

- 2.0.4 (latest) — 2022-01-29
- 2.0.3 — 2021-09-25
- 2.0.2 — 2021-09-25
- 2.0.1 — 2021-08-24
- 1.2.3 — 2021-05-26
- 1.2.2 — 2021-05-26
- 1.2.1 — 2021-05-26
- 1.2.0 — 2021-05-20
- 1.1.0 — 2021-05-06
- 1.0.0 — 2021-05-06

## README

# redux-zero-single-action

Single action for redux-zero which tries to cover most state change operations.

## Dependencies
```
npm i -g npm
npm i redux-zero
npm i react react-dom
```

## Installation
```
npm i redux-zero-single-action
```

## Usage
In your React component, import actions and the action constants required:

```
import { connect } from 'redux-zero/react'
import actions, {
  BOOLEAN_TOGGLE
} from 'redux-zero-single-action'
```

Connect your component to the store:
```
<< COMPONENT GOES HERE >>

const mapToProps = ({
  propToSet,
}) => ({
  propToSet,
})

export default connect(
  mapToProps,
  actions
)(TestComponent)
```

Finally use the action in your component:
```
const TestComponent = ({
  singleAction,
  propToSet,
}) => (
    <div className="container">
      <button
        onClick={() => singleAction({
          keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
          action: GENERAL_SET,
          value: 'new'
        })}
      />
    </div>
  )
}
```

Example folder coming soon.

## Action types
* GENERAL_SET: default key-value replacement
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: GENERAL_SET,
      value: 'new'
    })
```

* GENERAL_APPEND: append value to subkey
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: GENERAL_APPEND,
      value: 'new'
    })
```

* GENERAL_DELETE: remove key
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: GENERAL_DELETE,
    })
```

* BOOLEAN_TOGGLE: toggle boolean value
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: BOOLEAN_TOGGLE,
    })
```

* NUMBER_ADD: add number to existing value (if no value, it sets the value as the added number)
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: NUMBER_ADD,
      value: 1
    })
```

* NUMBER_MULTIPLY: multiply number to existing value (if no value, it sets the value to 0)
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: NUMBER_MULTIPLY,
      value: 8
    })
```

* OBJECT_SPREAD: spread object value into existing object-type key 
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: OBJECT_SPREAD,
      value: { id: 1 }
    })
```

* ARRAY_PUSH: push valueinto existing array-type key 
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: ARRAY_PUSH,
      value: 'item
    })
```

* ARRAY_PUSH_UNIQUE: push value into existing array-type key only if item is not present in the array
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: ARRAY_PUSH,
      value: 'item'
    })
```

* ARRAY_TOGGLE: push value into existing array-type key if item is not present in the array, otherwise removes it from the array
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: ARRAY_TOGGLE,
      value: 'item'
    })
```

* ARRAY_DELETE: removes item from existing array-type key if item is present
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: NUMBER_MULTIPLY,
      value: 'item'
    })
```

* ARRAY_DELETE_INDEX: removes item from existing array-type key by index, if index is present
```
singleAction({
      keys: ['propToSet', 'propToSetSubKey', 'propToSetSubSubKey'],
      action: NUMBER_MULTIPLY,
      value: 8
    })
```

## Why redux-zero-single-action?
[Redux-zero](https://github.com/redux-zero/redux-zero) does a great job in simplifying the Redux flow.
Having a single action bring an additional simplification, as:
* less actions to connect to components and pass around
* less code
* focus on functions development rather than store actions

## Publishing

Use *np* to publish the new version to npm.
```
  git add .
  git commit -m "Message"
```

## Next steps
* Add example folder

---
_Source: https://npm.io/package/redux-zero-single-action · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
