Skip to content

Commit

Permalink
feat(core): add onInitialized hooks for ApplicationComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk committed Jun 5, 2024
1 parent 3734ce2 commit 4239258
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .changeset/dull-dogs-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@difizen/mana-core': patch
'@difizen/mana-docs': patch
'@difizen/mana-app': patch
'@difizen/mana-common': patch
'@difizen/mana-l10n': patch
'@difizen/mana-observable': patch
'@difizen/mana-react': patch
'@difizen/mana-syringe': patch
'@difizen/mana-ui': patch
---

feat: add onInitialized hooks for ApplicationComponent
14 changes: 14 additions & 0 deletions packages/mana-core/src/components/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const PortalModule = ManaModule.create().register(
);

export interface ApplicationProps extends ContextProps {
onInitialized?: (ctx: ManaContext, app: Application) => void;

Check warning on line 23 in packages/mana-core/src/components/application.tsx

View check run for this annotation

Codecov / codecov/patch

packages/mana-core/src/components/application.tsx#L23

Added line #L23 was not covered by tests
onReady?: (ctx: ManaContext, app: Application) => void;
/**
* 使用路由模式时需要开启
Expand All @@ -31,6 +32,7 @@ export interface ApplicationProps extends ContextProps {
export const ApplicationComponent = (props: ApplicationProps) => {
const {
onReady,
onInitialized,

Check warning on line 35 in packages/mana-core/src/components/application.tsx

View check run for this annotation

Codecov / codecov/patch

packages/mana-core/src/components/application.tsx#L35

Added line #L35 was not covered by tests
modules = [],
loading,
renderChildren = false,
Expand Down Expand Up @@ -61,6 +63,18 @@ export const ApplicationComponent = (props: ApplicationProps) => {
if (current && app) {
app.host = current;
}
appState
.reachedState(ApplicationState.Initialized)
.then(() => {
if (onInitialized) {
onInitialized(ctx, app);
}
return;
})
.catch((_e) => {
//
});

Check warning on line 77 in packages/mana-core/src/components/application.tsx

View check run for this annotation

Codecov / codecov/patch

packages/mana-core/src/components/application.tsx#L66-L77

Added lines #L66 - L77 were not covered by tests
app.start();
appState
.reachedState(ApplicationState.Ready)
Expand Down

0 comments on commit 4239258

Please sign in to comment.