1.0.0 • Published 6 years ago

ts-onchange-decorator v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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
    }
}