Scalable javascript architecture - DrupalCon · 2016-06-28 · Scalable javascript architecture...

Post on 22-May-2020

31 views 0 download

Transcript of Scalable javascript architecture - DrupalCon · 2016-06-28 · Scalable javascript architecture...

Scalable javascript architectureJavascript developer - @frankbaele

The global blob

Step 1

Study the language

Step 2

Be critical of Frameworks

UseDesign patterns

Step 3

Structural

Creational

Behavioral

5 design patternsFor scalable javascript architecture

Revealing Module pattern

● Module Pattern● Reveal only what you want● Highly testable● Private functions and variables

Main Controls PlayButton

require require

Audio

ProgressBar

Do not do’sAccess globals

Extend globals

Alter input params

Super long modules

Think this is easy

Welcome to the module ecosystem!

Commonjs - amd - es6 modules

Browserify - RequireJs - Webpack

NPM

Nodejs way

Main Controller PlayButton

require require

Lodash.foreach

Virtual dom

require

NPM

Audio

ProgressBar

Dependency Inject All the things!

PlayButton

Audio

ProgressBar

Video

PlayBack Rate

Youtube

Mediator pattern

PlayButton

Audio

ProgressBar

Video

PlayBack Rate

Youtube

Mute

Mediator

Mediator js side effects● Debugging● Regression testing● Refactoring● Unit testing● Measuring

What do I do with my data?

What do I do with my controllers?

Singleton

Factory

Pass by reference

Facade pattern

Facade

{ Closure }● Study the language● Be critical of frameworks● Modularize● Use mediator to cut deps● Use creational patterns● Hide innerworkings● Use the right pattern in the right place

Questions?

MaterialBackground image: motorcycle kids - Michael rogier

Framework graph: http://www.planningforaliens.com/blog/2016/04/11/why-js-development-is-crazy/