decorate-properties
v1.0.1
Published
The untity for decorating class properties more official.
Downloads
3
Readme
decorate-properties
The repo is forked from the decorate
API of mobxjs@5.
Usage
import * as decorate from 'decorate-properties'
import { observable, computed, action } from 'mobx'
class Person {
name = "John"
age = 42
showAge = false
get labelText() {
return this.showAge ? `${this.name} (age: ${this.age})` : this.name;
}
setAge(age) {
this.age = age;
}
}
// when using decorate, all fields should be specified (a class might have many more non-observable internal fields after all)
decorate(Person, {
name: observable,
age: observable,
showAge: observable,
labelText: computed,
setAge: action,
// array of decorator function
foo: [computed, observable]
})
// or
decorate(new Person(), {
name: observable,
age: observable,
showAge: observable,
labelText: computed,
setAge: action
})