Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure notify is called after store.set #39

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading