@wcstack/fetch 4.0.2 → 4.0.3
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.ja.md +9 -2
- package/README.md +9 -2
- package/package.json +3 -2
package/README.ja.md
CHANGED
|
@@ -164,7 +164,7 @@ npm install @wcstack/fetch
|
|
|
164
164
|
その書き込みは **黙って無視** されます。fetch は実行されず、`trigger` は `false` のまま、
|
|
165
165
|
イベントも発火しません。先に `url` を設定してから改めて `true` を書き込んでください。
|
|
166
166
|
|
|
167
|
-
### 4.
|
|
167
|
+
### 4. body 付きの POST
|
|
168
168
|
|
|
169
169
|
```html
|
|
170
170
|
<wcs-state>
|
|
@@ -174,11 +174,16 @@ npm install @wcstack/fetch
|
|
|
174
174
|
name: "",
|
|
175
175
|
email: "",
|
|
176
176
|
},
|
|
177
|
+
submitBody: null,
|
|
177
178
|
submitRequest: false,
|
|
178
179
|
submitResult: null,
|
|
179
180
|
submitError: null,
|
|
181
|
+
submitLoading: false,
|
|
180
182
|
|
|
181
183
|
submit() {
|
|
184
|
+
// 送信のたびに(再試行も)新しいオブジェクトを作る。<wcs-fetch> は
|
|
185
|
+
// 要求のたびに `body` を null に戻す。
|
|
186
|
+
this.submitBody = { name: this["newUser.name"], email: this["newUser.email"] };
|
|
182
187
|
this.submitRequest = true;
|
|
183
188
|
},
|
|
184
189
|
};
|
|
@@ -195,7 +200,7 @@ npm install @wcstack/fetch
|
|
|
195
200
|
method="POST"
|
|
196
201
|
manual
|
|
197
202
|
data-wcs="
|
|
198
|
-
body:
|
|
203
|
+
body: submitBody;
|
|
199
204
|
trigger: submitRequest;
|
|
200
205
|
value: submitResult;
|
|
201
206
|
error: submitError;
|
|
@@ -212,6 +217,8 @@ npm install @wcstack/fetch
|
|
|
212
217
|
</template>
|
|
213
218
|
```
|
|
214
219
|
|
|
220
|
+
`body` は**使い捨て**の入力です。`<wcs-fetch>` は送信すると `body` を `null` に戻します([設計メモ](#設計メモ))。だから本文は要求を始めるハンドラで作り、毎回新しいオブジェクトを代入します。フォームのオブジェクトそのもの(`body: newUser`)を束ねると、送られるのは 1 回だけです。入力は束ねたパスの*下*の `newUser.name` に書くので束縛は当て直されず、2 回目の送信は本文なしになります。エラーは出ません。`wcs-validate` はこの形を `wcs/input-nested-write` で報告します。
|
|
221
|
+
|
|
215
222
|
### 5. `<wcs-infinite-scroll>` による無限スクロール
|
|
216
223
|
|
|
217
224
|
`<wcs-infinite-scroll>` は、sentinel 要素が表示領域に入ったときに既存の `<wcs-fetch>` を実行します。
|
package/README.md
CHANGED
|
@@ -164,7 +164,7 @@ If `url` is empty when `true` is written (e.g. a state-driven computed url not y
|
|
|
164
164
|
resolved), the write is **silently ignored**: no fetch runs, `trigger` stays `false`,
|
|
165
165
|
and no event fires. Set the `url` first, then write `true` again to execute.
|
|
166
166
|
|
|
167
|
-
### 4. POST with
|
|
167
|
+
### 4. POST with a body
|
|
168
168
|
|
|
169
169
|
```html
|
|
170
170
|
<wcs-state>
|
|
@@ -174,11 +174,16 @@ and no event fires. Set the `url` first, then write `true` again to execute.
|
|
|
174
174
|
name: "",
|
|
175
175
|
email: "",
|
|
176
176
|
},
|
|
177
|
+
submitBody: null,
|
|
177
178
|
submitRequest: false,
|
|
178
179
|
submitResult: null,
|
|
179
180
|
submitError: null,
|
|
181
|
+
submitLoading: false,
|
|
180
182
|
|
|
181
183
|
submit() {
|
|
184
|
+
// A new object on every submit (a retry included): <wcs-fetch> resets
|
|
185
|
+
// `body` to null after each request.
|
|
186
|
+
this.submitBody = { name: this["newUser.name"], email: this["newUser.email"] };
|
|
182
187
|
this.submitRequest = true;
|
|
183
188
|
},
|
|
184
189
|
};
|
|
@@ -195,7 +200,7 @@ and no event fires. Set the `url` first, then write `true` again to execute.
|
|
|
195
200
|
method="POST"
|
|
196
201
|
manual
|
|
197
202
|
data-wcs="
|
|
198
|
-
body:
|
|
203
|
+
body: submitBody;
|
|
199
204
|
trigger: submitRequest;
|
|
200
205
|
value: submitResult;
|
|
201
206
|
error: submitError;
|
|
@@ -212,6 +217,8 @@ and no event fires. Set the `url` first, then write `true` again to execute.
|
|
|
212
217
|
</template>
|
|
213
218
|
```
|
|
214
219
|
|
|
220
|
+
`body` is a **one-shot** input: `<wcs-fetch>` sends it and resets it to `null` (see [Design Notes](#design-notes)). So build the body in the handler that starts the request, and assign a new object every time. Binding the form object itself (`body: newUser`) sends it once: typing writes `newUser.name`, a path *below* the bound one, which never re-applies the binding, so the second submit goes without a body — no error. `wcs-validate` reports that form as `wcs/input-nested-write`.
|
|
221
|
+
|
|
215
222
|
### 5. Infinite scroll with `<wcs-infinite-scroll>`
|
|
216
223
|
|
|
217
224
|
`<wcs-infinite-scroll>` runs an existing `<wcs-fetch>` when its sentinel element enters the viewport.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/fetch",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Declarative fetch component for Web Components. Framework-agnostic async data fetching via wc-bindable-protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|
|
@@ -56,13 +56,14 @@
|
|
|
56
56
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
57
57
|
"@vitest/coverage-v8": "^4.0.15",
|
|
58
58
|
"@vitest/ui": "^4.0.15",
|
|
59
|
+
"@wcstack/state": "file:../state",
|
|
59
60
|
"eslint": "^9.39.1",
|
|
60
61
|
"globals": "^16.5.0",
|
|
61
62
|
"happy-dom": "^20.0.11",
|
|
62
63
|
"rimraf": "^6.0.1",
|
|
63
64
|
"rollup": "^4.22.4",
|
|
64
|
-
"rollup-plugin-dts": "^6.1.1",
|
|
65
65
|
"rollup-plugin-copy": "^3.5.0",
|
|
66
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
66
67
|
"tslib": "^2.8.1",
|
|
67
68
|
"typescript": "^5.9.3",
|
|
68
69
|
"typescript-eslint": "^8.49.0",
|