Debug: Context Resolver Buffering - rollthecloudinc/quell GitHub Wiki
readonly hookupContextSub = combineLatest(
this.contexts$,
// this.nested$,
this.afterContentInit$
).pipe(
// filter(([ _, nested ]) => !nested),
map(([ contexts ]) => contexts),
switchMap(contexts => this.inlineContextResolver.resolveMerged(contexts, `panelpage:${uuid.v4()}`).pipe(
switchMap(resolvedContext => this.cxm.getPlugins().pipe(
map(plugins => ({ contexts, resolvedContext, globalPlugins: Array.from(plugins.values()).filter(p => p.global === true) }))
)),
take(1)
)),
tap(() => {
if (this.resolveSub) {
this.resolveSub.unsubscribe();
}
}),
tap(({ contexts, resolvedContext, globalPlugins }) => {
this.resolvedContext = resolvedContext;
const short$ = new Subject<void>();
if (isPlatformServer(this.platformId)) {
const interval = setInterval(() => {
if (PanelPageComponent.registredContextListeners.size === 0) {
short$.next();
short$.complete();
clearInterval(interval);
}
}, 1000);
}
this.resolveSub = this.inlineContextResolver.resolveMergedSingle(contexts).pipe(
skip(globalPlugins.length + (contexts ? contexts.length : 0)),
tap(() => PanelPageComponent.registredContextListeners.add(this.instanceUniqueIdentity)),
tap(v => console.log('buffer', v)),
bufferTime(1),
tap(buffered => {
if (buffered.length === 0) {
PanelPageComponent.registredContextListeners.delete(this.instanceUniqueIdentity);
}
}),
filter(buffered => buffered.length !== 0),
tap(buffered => {
this.contextsChanged = buffered.reduce((p, [cName, _]) => [ ...p, ...(p.includes(cName) ? [] : [cName]) ], []);
this.resolvedContext = buffered.reduce((p, [cName, cValue]) => ({ ...p, [cName]: cValue }), this.resolvedContext);
}),
tap(() => PanelPageComponent.registredContextListeners.delete(this.instanceUniqueIdentity)),
isPlatformServer(this.platformId) ? takeUntil(short$) : tap(() => {})
).subscribe();
})
).subscribe();
At the moment the bufferTime() results in an endless buffer check in the browser. This was implemented as a work around to force server-side rendering to work. We don't want an endless buffer check loop in the browser. Instead the changes should be buffered for a set amount of time and after a period of inactivity buffer out once until more changes come in and repeat the process.