# cc-update-prop

> dva reducer helper, redux reducer helper, extend the target prop inside the tree

Latest version **1.1.0** (published 2017-03-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install cc-update-prop
pnpm add cc-update-prop
yarn add cc-update-prop
bun add cc-update-prop
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-03-16 |
| First published | 2017-03-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | cc |
| Maintainers | jserone |
| Keywords | extend, copy, json, walker, dva, redux |

## Links

- npm: https://www.npmjs.com/package/cc-update-prop
- npm.io page: https://npm.io/package/cc-update-prop

## Dependencies (1)

- [extend](https://npm.io/package/extend.md) ^3.0.0

## Recent versions

- 1.1.0 (latest) — 2017-03-16
- 1.0.9 — 2017-03-16
- 1.0.8 — 2017-03-16
- 1.0.6 — 2017-03-16
- 1.0.5 — 2017-03-16
- 1.0.4 — 2017-03-16
- 1.0.3 — 2017-03-15
- 1.0.1 — 2017-03-15
- 1.0.0 — 2017-03-15

## README

### cc-update-prop: updateProp

1. this is mainly used to be a helper for the dva's reducer
2. also can be treated as a fast copy tool without deep walking into the json tree
3. of course, redux reducer can also be applied with updateProp
4. support default value as the placeholder
5. the updateProp.save can be a useful method to cancel the ctrl+c|ctrl+v work

#### the array test
-------------------------------------
```javascript
var updateProp = require("cc-update-prop");

var state = [
  {
    x: {
      aaa: 1
    }
  },
  {
    x: 2
  }
]

var action = {
  payload: {
    ee: "asasas"
  }
};

var cb = updateProp({
  props: ["0", "x"],
  cb(state, payload) {
    return {
      ee: payload.ee + "!!!!"
    }
  }
});

var ret = cb(state, action);

console.log(ret);
// [ { x: { aaa: 1, ee: 'asasas!!!!' } }, { x: 2 } ]
```

#### the object test
-------------------------------------
```javascript
var updateProp = require("cc-update-prop");

var obj1 = {x: 1}

var state = {
  aa: 1,
  a: {
    bb: obj1,
    b: {
      cc: 3,
      c: {
        dd: "cc, haha, I am here !"
      }
    }
  }
};

var action = {
  payload: {
    ee: "asasas"
  }
};

var cb = updateProp({
  props: ["a", "b", "c"],
  cb(state, payload) {
    return {
      ee: state.aa + payload.ee + "!!!!"
    }
  }
});

var ret = cb(state, action);

console.log(ret.a.b.c); // { dd: 'cc, haha, I am here !', ee: '1asasas!!!!' }

console.log(ret === state); // false

console.log(ret.a.b.c === state.a.b.c); // false

console.log(ret.a.bb === state.a.bb); // true
```

---
_Source: https://npm.io/package/cc-update-prop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
