Skip to content

Latest commit

 

History

History
52 lines (42 loc) · 815 Bytes

README.md

File metadata and controls

52 lines (42 loc) · 815 Bytes

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