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

Nodevember Orchestrating Apps by Composing Angu...

Nodevember Orchestrating Apps by Composing Angular Directives

Jeremy Fairbank

November 15, 2015
Tweet

More Decks by Jeremy Fairbank

Other Decks in Programming

Transcript

  1. – Wikipedia “The various visual elements, known as elements of

    design, formal elements, or elements of art, are the vocabulary with which the visual artist composes. These elements in the overall design usually relate to each other and to the whole art work.” What is composition?
  2. – Wikipedia “The way in which something is put together

    or arranged. The combination of parts or elements that make up something.” What is composition?
  3. Design Principles • Modularity • Separation of concerns (SOC) •

    Loose coupling • High cohesion • Composition over inheritance • Ad nauseam…
  4. Composition and Angular • Focus on smaller problems to solve

    a large problem • Apply design principles to directives • Build app in terms of directives • Decompose large directives into small reusable directives • Refactoring and adding new features becomes more manageable
  5. Data Flow • Connecting directives to build an “app” through

    the flow of data • Handling model data among directives • Many approaches with pros and cons App Directive Directive Directive Directive Directive Directive Directive Directive Directive
  6. Data Flow 1.Isolate scope bindings and callbacks 2.controllerAs and bindToController

    3.Event broadcasting and emitting App Directive Directive Directive Directive Directive Directive Directive Directive Directive
  7. Isolate Scope and Controller Binding • Black box a directive

    to be self-contained and reusable • Think in terms of small pieces • Establish well-defined interface/API through HTML attributes • Eliminate $scope soup (with controller binding) • Juggle multiple points of state • A lot of markup
  8. Events • Decouple directives • Isolate state more easily •

    Cleaner markup • Indirection of data flow (who responds to an event?) • Have to remember and duplicate event names (may hurt directive reuse)
  9. Refactoring • Easier to change or update app • Don’t

    have to touch entire app, just an individual directive – Touching multiple pieces may mean better SOC needed – SOC is evolutionary for the lifetime of the app