1.3.0-alpha.0 • Published 1 year ago

@watch-state/decorators v1.3.0-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

  @watch-state/decorators

 
NPM downloads downloads license

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)