https://github.com/codewell/state-actions
https://github.com/codewell/state-actions
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/codewell/state-actions
- Owner: codewell
- License: mit
- Created: 2019-09-15T12:39:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T10:32:29.000Z (over 3 years ago)
- Last Synced: 2025-11-11T19:34:43.004Z (7 months ago)
- Language: JavaScript
- Size: 281 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @codewell/state-actions
## Installation
```
npm install @codewell/state-actions
```
## Basic usage
### Set state property
Setting a state property overrides the current value of a state property.
```JavaScript
import { setStateProperty } from '@codewell/state-actions';
const state = { foo: 'foo' };
const action = { payload: 'bar' };
setStateProperty(state, action, 'foo');
// => {foo: 'bar'}
```
### Update state property
Updates some (or all) fields of a state property.
```JavaScript
import { updateStateProperty } from '@codewell/state-actions';
const state = { foo: {
one: 1,
two: 0,
} };
const action = { payload: {two: 2, three: 3} };
updateStateProperty(state, action, 'foo');
// => {foo: {one: 1, two: 2, three: 3}}
```
### Remove state property
Removes a property from the state.
```JavaScript
import { removeStateProperty } from '@codewell/state-actions';
const state = { foo: 'foo' };
removeStateProperty(state, 'foo');
// => {}
```