Skip to content

Commit

Permalink
fix: fixed initializing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kobezzza committed Jan 15, 2024
1 parent 9e239cd commit 4fb8aa3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
24 changes: 22 additions & 2 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,29 @@
*/

import '@v4fire/core/core';
import { resolveAfterDOMLoaded } from 'core/event';

import initApp from 'core/init';
import createInitAppSemaphore from 'core/init/semaphore';

export { initApp, createInitAppSemaphore };

//#unless runtime has storybook
import 'core/init';
if (SSR) {
process.on('unhandledRejection', stderr);

} else {
resolveAfterDOMLoaded()
.then(() => {
const
targetToMount = document.querySelector<HTMLElement>('[data-root-component]'),
rootComponentName = targetToMount?.getAttribute('data-root-component'),
ready = createInitAppSemaphore();

return initApp(rootComponentName, {targetToMount, ready});
})

.catch(stderr);
}

export { default as initApp } from 'core/init';
//#endunless
7 changes: 2 additions & 5 deletions src/core/init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,12 @@ When calling this function from SSR, it is necessary to pass the name of the roo
and additional parameters can also be passed.

```typescript
// Or, import { initApp } from 'core';

import initApp from 'core/init';
import createSemaphore from 'core/init/semaphore';
import { initApp, createInitAppSemaphore } from 'core';

import type { ComponentOptions } from 'core/component/engines';

initApp('p-v4-components-demo', {
ready: createSemaphore(),
ready: createInitAppSemaphore(),
route: '/user/12345',

setup(rootComponentParams: ComponentOptions) {
Expand Down
23 changes: 2 additions & 21 deletions src/core/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
*/

import { initGlobalEnv } from 'core/env';
import { resolveAfterDOMLoaded } from 'core/event';

import createSemaphore from 'core/init/semaphore';
import type { App, InitAppOptions } from 'core/init/interface';

import initDom from 'core/init/dom';
import initState from 'core/init/state';
import initABT from 'core/init/abt';
import prefetchInit from 'core/init/prefetch';
import hydratedRouteInit from 'core/init/hydrated-route';

import type { App, InitAppOptions } from 'core/init/interface';

/**
* Initializes the application
*
Expand All @@ -44,20 +42,3 @@ export default async function initApp(
const createApp = await opts.ready('');
return createApp(rootComponent, opts);
}

if (SSR) {
process.on('unhandledRejection', stderr);

} else {
resolveAfterDOMLoaded()
.then(() => {
const
targetToMount = document.querySelector<HTMLElement>('[data-root-component]'),
rootComponentName = targetToMount?.getAttribute('data-root-component'),
ready = createSemaphore();

return initApp(rootComponentName, {targetToMount, ready});
})

.catch(stderr);
}
2 changes: 1 addition & 1 deletion src/core/init/semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { InitAppOptions, AppSSR } from 'core/init/interface';
/**
* A factory for creating a semaphore over application initialization
*/
export default function createSemaphore(): (flag: string) => Promise<ReturnType<typeof createAppInitializer>> {
export default function createInitAppSemaphore(): (flag: string) => Promise<ReturnType<typeof createAppInitializer>> {
return createsAsyncSemaphore(createAppInitializer, ...flags);
}

Expand Down

0 comments on commit 4fb8aa3

Please sign in to comment.