27
Tungsten.js Building a Modular Framework

Tungsten.js: Building a Modular Framework

Embed Size (px)

Citation preview

Page 1: Tungsten.js: Building a Modular Framework

Tungsten.jsBuilding a Modular Framework

Page 2: Tungsten.js: Building a Modular Framework

Who Are We

Andrew Rota@andrewrota

Matt DeGennaro@thedeeg

Page 3: Tungsten.js: Building a Modular Framework

Wayfair

Wayfair.com is an online destination for all thingshome

Selection of more than seven million home items from 7,000suppliers

Ecommerce company since 2002Several large websites running a sharedcodebasePHP backend for customer­facing pages

2,000,000+ lines of code for custom e­commerce platform2,000+ JavaScript modules

Page 4: Tungsten.js: Building a Modular Framework

Why we did

For a large codebase, overhauls are rarelypossible a good ideaWe needed a framework that we could upgradeas technologies shifted

Page 5: Tungsten.js: Building a Modular Framework

Let's Talk About Modularity

­ Edsger W. Dijkstra, Notes on Structured Programming, 1970

Large systems should be constructed outof smaller components; each componentshould be defined only by its interface andnot by its implementation

Page 6: Tungsten.js: Building a Modular Framework

Systems Need toAdapt

Page 7: Tungsten.js: Building a Modular Framework

Lavaflow

Page 8: Tungsten.js: Building a Modular Framework

ModularityRequires Choices

Page 9: Tungsten.js: Building a Modular Framework

Choices are yourInterfaces

Page 10: Tungsten.js: Building a Modular Framework
Page 11: Tungsten.js: Building a Modular Framework

Application Logic

DOM Manipulation

Templates

Page 12: Tungsten.js: Building a Modular Framework

Backbone

virtual­dom

Mustache

Page 13: Tungsten.js: Building a Modular Framework

Backbone

virtual­dom

Mustache

Familiar API for developersUses 'change' events to handle re­rendersDelegates events using Tungsten'sEvent interface

var AppView = View.extend( childViews: 'js‐new‐todo': NewItemView, 'js‐todo‐item': TodoItemView , events: 'click .js‐toggle‐all': 'handleClickToggleAll' 'click .js‐clear‐completed': 'handleClickClearCompleted' );

Page 14: Tungsten.js: Building a Modular Framework

Backbone

virtual­dom

Mustache

Handles taking the output from template andupdating the pageCreates patch operations from VirtualDOMtree diffing and applies them to the DOM

[ "0": "type": "PROPS", "vNode": "tagName": "LI", "properties": "className": "js‐todo‐item " , "count": 13, "children": "[5 children]" , "patch": "className": "js‐todo‐item completed "

Page 15: Tungsten.js: Building a Modular Framework

Backbone

virtual­dom

Mustache

Declarative descriptors of markupUses data to create the current state ofthe appRendered on both Client and Server

<div id="main"> <input id="toggle‐all" class="js‐toggle‐all" <ul id="todo‐list"> #todoItems > todo_item /todoItems </ul></div>

Page 16: Tungsten.js: Building a Modular Framework

Templates?!

Page 17: Tungsten.js: Building a Modular Framework

Separatingtechnologies not

concerns?

Page 18: Tungsten.js: Building a Modular Framework

Differentenvironments havedifferent concerns.

Page 19: Tungsten.js: Building a Modular Framework
Page 20: Tungsten.js: Building a Modular Framework

Server choice shouldnot be dictated byclient­side choices

Page 21: Tungsten.js: Building a Modular Framework

Implementations

FluxFlux

ReactReact

HandlebarsHandlebars

Page 22: Tungsten.js: Building a Modular Framework

Implementations

BackboneBackbone

ReactReact

HtmlBarsHtmlBars

Page 23: Tungsten.js: Building a Modular Framework

Implementations

FluxFlux

ReactReact

UnderscoreUnderscore

Page 24: Tungsten.js: Building a Modular Framework

Implementations

FluxFlux

virtual­domvirtual­dom

HtmlBarsHtmlBars

Page 25: Tungsten.js: Building a Modular Framework

Implementations

AmpersandAmpersand

ReactReact

JadeJade

Page 26: Tungsten.js: Building a Modular Framework

Implementations

BackboneBackbone

Reactvirtual­dom

JadeJade

Page 27: Tungsten.js: Building a Modular Framework

github.com/wayfair/tungstenjs