npm.io
1.0.0 • Published 8 years ago

ts-onchange-decorator

Licence
MIT
Version
1.0.0
Deps
0
Size
7 kB
Vulns
0
Weekly
0
Stars
3

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

Keywords