@soleil-se/app-util 5.4.1 → 5.5.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [5.5.0] - 2023-08-25
9
+
10
+ - Remove abort controllers in `fetchJson` since it's better to handle this seperatly case by case.
11
+
8
12
  ## [5.4.1] - 2023-08-22
9
13
 
10
14
  - Add `/edit-app-config` to ignored URI:s in `fetchJson`.
package/README.md CHANGED
@@ -272,15 +272,23 @@ async function getItems() {
272
272
  }
273
273
  ```
274
274
 
275
- Handle aborted requests called in rapid succession, for example searching when typing.
275
+ When searching on input you probably want to abort the ongoing request to avoid weird bugs when
276
+ the first request might be completed after the subsequent one.
277
+ Pass an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) signal
278
+ in options and abort the ongoing call.
276
279
 
277
280
  ```js
278
281
  import { fetchJson } from '@soleil-se/webapp-util/client';
279
282
 
283
+ let controller;
284
+
280
285
  async function onInput() {
286
+ if(controller) controller.abort();
287
+ controller = new AbortController();
288
+
281
289
  const params = { query: 'foo' };
282
290
  try {
283
- const result = await fetchJson('/search', { params });
291
+ const result = await fetchJson('/search', { params, signal: controller.signal });
284
292
  console.log(result);
285
293
  } catch(e) {
286
294
  // Ignore aborts due to new search.
@@ -29,12 +29,8 @@ async function handleResponse(response) {
29
29
  return json;
30
30
  }
31
31
 
32
- const controllers = {};
33
-
34
32
  export default function fetchJson(uri, { params = {}, retries = 0, ...options } = {}) {
35
- if (controllers[uri]) controllers[uri].abort();
36
- controllers[uri] = new AbortController();
37
- return fetch(getUrl(uri, params), { signal: controllers[uri].signal, ...options })
33
+ return fetch(getUrl(uri, params), options)
38
34
  .then(handleResponse)
39
35
  .catch((error) => {
40
36
  const isTimeout = error.status === 504 || error.status === 408 || error.message.includes('SocketTimeoutException');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleil-se/app-util",
3
- "version": "5.4.1",
3
+ "version": "5.5.0",
4
4
  "description": "Utility and rendering functions for WebApps.",
5
5
  "main": "./common/index.js",
6
6
  "author": "Soleil AB",
@@ -14,6 +14,6 @@
14
14
  "peerDependencies": {
15
15
  "@sitevision/api": "*"
16
16
  },
17
- "gitHead": "e95307bdefd374f4f325b6619430b2135c9334e2",
17
+ "gitHead": "b70a56edccc70b2af2da994e9fd4a99a7a908003",
18
18
  "dependencies": {}
19
19
  }