# ts-onchange-decorator

> A property and accessor decorator to call a function on new values

Latest version **1.0.0** (published 2018-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-onchange-decorator
pnpm add ts-onchange-decorator
yarn add ts-onchange-decorator
bun add ts-onchange-decorator
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-03-28 |
| First published | 2018-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Christoph Hoffmann |
| Maintainers | noox |
| Keywords | typescript, ts, decorator, onchange |

## Links

- npm: https://www.npmjs.com/package/ts-onchange-decorator
- Repository: https://github.com/no0x9d/ts-onchange-decorator
- Issues: https://github.com/no0x9d/ts-onchange-decorator/issues
- npm.io page: https://npm.io/package/ts-onchange-decorator

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-03-28

## README

# ts-onchange-decorator

A property or accessor decorator, which calls a change handler if a new value is assigned.

## Usage

```javascript
class Example {
    @OnChange('changeHandler')
    foo = 'bar'

    changeHandler(newFoo, oldFoo) {
        // do something with foo
    }
}
```

```javascript
class Example {
    @OnChange(Example.prototype.changeHandler)
    foo = 'bar'

    changeHandler(newFoo, oldFoo) {
        // do something with foo
    }
}
```

```javascript
class Example {
    @OnChange()
    foo = 'bar'

    fooChange(newFoo, oldFoo) {
        // do something with foo
    }
}
```

```javascript
class Example {
    @OnChange()
    set foo(value) {
        //
    } 

    fooChange(newFoo, oldFoo) {
        // do something with foo
        // Change handler is called after setter
    }
}
```

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