Skip to content

Commit

Permalink
Merge pull request #39 from webzard-io/fix/global-store
Browse files Browse the repository at this point in the history
fix: make sure notify is called after store.set
  • Loading branch information
tanbowensg authored Mar 20, 2024
2 parents e2016d9 + 86d2c6c commit bbc9511
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "k8s-api-provider",
"version": "0.0.18",
"version": "0.0.19",
"description": "K8s ui data provider",
"main": "lib/index.js",
"module": "lib/index.js",
Expand Down
11 changes: 6 additions & 5 deletions src/global-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,18 @@ export class GlobalStore {
let resolved = false;
kubeApi
.listWatch({
onResponse: async res => {
onResponse: async (res, event) => {
const processedRes = await this.processList(res);
if (!resolved) {
resolve(processedRes as unknown as T);
resolved = true;
}
this.store.set(resource, processedRes);
},
onEvent: async event => {
await this.processItem(event.object);
this.notify(resource, event);

if (event) {
await this.processItem(event.object);
this.notify(resource, event);
}
},
signal,
})
Expand Down
13 changes: 8 additions & 5 deletions src/kube-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type KubeApiListOptions = {
};

type KubeApiListWatchOptions<T> = KubeApiListOptions & {
onResponse?: (response: T) => void;
onResponse?: (response: T, event?: WatchEvent) => void;
onEvent?: (event: WatchEvent) => void;
signal?: AbortSignal;
};
Expand Down Expand Up @@ -379,10 +379,13 @@ export class KubeApi<T extends UnstructuredList> {
break;
default:
}
onResponse?.({
...response,
items,
});
onResponse?.(
{
...response,
items,
},
event
);
onEvent?.(event);
};

Expand Down

0 comments on commit bbc9511

Please sign in to comment.