staying dry with yui

103

Upload: jonathan-tsai

Post on 28-May-2015

803 views

Category:

Technology


2 download

DESCRIPTION

Presented at YUI Conf 2013 Conference web site: http://yuilibrary.com/yuiconf/2013/schedule/#jonathan-tsai-and-william-seo This tech talk is about how a team of merely two engineers built all of Talentral, a complex, rich, feels-like-desktop webapp. Everyone knows about DRY, but how is it done in practice with YUI? This is our story about how using YUI + YUI Gallery enables us to focus on high-leverage tasks at a fast-paced startup when the temptations to write quick-and-dirty solutions surface at every corner. We'll walk through several examples of how we evaluated existing YUI modules (not just UI widgets, but also behaviors and patterns) and then decided to roll our own custom YUI modules (we've written 10, to date) in good OO-JS fashion to stay faithful to the YUI ecosystem (elegant, DRY, maintainable, community friendly) instead of succumbing to the FrankenJS approach that is so prevalent in today's JS landscape.

TRANSCRIPT

Page 1: Staying DRY with YUI
Page 2: Staying DRY with YUI

Staying DRY with YUIBy Jonathan Tsai & William Seo

Page 3: Staying DRY with YUI

William SeoJonathan Tsai

Page 4: Staying DRY with YUI
Page 5: Staying DRY with YUI
Page 6: Staying DRY with YUI
Page 7: Staying DRY with YUI

Part 4.Conclusion

Page 8: Staying DRY with YUI

Best Practices

Page 9: Staying DRY with YUI

Use, Create, Proliferate

Page 10: Staying DRY with YUI

Best Practices

Page 11: Staying DRY with YUI

Use YUI and Pure

Page 12: Staying DRY with YUI

Use YUI and Pure+

Custom YUI Modules

Page 13: Staying DRY with YUI

Part 0. Background

Page 14: Staying DRY with YUI

Talentral = Startup

Page 15: Staying DRY with YUI

Hacker + Hustler

- Micah Baldwin, Startup Mentor

Page 16: Staying DRY with YUI

Hacker + Hustler (CTO) (CEO)

Page 17: Staying DRY with YUI

Hacker

Page 18: Staying DRY with YUI

Talentral = Lean Startup

Page 19: Staying DRY with YUI

Hackers!

Page 20: Staying DRY with YUI

Lean Startup = Underdogs

Page 21: Staying DRY with YUI

Mistakes are costly

Page 22: Staying DRY with YUI

Choose wisely

Page 23: Staying DRY with YUI

Plan Your WorkWork Your Plan

Page 24: Staying DRY with YUI

Plan Your WorkChoose a Solid Tech

Stack

Page 25: Staying DRY with YUI

• Open Source• Good community support• Modern• Comfort• Compatibility• Talent

Page 26: Staying DRY with YUI

Amazon Web ServicesMySQL + Redis

Django + PythonYUI

Page 27: Staying DRY with YUI

Work Your PlanApply it correctly

Page 28: Staying DRY with YUI

Best Practices

Page 29: Staying DRY with YUI

Use, Create, Proliferate

Page 30: Staying DRY with YUI

Part 1.Using Best Practices

Page 31: Staying DRY with YUI

Amazon Web ServicesMySQL + Redis

Django + PythonYUI

Page 32: Staying DRY with YUI

YUI = Best Practice?

Page 33: Staying DRY with YUI
Page 34: Staying DRY with YUI

• Open Source• Good community support• Modern• Comfort• Compatibility• Talent

Page 35: Staying DRY with YUI

Best Practice #1Use YUI

Page 36: Staying DRY with YUI

Best Practice #2Stay DRY

Page 37: Staying DRY with YUI

DRY:DON’T REPEAT YOURSELF

http://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Page 38: Staying DRY with YUI

NOT a Best PracticeGetting WET

Page 39: Staying DRY with YUI

WET:WRITE EVERYTHING

TWICE

Page 40: Staying DRY with YUI

WET:WE ENJOY TYPING

Page 41: Staying DRY with YUI

Best Practice #3OO-JS

Page 42: Staying DRY with YUI

OOPAbstraction + Encapsulation

Page 43: Staying DRY with YUI

Part 2.Creating Best Practices

Page 44: Staying DRY with YUI

Best Practices1. Use YUI2. Stay DRY3. OO-JS

Page 45: Staying DRY with YUI

Best Practices+

Time

Page 46: Staying DRY with YUI

Case StudyBackbone.js + Hulu

Page 47: Staying DRY with YUI
Page 48: Staying DRY with YUI
Page 49: Staying DRY with YUI

UH. OH.YUI = Best Practice?

Page 50: Staying DRY with YUI

CaveatObjects don’t define

themselves

Page 51: Staying DRY with YUI

Use, Create, Proliferate

Page 52: Staying DRY with YUI

Best Practices #1-3Custom YUI Modules

Page 53: Staying DRY with YUI

Where do we begin…

Page 54: Staying DRY with YUI
Page 55: Staying DRY with YUI

Y.Nodevar nodeB = f(nodeA);

Page 56: Staying DRY with YUI

Identify a pattern

Page 57: Staying DRY with YUI

At first we tried…

Page 58: Staying DRY with YUI

Repeated code everywhere

Page 59: Staying DRY with YUI

var _Y; // global YYUI().use(..., function(Y) { _Y = Y;});

Page 60: Staying DRY with YUI

Y.namespace()

Page 61: Staying DRY with YUI

Best Practices #1-3Custom YUI Modules

Page 62: Staying DRY with YUI

Example:Background Fetcher

Page 63: Staying DRY with YUI

What we wanted:

Page 64: Staying DRY with YUI

What we wanted:HTTP.GET + Render

Content

Page 65: Staying DRY with YUI

var cfg = {on:{complete:..., failure: ...}};var request = Y.io(uri,cfg);IO_TRANSACTION_DATA[request.id] = transactionData;...

Page 66: Staying DRY with YUI

Y.BackgroundFetcher.backgroundFetch(uri, type, parent, callbacks);

Page 67: Staying DRY with YUI

Example:Unescape

Page 68: Staying DRY with YUI

What we wanted:

Page 69: Staying DRY with YUI

What we wanted:Edit HTML Content as Text

Page 70: Staying DRY with YUI

Node.getHTML()

Page 71: Staying DRY with YUI

71

Page 72: Staying DRY with YUI

72

Page 73: Staying DRY with YUI

Node.get('text')

Page 74: Staying DRY with YUI

74

Page 75: Staying DRY with YUI

75

Page 76: Staying DRY with YUI

var unescaped = Y.Unescape.htmlUnescape(node.getHTML());

Page 77: Staying DRY with YUI

Example:UI Lock

Page 78: Staying DRY with YUI

What we wanted:

Page 79: Staying DRY with YUI

What we wanted:Don’t stack API calls

Page 80: Staying DRY with YUI

function handleBtnClicked(e) { var btn = this; var lock = Y.UILock.lock(btn); if (lock) {...} lock.release();}

Page 81: Staying DRY with YUI

Y.io(uri, { on: { complete: Y.UILock.ioUnlock(lock, callback) }});

Page 82: Staying DRY with YUI

Example:Spotlight

Page 83: Staying DRY with YUI

What we wanted:

Page 84: Staying DRY with YUI

What we wanted:Node-level modal effect

Page 85: Staying DRY with YUI

85

Page 86: Staying DRY with YUI

Part 3.Proliferating Best

Practices

Page 87: Staying DRY with YUI

Coming Soonhttps://github.com/

talentral

Page 88: Staying DRY with YUI

Fav Tips & Tricks #1<script id="..." type="text/x-template">BLOB</script>

Page 89: Staying DRY with YUI

Fav Tips & Tricks #2Y.Template();Y.Lang.sub();

Page 90: Staying DRY with YUI

Fav Tips & Tricks #3<div tlnt:item-type="skill" tlnt:item-id="6547"></div>

Page 91: Staying DRY with YUI

Fav Tips & Tricks #3node.getAttribute('tlnt

:item-id’);

Page 92: Staying DRY with YUI

How did we ever survive without…

Page 93: Staying DRY with YUI
Page 94: Staying DRY with YUI

94

Page 95: Staying DRY with YUI

95

Page 96: Staying DRY with YUI

96

Page 97: Staying DRY with YUI

Part 4.Conclusion

Page 98: Staying DRY with YUI

Best Practices

Page 99: Staying DRY with YUI

Use YUI and Pure+

Custom YUI Modules

Page 100: Staying DRY with YUI

Use, Create, Proliferate

Page 101: Staying DRY with YUI

Special Thanks ToYUI Team & Contributors

#yui IRC folks

Page 102: Staying DRY with YUI

On the Interwebs@jontsai

http://talentral.com

Page 103: Staying DRY with YUI

Q&A