Intro to Front End Development with Angular + Firebase

27
Intro to Front End Development Building Web Applications for the Browser http://bit.ly/ben-fs-219

description

Intro to front end development and tooling with Angular + Firebase. Originally presented at FullStack Academy in NYC on 2/19/14.

Transcript of Intro to Front End Development with Angular + Firebase

Page 1: Intro to Front End Development with Angular + Firebase

IntrotoFrontEndDevelopment

BuildingWebApplicationsfortheBrowser

http://bit.ly/ben-fs-219

Page 2: Intro to Front End Development with Angular + Firebase

AboutMe

@bendrucker

github/bendrucker

bendrucker.me

[email protected]

Page 3: Intro to Front End Development with Angular + Firebase

Columbia-ClassofTBD

Page 4: Intro to Front End Development with Angular + Firebase

Valet.io

Fundraisingtechnologythatdoesn'tsuck

Page 5: Intro to Front End Development with Angular + Firebase

RealtimeDBaaS

NYCEvangelist

ORMforNode.js

Co-Lead

Page 6: Intro to Front End Development with Angular + Firebase

TheJavaScriptEcosytstem

Reuseyourservercodeinthebrowser

nodeJS===webScale

Solveworldhunger!

Page 7: Intro to Front End Development with Angular + Firebase

SoWhatHappened?

Page 8: Intro to Front End Development with Angular + Firebase

Servervs.Browser

Server BrowserUntrustedenvironment

Optimizefor:filesize

Optimizefor:painttime

Services:

DOM

Cookies

window

RemoteAPIs

Consistentenvironment

Optimizefor:Concurrency

Optimizefor:Responsetime

Services:

Databases

Caches

HTTPwebservices

Page 9: Intro to Front End Development with Angular + Firebase

jQueryisthePHPoftheWeb

varuserTemplate=function(user){return'<ul><liclass="user-first-name">'+user.name.first+'</li><liclass="user-last-name">'+user.name.last+'</li>';

$.getJSON('/api/user/1',function(data){vartemplate=userTemplate(data);$('ul.users').append(template);});

KeepingtheDOMinsyncwithourmodelsishard.jQuerydoesn'thelp.

Page 10: Intro to Front End Development with Angular + Firebase

WhatCanaFrontEndFrameworkDo?

Templating

Eventmanagement

Routing

Dependencymanagement

Twowaydatabinding

Page 11: Intro to Front End Development with Angular + Firebase

FrameworkOverload!

Page 12: Intro to Front End Development with Angular + Firebase

WhyDoWeNeed2WayBinding?

Page 13: Intro to Front End Development with Angular + Firebase

Forms

BAD!

<form><inputid="first-name"/><inputid="last-name"/><inputid="username"/></form>varuser={firstName:$('#first-name').val(),lastName:$('#last-name').val(),username:$('#username').val()};

Page 14: Intro to Front End Development with Angular + Firebase

Forms

GOOD!

<form><inputng-model="user.firstName"/><inputng-model="user.lastName"/><inputng-model="user.username"/></form>varuser=$scope.user;

Page 15: Intro to Front End Development with Angular + Firebase

Getters/Settersvs.DirtyChecking

Page 16: Intro to Front End Development with Angular + Firebase

DirtyCheckingExplained

POJOModels–$scope

Watchers–$scope.$watch

Digestcycles–$scope.$digest

Integrateexternalcode–$scope.$apply

FurtherReading:BuildYourOwnAngular

Page 17: Intro to Front End Development with Angular + Firebase

AdvantagesofGetters/Setters

Nodigestcycles

No$scope.digest

No$scope.watch

No$scope.$apply

UAforfree( )

Computedproperties

UniformAccessPrinciple

Page 18: Intro to Front End Development with Angular + Firebase

NativeUAP(ES5)Object.defineProperty

Object.defineProperty(User.prototype,'fullName',{get:function(){returnthis.firstName+''+this.lastName},set:function(fullName){varnameParts=fullName.split('');this.firstName=nameParts[0];this.lastName=nameParts[1];}});

Page 19: Intro to Front End Development with Angular + Firebase

Angular/Ember

vs.

EverythingElse

Page 20: Intro to Front End Development with Angular + Firebase

vs.

Page 21: Intro to Front End Development with Angular + Firebase

Let'sWriteSomeCode!

Page 22: Intro to Front End Development with Angular + Firebase

RealTimeWeb:Challenges

Eventhandlingismuchharderthanrequest-reply

Multiplesimultaneouswritescreateconflicts/overwrites

Example:

Heartbeating

Scopedsubscriptions

Networklatency

[].push

Page 23: Intro to Front End Development with Angular + Firebase

FirebasetotheRescue!

Page 24: Intro to Front End Development with Angular + Firebase

RESTvs.EventDrivenData

NomoreGET,POST,PUT,DELETE

Endpoints,justlikeREST(references)

Usedataeventstokeepmodelsinsync:

value

child_added

child_changed

child_removed

Page 25: Intro to Front End Development with Angular + Firebase

RESTStyle

EventStyle

$.getJSON('/users',function(users){$.each(users,appendUser;});

usersRef.on('child_added',appendUser);

Page 26: Intro to Front End Development with Angular + Firebase

:Angular+FirebaseAngularFire

$firebase

Auto-registerslistenerstoupdatethemodelwithremotechanges

Addsmethodsforsavinglocalchangestoremote

Optional:setup$watchtoautosynclocalchanges

Page 27: Intro to Front End Development with Angular + Firebase

MoreCode!