@watch-state/decorators

Decorators to use watch-state

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@watch-state/decorators
001.3.0-alpha.0a year ago3 years agoMinified + gzip package size for @watch-state/decorators in KB

Readme

Watch-State logo by Mikhail Lysikov
  @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)