Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro Frontends with Angular Elements and Ivy: ...

Micro Frontends with Angular Elements and Ivy: A Perfect Match?

Avatar for Manfred Steyer

Manfred Steyer

November 07, 2019
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer Micro Frontends with Angular Elements and Ivy: A Perfect

    Match? Manfred Steyer SOFTWAREarchitekt.at ManfredSteyer
  2. @ManfredSteyer ✓ Commodore 64 ✓ 1982 ✓ ~ 1 MHz

    ✓ 64 KB RAM ✓ Disks with 170 KB
  3. @ManfredSteyer About me… • Manfred Steyer SOFTWAREarchitekt.at • Angular Trainings

    and Consultancy • Google Developer Expert (GDE) • Angular Tooling Team Page ▪ 9 Manfred Steyer Public: München, Frankfurt, Wien In-House: everywhere http://softwarearchitekt.at/workshops
  4. @ManfredSteyer Angular Elements @NgModule({ imports: [BrowserModule], declarations: [DateComponent], bootstrap: [],

    entryComponents: [DateComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { } }
  5. @ManfredSteyer Angular Elements @NgModule({ imports: [BrowserModule], declarations: [DateComponent], bootstrap: [],

    entryComponents: [DateComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { const DateElement = createCustomElement( DateComponent, { injector: this.injector }); customElements.define('date-picker', DateElement); } }
  6. @ManfredSteyer ✓ Simple  Loosing State  Load a new

    Application  Consistent Look and Feel
  7. @ManfredSteyer µService Providing a (SPA based) Shell µFrontend µFrontend µFrontend

    Shell ▪ iframes ▪ Bootstrapping several SPAs ▪ Consider Lazy Loading!
  8. @ManfredSteyer Common Interface for µFrontends • Shell should not know

    details of µFrontend and used Frameworks! • Eventing • Wrap µFrontend as Web Component? • Shadow DOM
  9. @ManfredSteyer µService µFE3 µFE2 µFE1 Shell Web Components for Shell-Architecture

    Shared Widget Shared Widget Shared Widget Web Components for shared Widgets
  10. @ManfredSteyer Communication via Service Bus (Alternative) window.serviceBus = new ReplaySubject<Event>(10)

    // Sender window.serviceBus.next(…); // Receiver window.serviceBus.subscribe(event => handleEvent(event));
  11. @ManfredSteyer Custom DOM Events (Alternative) // Sender window.addEventListener('micro-frontend-event', (event) =>

    …); // Receiver window.dispatchEvent(new CustomEvent('micro-frontend-event', …));
  12. @ManfredSteyer Lazy Loading const content = document.getElementById('content'); // Add script-Tag

    const script = document.createElement('script'); script.src = [...]; content.appendChild(script);
  13. @ManfredSteyer Lazy Loading const content = document.getElementById('content'); // Add script-Tag

    const script = document.createElement('script'); script.src = [...]; content.appendChild(script); // Add Element const element: HTMLElement = document.createElement('client-a'); element.addEventListener('message', (event) => [...]); element.setAttribute('appState', [...]); content.appendChild(element);
  14. @ManfredSteyer Bundles Custom Element 1 Custom Element 2 Custom Element

    3 Libraries: Angular, Bootstrap, … Libraries: Angular, Bootstrap, …
  15. @ManfredSteyer Roadmap (details can change) • Ivy behind a flag

    Angular 8 (Spring 2019) • Ivy by default • No breaking changes Angular 9 (Fall 2019)
  16. @ManfredSteyer Where Ivy can help ✓ Widgets based on @angular/core,

    @angular/common  Libs like @angular/forms or @angular/router
  17. @ManfredSteyer Sharing Libs Custom Element 1 Custom Element 2 Custom

    Element 3 Libraries: Angular, RxJS, … UMD Drawbacks: Complexity, no isolation
  18. @ManfredSteyer Some General Advice Shared state, navigation b/w apps Hyperlinks

    Legacy Apps or *very very* strong isolation? iframes Separate Deployment/ mix Technologies? Bootstrap several SPAs Deployment Monolith little much yes no yes no Not a good fit for public web sites
  19. @ManfredSteyer Blog > SOFTWAREarchitekt.at • A Software Architect's Approach Towards

    Using Angular (And SPAs In General) For Microservices Aka Microfrontends • Micro Apps With Web Components Using Angular Elements • Angular Elements: A dynamic Dashboard … • Angular, React, Vue.Js And Co. Peacefully United Thanks To Micro Apps And Web Components
  20. @ManfredSteyer Conclusion Web Components: Decoupling from your Framework Micro FE:

    Decoupling b/w Teams & Projects Web Components + Micro FE = ❤️ Best Technology for your current project