angularjs directives - dsl for your html

42

Upload: lukas-ruebbelke

Post on 02-Nov-2014

5.098 views

Category:

Technology


0 download

DESCRIPTION

These are the slides from the talk that Brian Ford and I did at Philly ETE 2013.

TRANSCRIPT

Page 1: AngularJS Directives - DSL for your HTML

AngularJS DirectivesDSL For Your HTML!

Page 2: AngularJS Directives - DSL for your HTML

Who are we?

Page 3: AngularJS Directives - DSL for your HTML

Who am I?Lukas Ruebbelke

Senior Software Engineer at WebFilingsContributed to AngularJS

Co-Author of AngularJS in Action

Page 4: AngularJS Directives - DSL for your HTML

Who is he?Brian Ford

Core Contributor to AngularJSCore Contributor to Yeoman

Co-Author of AngularJS in ActionWrote Batarang

Loveliest Hair - Univeristy of Michigan 2011

Page 5: AngularJS Directives - DSL for your HTML

Brian Ford === JoJoInspiration behind Horton Hears a Who Character

True Story Bro!

Page 6: AngularJS Directives - DSL for your HTML

Okay so what is AngularJS?¾ AngularJS lets you extend HTML vocabulary for your

application. ¿

Page 7: AngularJS Directives - DSL for your HTML

JavaScript Framework"Model View Whatever"

For the sake of conversation we refer W as ViewModelViewModel increases surface area for testable code

Page 8: AngularJS Directives - DSL for your HTML

Two Way DatabindingDOM is NOT the model - Keep state out of your DOMDOM should only visually reflect the state of your app

Creates a nice separation between declarative markup and imperativefunctions

More productive way to write a web app

Page 9: AngularJS Directives - DSL for your HTML

Plain JavaScriptYou are not locking your JavaScript into special container classes

No API to learn

Page 10: AngularJS Directives - DSL for your HTML

TemplatingDon't try to solve HTML by abstracting it away

Embrace it and extend itNo redraw or refresh

Page 11: AngularJS Directives - DSL for your HTML

Dependency InjectionHave what you need delivered to you

Great for mocksEncourages testable code

Page 12: AngularJS Directives - DSL for your HTML

TestableWritten from the ground up to be entirely testable

Any assertion library will doFull E2E with Karma

Page 13: AngularJS Directives - DSL for your HTML

EmbeddablePlays nice with others

Not an all or nothing proposition

Page 14: AngularJS Directives - DSL for your HTML

What is a DSL?A Domain Specific Language (DSL) is a programming language designed

specifically to express solutions to problems in a specific domain.

Page 15: AngularJS Directives - DSL for your HTML

But Why?

Martin Fowler

¾ People find DSLs valuable because a well-designed DSLcan be much easier to program with than a traditional

library. This improves programmer productivity, which isalways valuable. In particular it may also improvecommunication with domain experts, which is an

important tool for tackling one of the hardest problems insoftware development. ¿

Page 16: AngularJS Directives - DSL for your HTML

Fixed Languages Are Broken

Stuart Halloway

¾ [Without the ability to reprogram the language]programmers resort to repetitive, error-prone

workarounds. Literally millions of lines of code have beenwritten to work around missing features in programming

languages. ¿

Page 17: AngularJS Directives - DSL for your HTML

HTML is a fixed language... OR ISIT!?!?

Page 18: AngularJS Directives - DSL for your HTML

Anatomy of a Directive

Page 19: AngularJS Directives - DSL for your HTML
Page 20: AngularJS Directives - DSL for your HTML

myModule.directive('sampleDirective', function(){ var linker = function(scope, element, attrs) { // FASHION GOES HERE };

var controller = function(scope, element, attrs) { // FUNCTIONALITY GOES HERE };

// DIRECTIVE DEFINITION OBJECT (DDO) return { restrict:'A', link: linker controller: controller }})

Page 21: AngularJS Directives - DSL for your HTML
Page 22: AngularJS Directives - DSL for your HTML

myModule.directive('sampleDirective', function(){ var linker = function(scope, element, attrs) { // FASHION GOES HERE };

var controller = function(scope, element, attrs) { // FUNCTIONALITY GOES HERE };

// DIRECTIVE DEFINITION OBJECT (DDO) return { restrict:'A', link: linker controller: controller }})

Page 23: AngularJS Directives - DSL for your HTML
Page 24: AngularJS Directives - DSL for your HTML

myModule.directive('sampleDirective', function(){ var linker = function(scope, element, attrs) { // FASHION GOES HERE };

var controller = function(scope, element, attrs) { // FUNCTIONALITY GOES HERE };

// DIRECTIVE DEFINITION OBJECT (DDO) return { restrict:'A', link: linker controller: controller }})

Page 25: AngularJS Directives - DSL for your HTML
Page 26: AngularJS Directives - DSL for your HTML

Restrict

Page 27: AngularJS Directives - DSL for your HTML

E is for ELEMENT

Page 28: AngularJS Directives - DSL for your HTML

A is for ATTRIBUTE

Page 29: AngularJS Directives - DSL for your HTML

C is for COOKIE!

Page 30: AngularJS Directives - DSL for your HTML

C is for CLASS

Page 31: AngularJS Directives - DSL for your HTML

Isolated Scope

Page 32: AngularJS Directives - DSL for your HTML

Why?Explicit Interface

ReusableMitigates Side Effects

Page 33: AngularJS Directives - DSL for your HTML

myModule.directive('myComponent', function () { return { restrict:'E', scope:{ attributeFoo:'@', bindingFoo:'=', expressionFoo:'&' } };})

Page 34: AngularJS Directives - DSL for your HTML

Attribute

Page 35: AngularJS Directives - DSL for your HTML

Binding

Page 36: AngularJS Directives - DSL for your HTML

Expression

Page 37: AngularJS Directives - DSL for your HTML

Stop! Demo Time!

Page 38: AngularJS Directives - DSL for your HTML

Questions?

Page 39: AngularJS Directives - DSL for your HTML

Holla At Yer Boy!!BLOG: http://onehungrymind.com/

GITHUB: https://github.com/simpultonTWITTER: @simpulton

Page 40: AngularJS Directives - DSL for your HTML

Resourceshttp://angularjs.org/

http://onehungrymind.com/http://briantford.com/http://egghead.io/

Page 41: AngularJS Directives - DSL for your HTML

AngularJS in Action

Chapters 3 and 4 In ReviewAngello Posted

Coupon Code 12mp25 for 42% Off

Page 42: AngularJS Directives - DSL for your HTML

Thanks!