watch-state 3.5.0 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -6
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
<a href="https://www.npmjs.com/package/watch-state" target="_blank">
|
|
51
51
|
<img src="https://img.shields.io/npm/v/watch-state.svg" alt="watch-state npm">
|
|
52
52
|
</a>
|
|
53
|
-
<a href="https://bundlephobia.com/result?p=watch-state" target="_blank">
|
|
54
|
-
<img src="https://img.shields.io/bundlephobia/minzip/watch-state" alt="watch-state minzipped size">
|
|
55
|
-
</a>
|
|
56
53
|
<a href="https://www.npmtrends.com/watch-state" target="_blank">
|
|
57
54
|
<img src="https://img.shields.io/npm/dm/watch-state.svg" alt="watch-state downloads">
|
|
58
55
|
</a>
|
|
56
|
+
<a href="https://www.typescriptlang.org" target="_blank">
|
|
57
|
+
<img src="https://img.shields.io/npm/types/watch-state" alt="TypeSctipt">
|
|
58
|
+
</a>
|
|
59
59
|
<a href="https://packagequality.com/#?package=watch-state" target="_blank">
|
|
60
60
|
<img src="https://packagequality.com/shield/watch-state.svg" alt="watch-state quality">
|
|
61
61
|
</a>
|
|
@@ -134,6 +134,19 @@ html
|
|
|
134
134
|
|
|
135
135
|
<sup>[Simple example](#simple-example) • [Example Vanilla JS](#example-vanilla-js) • [Example React](#example-react) • [Example @innet/dom](#example-innetdom)</sup>
|
|
136
136
|
|
|
137
|
+
The library is based on the core concepts of `Observable` (something that can be observed) and `Observer` (something that can observe). On top of these concepts, the core classes `State`, `Compute`, and `Watch` are built according to the following scheme:
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
┌────────────┐ ┌─────────────┐
|
|
141
|
+
│ Observable │ │ Observer │
|
|
142
|
+
│ (abstract) │ │ (interface) │
|
|
143
|
+
└──────┬─────┘ └──────┬──────┘
|
|
144
|
+
┌────┴─────┐ ┌──────┴───┐
|
|
145
|
+
┌────┴────┐ ┌───┴─┴───┐ ┌────┴────┐
|
|
146
|
+
│ State │ │ Compute │ │ Watch │
|
|
147
|
+
└─────────┘ └─────────┘ └─────────┘
|
|
148
|
+
```
|
|
149
|
+
|
|
137
150
|
### Simple example
|
|
138
151
|
###### [🏠︎](#index) / [Usage](#usage) / Simple example [↓](#example-vanilla-js)
|
|
139
152
|
|
|
@@ -191,11 +204,11 @@ Simple reactive state without build tools or framework dependencies.
|
|
|
191
204
|
### Example React
|
|
192
205
|
###### [🏠︎](#index) / [Usage](#usage) / Example React [↑](#example-vanilla-js) [↓](#example-innetdom)
|
|
193
206
|
|
|
194
|
-
|
|
207
|
+
[@watch-state/react](https://www.npmjs.com/package/@watch-state/react) provides `useObservable()` hook that automatically subscribes React components to state changes and re-renders only when needed.
|
|
195
208
|
|
|
196
209
|
```tsx
|
|
197
210
|
import { State } from 'watch-state'
|
|
198
|
-
import {
|
|
211
|
+
import { useObservable } from '@watch-state/react'
|
|
199
212
|
|
|
200
213
|
const $count = new State(0)
|
|
201
214
|
|
|
@@ -204,7 +217,7 @@ const increase = () => {
|
|
|
204
217
|
}
|
|
205
218
|
|
|
206
219
|
export function CountButton () {
|
|
207
|
-
const count =
|
|
220
|
+
const count = useObservable($count)
|
|
208
221
|
|
|
209
222
|
return <button onClick={increase}>{count}</button>
|
|
210
223
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "watch-state",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "CANT inc. state management system.",
|
|
5
5
|
"author": "Mikhail Lysikov <d8corp@mail.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"types": "index.d.ts",
|
|
11
11
|
"unpkg": "index.min.js",
|
|
12
12
|
"jsdelivr": "index.min.js",
|
|
13
|
-
"browser": "index.min.js",
|
|
14
13
|
"homepage": "https://github.com/d8corp/watch-state",
|
|
15
14
|
"bugs": {
|
|
16
15
|
"url": "https://github.com/d8corp/watch-state/issues"
|