@mittwald/api-models 4.483.0 → 4.484.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.
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
import { reactProvisionContext } from "./reactProvisionContext.js";
|
|
2
|
-
import { refresh } from "@mittwald/react-use-promise";
|
|
2
|
+
import { asyncResourceStore, refresh } from "@mittwald/react-use-promise";
|
|
3
3
|
import { Store } from "@mittwald/react-use-promise/store";
|
|
4
4
|
const cacheTagStore = new Store();
|
|
5
5
|
export const refreshProvideReactCache = (tag) => {
|
|
6
|
-
cacheTagStore.getAll(tag)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const idSets = cacheTagStore.getAll(tag);
|
|
7
|
+
const ids = new Set(idSets.flatMap((idSet) => [...idSet]));
|
|
8
|
+
if (ids.size === 0) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const resources = asyncResourceStore.getAll();
|
|
12
|
+
const [firstResource] = resources;
|
|
13
|
+
// AsyncResource.meta only exists since @mittwald/react-use-promise 4.1. All
|
|
14
|
+
// resources come from the same version, so checking one of them is enough.
|
|
15
|
+
if (firstResource && !firstResource.meta) {
|
|
16
|
+
ids.forEach((id) => refresh({ tag: id }));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const existingIds = new Set();
|
|
20
|
+
resources.forEach((resource) => {
|
|
21
|
+
const id = resource.meta.tags?.tags.find((resourceTag) => typeof resourceTag === "string" && ids.has(resourceTag));
|
|
22
|
+
if (id !== undefined) {
|
|
23
|
+
existingIds.add(id);
|
|
24
|
+
resource.refresh();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
idSets.forEach((idSet) => {
|
|
28
|
+
idSet.forEach((id) => {
|
|
29
|
+
if (!existingIds.has(id)) {
|
|
30
|
+
idSet.delete(id);
|
|
31
|
+
}
|
|
11
32
|
});
|
|
12
33
|
});
|
|
34
|
+
// Store.releaseBy only exists since @mittwald/react-use-promise 4.3
|
|
35
|
+
if (idSets.some((idSet) => idSet.size === 0)) {
|
|
36
|
+
cacheTagStore.releaseBy?.((idSet) => idSet.size === 0);
|
|
37
|
+
}
|
|
13
38
|
};
|
|
14
39
|
export const addTagToProvideReactCache = (tag) => {
|
|
15
40
|
const context = reactProvisionContext.use();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/api-models",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.484.0",
|
|
4
4
|
"author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Collection of domain models for coherent interaction with the API",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"test:unit": "node --experimental-vm-modules $(yarn bin jest)"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@mittwald/api-client": "^4.
|
|
42
|
+
"@mittwald/api-client": "^4.484.0",
|
|
43
43
|
"another-deep-freeze": "1.0.0",
|
|
44
44
|
"context": "^3.0.33",
|
|
45
45
|
"dinero.js": "^1.9.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@jest/globals": "^29.7.0",
|
|
53
|
-
"@mittwald/react-use-promise": "^4.
|
|
53
|
+
"@mittwald/react-use-promise": "^4.3.0",
|
|
54
54
|
"@testing-library/dom": "^10.4.1",
|
|
55
55
|
"@testing-library/jest-dom": "^6.9.1",
|
|
56
56
|
"@testing-library/react": "^16.3.0",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"optional": true
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "79279728fdedf7a405c510b4080867b756d0d908"
|
|
90
90
|
}
|