# swift-onchange

> Trigger function on object, array or primitive value change

Latest version **1.0.3** (published 2019-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install swift-onchange
pnpm add swift-onchange
yarn add swift-onchange
bun add swift-onchange
```

## 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.0.3 |
| Published | 2019-01-27 |
| First published | 2019-01-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 23 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Anthony White |
| Maintainers | anthonywhite |

## Links

- npm: https://www.npmjs.com/package/swift-onchange
- Repository: https://github.com/AnthonySLWhite/swift-onchange
- Homepage: https://github.com/AnthonySLWhite/swift-onchange#readme
- Issues: https://github.com/AnthonySLWhite/swift-onchange/issues
- npm.io page: https://npm.io/package/swift-onchange

## Recent versions

- 1.0.3 (latest) — 2019-01-27
- 1.0.2 — 2019-01-22
- 1.0.1 — 2019-01-21
- 1.0.0 — 2019-01-21

## README

# Swift-OnChange

Swift-OnChange is inpired on the [on-change] project

## Installation

Use the package manager [NPM](https://www.npmjs.com/package/swift-onchange) to install Swift-OnChange.

```bash
npm i swift-onchange
```

## Usage

onChange takes 3 arguments

- (required) Callback function
- (optional) Original object, array or primitive value
- (optional) Create a setState property (1 for true)

```javascript
import onChange from "swift-onchange";

const originalObject = { a: 1 };

const objectWatch = onChange(
  e => console.log(`The value was changed to ${e}`),
  originalObject,
  1
);

console.log("objectWatch:", objectWatch);
// objectWatch: { a: 1, SetState: [Function] }

objectWatch.a = 2;
// The value was changed to 2

objectWatch.setState({
  b: 34,
  c: 9,
  d: {
    anotherChain: 4
  }
});
// The value was changed to
// {"a":2,"b":34,"c":9,"d":{"anotherChain":4}}

console.log("Chained changes watcher and SetState: ", objectWatch.d);
//Chained changes watcher and SetState:
// { anotherChain: 4, SetState: [Function] }
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License

[MIT](https://choosealicense.com/licenses/mit/)

[on-change]: https://github.com/sindresorhus/on-change

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