-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dae812
commit c224d9a
Showing
9 changed files
with
70 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 47 additions & 13 deletions
60
modulefederation/libs/portal/src/lib/federation/react/react-wrapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,49 @@ | ||
import { AfterContentInit, Component } from "@angular/core"; | ||
import { Component, AfterContentInit, ViewChild, ElementRef, OnDestroy } from '@angular/core'; | ||
import { loadRemoteModule } from "@nx/angular/mf"; | ||
|
||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom/client'; | ||
import { ActivatedRoute } from "@angular/router"; | ||
import { Root } from 'react-dom/client'; | ||
|
||
export type ReactWrapperOptions = { | ||
module: string | ||
}; | ||
|
||
@Component({ | ||
selector: 'react-component-wrapper', | ||
template: '<div #vc></div>', | ||
}) | ||
// eslint-disable-next-line @angular-eslint/component-class-suffix | ||
export class ReactComponentWrapper implements AfterContentInit { | ||
// implement AfterContentInit | ||
|
||
ngAfterContentInit(): void { | ||
// TODO | ||
console.log() | ||
} | ||
} | ||
selector: 'react-component-wrapper', | ||
template: '<div #container></div>' | ||
}) | ||
export class ReactComponentWrapper implements AfterContentInit, OnDestroy { | ||
// instance data | ||
|
||
@ViewChild('container', { static: true }) container!: ElementRef; | ||
|
||
options! : ReactWrapperOptions | ||
root!: Root | ||
|
||
// constructor | ||
|
||
constructor(private route: ActivatedRoute) {} | ||
|
||
// implement AfterContentInit | ||
|
||
async ngAfterContentInit() { | ||
this.options = this.route.snapshot.data as ReactWrapperOptions | ||
|
||
const module = await loadRemoteModule(this.options.module, "./Module"); | ||
|
||
const component = module.default; // Assuming default export | ||
const reactElement = React.createElement(component); // args? | ||
|
||
this.root = ReactDOM.createRoot(this.container.nativeElement); | ||
|
||
this.root.render(reactElement); // Render using 'createRoot' | ||
} | ||
|
||
// implement OnDestroy | ||
|
||
ngOnDestroy(): void { | ||
this.root.unmount() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters