ts-onchange-decorator
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ts-onchange-decorator

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

Usage

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

    changeHandler(newFoo, oldFoo) {
        // do something with foo
    }
}
class Example {
    @OnChange(Example.prototype.changeHandler)
    foo = 'bar'

    changeHandler(newFoo, oldFoo) {
        // do something with foo
    }
}
class Example {
    @OnChange()
    foo = 'bar'

    fooChange(newFoo, oldFoo) {
        // do something with foo
    }
}
class Example {
    @OnChange()
    set foo(value) {
        //
    } 

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

Package Sidebar

Install

npm i ts-onchange-decorator

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

7.48 kB

Total Files

6

Last publish

Collaborators

  • noox