@substrate-system/state 0.0.1 → 0.0.4
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 +33 -2
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -17,7 +17,8 @@ Helpful pieces for application state.
|
|
|
17
17
|
|
|
18
18
|
- [Install](#install)
|
|
19
19
|
- [Example](#example)
|
|
20
|
-
* [
|
|
20
|
+
* [`RequestFor`](#requestfor)
|
|
21
|
+
* [With Signals](#with-signals)
|
|
21
22
|
- [Modules](#modules)
|
|
22
23
|
* [ESM](#esm)
|
|
23
24
|
* [Common JS](#common-js)
|
|
@@ -35,7 +36,9 @@ npm i -S @substrate-system/package
|
|
|
35
36
|
|
|
36
37
|
## Example
|
|
37
38
|
|
|
38
|
-
###
|
|
39
|
+
### `RequestFor`
|
|
40
|
+
|
|
41
|
+
Model an HTTP request.
|
|
39
42
|
|
|
40
43
|
```ts
|
|
41
44
|
import { type HTTPError } from 'ky'
|
|
@@ -59,6 +62,34 @@ error(myRequest, new Error('ok'))
|
|
|
59
62
|
// { data: 'abc', error: Error, pending: false }
|
|
60
63
|
```
|
|
61
64
|
|
|
65
|
+
### With Signals
|
|
66
|
+
|
|
67
|
+
A good combination is [@preact/signals](https://preactjs.com/guide/v10/signals)
|
|
68
|
+
plus this module.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { type HTTPError, ky } from 'ky'
|
|
72
|
+
import { type Signal, signal } from '@preact/signals'
|
|
73
|
+
import {
|
|
74
|
+
type RequestFor,
|
|
75
|
+
RequestState
|
|
76
|
+
} from '@substrate-system/state'
|
|
77
|
+
const { start, set, error } = RequestState
|
|
78
|
+
|
|
79
|
+
const myRequestSignal:Signal<RequestFor<{
|
|
80
|
+
hello:string
|
|
81
|
+
}>> = signal(RequestState(null))
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
myRequestSignal.value = start(myRequestSignal)
|
|
85
|
+
const res = await ky.get('http://example.com')
|
|
86
|
+
myRequestSignal.value = set(myRequestSignal, { hello: 'world' })
|
|
87
|
+
} catch (_err) {
|
|
88
|
+
const err = _err as HTTPError
|
|
89
|
+
myRequestSignal.value = error(myRequestSignal, err)
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
62
93
|
|
|
63
94
|
## Modules
|
|
64
95
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@substrate-system/state",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Helpers for state in the browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"build-cjs:min": "esbuild src/*.ts --format=cjs --minify --keep-names --tsconfig=tsconfig.build.json --outdir=./dist --out-extension:.js=.min.cjs --sourcemap",
|
|
36
36
|
"build-esm": "esbuild src/*.ts --format=esm --metafile=dist/meta.json --keep-names --tsconfig=tsconfig.build.json --outdir=./dist --sourcemap && tsc --emitDeclarationOnly --project tsconfig.build.json --outDir dist",
|
|
37
37
|
"build-esm:min": "esbuild ./src/*.ts --format=esm --keep-names --bundle --tsconfig=tsconfig.build.json --minify --out-extension:.js=.min.js --outdir=./dist --sourcemap",
|
|
38
|
-
"build-example": "mkdir -p ./public && rm -rf ./public/* && VITE_DEBUG_MODE=staging vite --mode staging --base=\"/repo-name\" build",
|
|
39
38
|
"build-docs": "typedoc ./src/index.ts",
|
|
40
39
|
"build": "mkdir -p ./dist && rm -rf ./dist/* && npm run build-cjs && npm run build-esm && npm run build-esm:min && npm run build-cjs:min",
|
|
41
40
|
"start": "vite",
|