https://github.com/d8corp/watch-state-decorators
Decorators to use watch-state
https://github.com/d8corp/watch-state-decorators
Last synced: about 1 year ago
JSON representation
Decorators to use watch-state
- Host: GitHub
- URL: https://github.com/d8corp/watch-state-decorators
- Owner: d8corp
- License: mit
- Created: 2021-05-29T09:52:06.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-04-30T10:53:11.000Z (about 3 years ago)
- Last Synced: 2025-03-30T16:02:25.570Z (over 1 year ago)
- Language: TypeScript
- Size: 558 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @watch-state/decorators
[](https://www.npmjs.com/package/@watch-state/decorators)
[](https://www.npmtrends.com/@watch-state/decorators)
[](https://changelogs.xyz/@watch-state/decorators)
[](https://github.com/d8corp/watch-state-decorators/blob/master/LICENSE)
State management decorators based on [watch-state](https://www.npmjs.com/package/watch-state)
### Install
npm
```bash
npm i @watch-state/decorators
```
yarn
```bash
yarn add @watch-state/decorators
```
### Usage
You can use one of the next decorators
```javascript
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)
```