@watch-state/decorators
v1.3.0-alpha.0
Published
Decorators to use watch-state
Downloads
12
Maintainers
Readme
@watch-state/decorators
State management decorators based on watch-state
Install
npm
npm i @watch-state/decorators
yarn
yarn add @watch-state/decorators
Usage
You can use one of the next decorators
import { Watch } from 'watch-state'
import { state, cache, event } from '@watch-state/decorators'
class Counter {
// fields
@state accessor value = 1
// accessors
@cache get square () {
return this.value ** 2
}
// methods
@event tick () {
this.value++
}
}
const counter = new Counter()
new Watch(() => console.log(counter.value, counter.square))
// console.log(1, 1)
counter.tick()
// console.log(2, 4)