Skip to content

Commit

Permalink
Fix #579 (piral-ng destroying all modules instead of only the intende…
Browse files Browse the repository at this point in the history
…d one)
  • Loading branch information
Siphalor committed Jan 31, 2023
1 parent 143d72e commit d544cf6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/converters/piral-ng/src/startup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import type { ComponentContext } from 'piral-core';
import type { NgOptions } from './types';
import { enableProdMode, NgModuleRef, NgZone, PlatformRef } from '@angular/core';
import {
createPlatformFactory,
enableProdMode,
NgModuleRef,
NgZone,
PlatformRef,
ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS,
} from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {
ɵplatformCoreDynamic as platformCoreDynamic,
ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
} from '@angular/platform-browser-dynamic';
import { getId, getNgVersion } from './utils';

function getVersionHandler(versions: Record<string, () => void>) {
Expand All @@ -11,11 +21,19 @@ function getVersionHandler(versions: Record<string, () => void>) {
return versions[version];
}

// Equivalent to platformBrowserDynamic, but with support for multiple platforms
const customPlatformDynamicFactory = createPlatformFactory(platformCoreDynamic, 'piralDynamic', [
...INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
{
provide: ALLOW_MULTIPLE_PLATFORMS,
useValue: true,
},
]);
const runningModules: Array<[any, NgModuleInt, PlatformRef]> = [];

function startNew(BootstrapModule: any, context: ComponentContext, ngOptions?: NgOptions) {
const path = context.publicPath || '/';
const platform = platformBrowserDynamic([
const platform = customPlatformDynamicFactory([
{ provide: 'Context', useValue: context },
{ provide: APP_BASE_HREF, useValue: path },
]);
Expand Down

0 comments on commit d544cf6

Please sign in to comment.