@watch-state/decorators

Decorators to use watch-state

Usage no npm install needed!

<script type="module">
  import watchStateDecorators from 'https://cdn.skypack.dev/@watch-state/decorators';
</script>

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