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

15934fa2aa7b2ce21f091e9b7cffa856?s=128

Manfred Steyer
PRO

November 08, 2018
Tweet

Transcript

  1. @ManfredSteyer Micro Apps with Angular Elements and Web Components Manfred

    Steyer SOFTWAREarchitekt.at ManfredSteyer
  2. @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
  3. @ManfredSteyer ✓ Commodore 64 ✓ 1982 ✓ ~ 1 MHz

    ✓ 64 KB RAM ✓ Disks with 170 KB
  4. @ManfredSteyer Version with two cores ;-) Challenge: Resources!

  5. @ManfredSteyer Challenges today: Complexity

  6. @ManfredSteyer Coordination b/w teams

  7. @ManfredSteyer Long Time Maintain- ability Maintain + Extend for 10

    - 20 yrs
  8. @ManfredSteyer There are milk products lasting longer than some JavaScript

    frameworks
  9. @ManfredSteyer Contents 1) Web Components 2) Micro Apps 3) Recipes

    4) Evaluierung
  10. @ManfredSteyer 1) Web Components

  11. @ManfredSteyer Framework independent Components

  12. @ManfredSteyer Can be dynamically loaded into the browser!

  13. @ManfredSteyer Umbrella Term for several Standards

  14. @ManfredSteyer Standards Templates HTML Imports Custom Elements Shadow DOM

  15. @ManfredSteyer Can be pollyfilled down to IE11

  16. @ManfredSteyer API class CustomerSelector extends HTMLElement { […] }

  17. @ManfredSteyer API class CustomerSelector extends HTMLElement { constructor() { super();

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

    this.attachShadow({mode: 'open'}); this.shadowRoot.innerHTML = '<div>[…]</div>'; } […] } customElements.define('customer-selector', CustomerSelector);
  19. @ManfredSteyer API <script src="customer-selector.min.js"></script> […] <customer-selector></customer-selector>

  20. @ManfredSteyer Angular Elements

  21. @ManfredSteyer Angular Elements @NgModule({ imports: [BrowserModule], declarations: [DateComponent], bootstrap: [],

    entryComponents: [DateComponent] }) export class AppModule { }
  22. @ManfredSteyer Angular Elements @NgModule({ imports: [BrowserModule], declarations: [DateComponent], bootstrap: [],

    entryComponents: [DateComponent] }) export class AppModule { }
  23. @ManfredSteyer Angular Elements @NgModule({ imports: [BrowserModule], declarations: [DateComponent], bootstrap: [],

    entryComponents: [DateComponent] }) export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { } }
  24. @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); } }
  25. @ManfredSteyer Loading MicroApps <script src="date-element.bundle.js"></script> <micro-app></micro-app>

  26. @ManfredSteyer 2) Micro Apps

  27. @ManfredSteyer Idea System Team A Team B Framework Architecture Maintainability?

    Hard to change!
  28. @ManfredSteyer Idea µService µService µService

  29. @ManfredSteyer Idea µApp µApp µApp

  30. @ManfredSteyer Folie▪ 30 Pro Contra

  31. @ManfredSteyer UI Composition w/ Hyperlinks µApp SPA µApp SPA µApp

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

    Application  Consistent Look and Feel
  33. @ManfredSteyer

  34. @ManfredSteyer Web Components for Shared Widgets?

  35. @ManfredSteyer µService Providing a (SPA based) Shell µApp µApp µApp

    Shell ▪ iframes ▪ Bootstrapping several SPAs ▪ Consider Lazy Loading!
  36. @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?
  37. @ManfredSteyer 3) DEMO

  38. @ManfredSteyer µService µApp3 µApp2 µApp1 Shell Web Components for Shell-Architecture

    Shared Widget Shared Widget Shared Widget Web Components for shared Widgets
  39. @ManfredSteyer 3) Recipes

  40. @ManfredSteyer Communication

  41. @ManfredSteyer Communication b/w Web Components <client-a state="appState" message="handle(event)"></client-a> <client-b state="appState"

    message="handle(event)"></client-b> JavaScript in Shell
  42. @ManfredSteyer Routing

  43. @ManfredSteyer Routing /client-a/this/that /client-b/this/that /client-c/this/that :

  44. @ManfredSteyer Routing /client-a/this/that /client-b/this/that /client-c/this/that :

  45. @ManfredSteyer Lazy Loading

  46. @ManfredSteyer Lazy Loading const content = document.getElementById('content');

  47. @ManfredSteyer Lazy Loading const content = document.getElementById('content'); // Add script-Tag

    const script = document.createElement('script'); script.src = [...]; content.appendChild(script);
  48. @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);
  49. @ManfredSteyer Bundling

  50. @ManfredSteyer Bundles Custom Element 1 Custom Element 2 Custom Element

    3 Libraries: Angular, Bootstrap, … Libraries: Angular, Bootstrap, …
  51. @ManfredSteyer Tree Shaking + Ivy (Angular 7.x oder 8?) Custom

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

    Element 3 Libraries: Angular, Bootstrap, … UMD ngx-build-plus Drawbacks: Complexity, no isolation
  53. @ManfredSteyer 4) Choosing a Solution

  54. @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?
  55. @ManfredSteyer Shared Widgets Packages (e. g. w/ Web Components) Lazy

    Loaded Web Components Inner Sourcing Seperate Ways …
  56. @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
  57. @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
  58. @ManfredSteyer Contact and Downloads [mail] manfred.steyer@SOFTWAREarchitekt.at [web] SOFTWAREarchitekt.at [twitter] ManfredSteyer

    d Slides & Examples