mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'fix-1898/watch-api-streaming' into fix/store.loadAll
# Conflicts: # src/renderer/api/kube-watch-api.ts
This commit is contained in:
commit
219852dce1
@ -116,7 +116,7 @@ export class KubeWatchApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isAllowedApi(api: KubeApi): boolean {
|
isAllowedApi(api: KubeApi): boolean {
|
||||||
return !!this.cluster?.isAllowedResource(api.kind);
|
return !!this?.cluster?.isAllowedResource(api.kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeApi(api: KubeApi | KubeApi[]): () => void {
|
subscribeApi(api: KubeApi | KubeApi[]): () => void {
|
||||||
@ -142,8 +142,14 @@ export class KubeWatchApi {
|
|||||||
const limitRequests = plimit(1); // load stores one by one to allow quick skipping when fast clicking btw pages
|
const limitRequests = plimit(1); // load stores one by one to allow quick skipping when fast clicking btw pages
|
||||||
const preloading: Promise<any>[] = [];
|
const preloading: Promise<any>[] = [];
|
||||||
const apis = new Set(stores.map(store => store.getSubscribeApis()).flat());
|
const apis = new Set(stores.map(store => store.getSubscribeApis()).flat());
|
||||||
|
const unsubscribeList: (() => void)[] = [];
|
||||||
let isUnsubscribed = false;
|
let isUnsubscribed = false;
|
||||||
|
|
||||||
|
const subscribe = () => {
|
||||||
|
if (isUnsubscribed) return;
|
||||||
|
apis.forEach(api => unsubscribeList.push(this.subscribeApi(api)));
|
||||||
|
};
|
||||||
|
|
||||||
if (preload) {
|
if (preload) {
|
||||||
for (const store of stores) {
|
for (const store of stores) {
|
||||||
preloading.push(limitRequests(async () => {
|
preloading.push(limitRequests(async () => {
|
||||||
@ -154,35 +160,24 @@ export class KubeWatchApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscribe = () => {
|
if (waitUntilLoaded) {
|
||||||
const unsubscribeList: (() => void)[] = [];
|
Promise.all(preloading).then(subscribe, error => {
|
||||||
|
this.log({
|
||||||
const subscribeApis = () => {
|
message: new Error("Loading stores has failed"),
|
||||||
if (isUnsubscribed) return;
|
meta: { stores, error, options },
|
||||||
apis.forEach(api => unsubscribeList.push(this.subscribeApi(api)));
|
|
||||||
};
|
|
||||||
|
|
||||||
if (waitUntilLoaded) {
|
|
||||||
Promise.all(preloading).then(subscribeApis, error => {
|
|
||||||
this.log({
|
|
||||||
message: new Error("Loading stores has failed"),
|
|
||||||
meta: { stores, error, options },
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
subscribeApis();
|
} else {
|
||||||
}
|
subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
// unsubscribe
|
// unsubscribe
|
||||||
return () => {
|
return () => {
|
||||||
if (isUnsubscribed) return;
|
if (isUnsubscribed) return;
|
||||||
isUnsubscribed = true;
|
isUnsubscribed = true;
|
||||||
limitRequests.clearQueue();
|
limitRequests.clearQueue();
|
||||||
unsubscribeList.forEach(unsubscribe => unsubscribe());
|
unsubscribeList.forEach(unsubscribe => unsubscribe());
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return subscribe();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async connectionCheck() {
|
protected async connectionCheck() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user