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

Micro Apps with Angular Elements and Web Components @w-jax 2018 in Munich

Micro Apps with Angular Elements and Web Components @w-jax 2018 in Munich

Manfred Steyer

November 08, 2018
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer About me… • Manfred Steyer • SOFTWAREarchitekt.at • Angular

    Trainings and Consultancy • Google Developer Expert (GDE) Page ▪ 2 Manfred Steyer Public: Vienna, München, Zürich In-House: everywhere http://softwarearchitekt.at/workshops
  2. @ManfredSteyer ✓ Commodore 64 ✓ 1982 ✓ ~ 1 MHz

    ✓ 64 KB RAM ✓ Disks with 170 KB
  3. @ManfredSteyer API class CustomerSelector extends HTMLElement { constructor() { super();

    this.attachShadow({mode: 'open'}); this.shadowRoot.innerHTML = '<div>[…]</div>'; } […] }
  4. @ManfredSteyer API class CustomerSelector extends HTMLElement { constructor() { super();

    this.attachShadow({mode: 'open'}); this.shadowRoot.innerHTML = '<div>[…]</div>'; } […] } customElements.define('customer-selector', CustomerSelector);
  5. @ManfredSteyer Angular Elements @NgModule({ imports: [BrowserModule], declarations: [DateComponent], bootstrap: [],

    entryComponents: [DateComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { } }
  6. @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); } }
  7. @ManfredSteyer UI Composition w/ Hyperlinks µApp SPA µApp SPA µApp

    SPA <a href="…>…</a> <a href="…>…</a>
  8. @ManfredSteyer ✓ Simple  Loosing State  Load a new

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

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

    details of µApp and used Frameworks! • µApp provides events • µApp consumes events • Wrap µApp as Web Component?
  11. @ManfredSteyer µService µApp3 µApp2 µApp1 Shell Web Components for Shell-Architecture

    Shared Widget Shared Widget Shared Widget Web Components for shared Widgets
  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 Tree Shaking + Ivy (Angular 7.x oder 8?) Custom

    Element 1 Custom Element 2 Custom Element 3
  16. @ManfredSteyer Sharing Libs Custom Element 1 Custom Element 2 Custom

    Element 3 Libraries: Angular, Bootstrap, … UMD ngx-build-plus Drawbacks: Complexity, no isolation
  17. @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 Monorepo little much yes no yes no Not a good fit for public web sites Wrap as Web Component?
  18. @ManfredSteyer Shared Widgets Packages (e. g. w/ Web Components) Lazy

    Loaded Web Components Inner Sourcing Seperate Ways …
  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 App:

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