Move communication workbench to use resource store
Because it's getting better all the time, including by adding the ability to get new resources when they get created over SSE.
This commit is contained in:
parent
72eef554ea
commit
b4ae9e5a95
6 changed files with 50 additions and 116 deletions
|
|
@ -31,8 +31,12 @@ function createResourceStore<dto, full extends uriHaver>(
|
|||
|
||||
// Subscription
|
||||
SSEManager.subscribe((msg: SSEMessageResource) => {
|
||||
if (msg.resource.startsWith(resource_name) && msg.type == "updated") {
|
||||
fetchByURI(msg.uri);
|
||||
if (msg.resource.startsWith(resource_name)) {
|
||||
if (msg.type == "created") {
|
||||
fetchByURI(msg.uri);
|
||||
} else if (msg.type == "updated") {
|
||||
fetchByURI(msg.uri);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -92,10 +96,22 @@ function createResourceStore<dto, full extends uriHaver>(
|
|||
throw err;
|
||||
}
|
||||
}
|
||||
function getAll(): full[] | null {
|
||||
if (_resourceFetchAll) {
|
||||
return Array.from(_resourceByURI.value.values());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function hasAll(): boolean {
|
||||
return !!_resourceFetchAll.value;
|
||||
}
|
||||
function loadingAll(): boolean {
|
||||
return !!_resourceFetchAll.value;
|
||||
}
|
||||
function loadingURI(uri: string): boolean {
|
||||
function loadingURI(uri: string | undefined): boolean {
|
||||
if (uri === undefined) {
|
||||
return false;
|
||||
}
|
||||
return !!_resourceFetchByURI.value.get(uri);
|
||||
}
|
||||
function uriFromID(id: string): string {
|
||||
|
|
@ -108,6 +124,8 @@ function createResourceStore<dto, full extends uriHaver>(
|
|||
fetchAll,
|
||||
fetchByID,
|
||||
fetchByURI,
|
||||
getAll,
|
||||
hasAll,
|
||||
loadingAll,
|
||||
loadingURI,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue