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: lifecycle event handling in plugin holder #2244

Merged
merged 3 commits into from
May 15, 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
8 changes: 7 additions & 1 deletion packages/core/src/services/lifecycle/lifecycle.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ export class LifecycleService extends Disposable {
subscriber.next(LifecycleStages.Rendered);
}

return this._lifecycle$.subscribe(subscriber);
this._lifecycle$.subscribe((stage) => {
subscriber.next(stage);

if (stage === LifecycleStages.Steady) {
subscriber.complete();
}
});
});
}

Expand Down
15 changes: 8 additions & 7 deletions packages/core/src/services/plugin/plugin-holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

/* eslint-disable ts/no-explicit-any */

import { type Ctor, Inject, Injector } from '@wendellhu/redi';
import type { Ctor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';

import { finalize } from 'rxjs';
import { LifecycleStages } from '../lifecycle/lifecycle';
import { LifecycleInitializerService, LifecycleService } from '../lifecycle/lifecycle.service';
import { Disposable } from '../../shared/lifecycle';
Expand Down Expand Up @@ -74,12 +76,11 @@ export class PluginHolder extends Disposable {
const plugins = this._pluginRegistry.getRegisterPlugins().map(({ plugin, options }) => this._initPlugin(plugin, options));
this._pluginRegistry.removePlugins();

const lifecycleSubscription = this.disposeWithMe(this._lifecycleService.subscribeWithPrevious().subscribe((stage) => {
this._pluginsRunLifecycle(plugins, stage);
if (stage === LifecycleStages.Steady) {
lifecycleSubscription.dispose();
}
}));
const subscription = this.disposeWithMe(this._lifecycleService.subscribeWithPrevious()
// It has to been async because the finalize may execute synchronously after we
// make the subscription. For example, the lifecycle service is already in stage "steady".
.pipe(finalize(() => { Promise.resolve().then(() => subscription.dispose()); }))
.subscribe((stage) => { this._pluginsRunLifecycle(plugins, stage); }));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export class SheetSkeletonManagerService implements IDisposable {
removeSkeleton(searchParam: Pick<ISheetSkeletonManagerSearch, 'unitId'>) {
const index = this._sheetSkeletonParam.findIndex((param) => param.unitId === searchParam.unitId);
if (index !== -1) {
const skeletonParam = this._sheetSkeletonParam[index];
skeletonParam.skeleton.dispose();

this._sheetSkeletonParam.splice(index, 1);
this._currentSkeletonBefore$.next(null);
this._currentSkeleton$.next(null);
Expand Down
Loading