TipTheWeb.org - Heavy Duty YUI 3 & YQL

43
Heavy Duty YUI 3 & YQL Eric Ferraiuolo @ericf http://tiptheweb.org

description

A look at TipTheWeb (with live demo action), digging into how we built our web application's rich UI on YUI 3 — the project-scale codebase, strategies developed, and YUI Gallery modules that came out of it. Followed up with a dive into TipTheWeb's advanced usage of YQL to process our most important data, URLs; making YQL the place where web service requests are made and data is gathered. http://tiptheweb.org/

Transcript of TipTheWeb.org - Heavy Duty YUI 3 & YQL

Page 1: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Heavy Duty YUI 3 & YQL

Eric Ferraiuolo@ericf

http://tiptheweb.org

Page 2: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Community-SupportedWeb Publishing

Page 5: TipTheWeb.org - Heavy Duty YUI 3 & YQL

YUI 3 at TipTheWeb

Page 6: TipTheWeb.org - Heavy Duty YUI 3 & YQL

A Lot of YUI 3

56YUI 3 Modules

Page 8: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Top-Level Components

• Manage interactions within page

• Extends Y.Base uses ATTRS, Custom Events

•Y.BaseComponentMgr

•Y.Resource

Page 9: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Component Management

• Y.Base extension

• Adds COMPONENTS to Y.Base, think ATTRS

• Dependencies & Instances on-demand

• this.useComponent('foo', callback);

Page 10: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Y.BaseComponentMgr Example

// Defined staticallyCOMPONENTS : {! myOverlay : {! ! requires : ['overlay', 'gallery-overlay-extras'],! ! initializer : '_initMyOverlay'! }}

// …Somewhere elseY.one('#show').on('click', Y.bind(function(e){ this.useComponent('myOverlay', function(overlay){ overlay.show(); });}, this));

Page 11: TipTheWeb.org - Heavy Duty YUI 3 & YQL

RESTful Client

• RESTful HTTP semantics

• JSON in, JSON out

• Resource-scoped Events

Page 12: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Y.Resource Example

var r = new Y.Resource({ uri: 'path/to/{id}' });

r.GET({! // makes request to: path/to/123! params!: { id: 123 },! on!: {! ! success : function(e){! !! ! ! // e.entity is an Object parsed from JSON! ! !! ! }! }});

Page 13: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Lots of Overlays

Page 14: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Overlay Extras

• Y.Plugin.OverlayModal

• Y.Plugin.OverlayKeepaligned

• Y.Plugin.OverlayAutohide

Page 15: TipTheWeb.org - Heavy Duty YUI 3 & YQL

YQL at TipTheWeb

Page 17: TipTheWeb.org - Heavy Duty YUI 3 & YQL

URL Processing — Targeting Tips

Page 18: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Example: http://bit.ly/Bb6g0

1. Determine Integration, If Any

2. Gather URL Data

3. Cache & Return Results

SELECT * FROM targetresolver WHERE url="http://bit.ly/Bb6g0"

Page 19: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

Page 20: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

No, Request Page

Page 21: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

No, Request Page

SELECT url FROM docresolverWHERE url="http://bit.ly/Bb6g0"

Page 22: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

Redirected?

No, Request Page

Page 23: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

Redirected?

No, Request Page

Yes, http://www.youtube.com/watch?v=8410qUT4QtA

Page 24: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

Redirected?

No, Request Page

Yes, http://www.youtube.com/watch?v=8410qUT4QtA

youtube.com Matches?

Page 25: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

Redirected?

No, Request Page

Yes, http://www.youtube.com/watch?v=8410qUT4QtA

youtube.com Matches?

Yes, Load Integration

Page 26: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Determine Integration, If Anyhttp://bit.ly/Bb6g0

bit.ly Matches?

Redirected?

No, Request Page

Yes, http://www.youtube.com/watch?v=8410qUT4QtA

youtube.com Matches?

Yes, Load Integration

y.include("store://youtube.js");

Page 27: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Gather URL Datahttp://www.youtube.com/watch?v=8410qUT4QtA

Matches Video URL?

Page 28: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Gather URL Datahttp://www.youtube.com/watch?v=8410qUT4QtA

Matches Video URL?

Yes, 8410qUT4QtA

Page 29: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Gather URL Datahttp://www.youtube.com/watch?v=8410qUT4QtA

Matches Video URL?

Is YouTube Video?

Yes, 8410qUT4QtA

Page 30: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Gather URL Datahttp://www.youtube.com/watch?v=8410qUT4QtA

Matches Video URL?

Is YouTube Video?

Yes, 8410qUT4QtA

SELECT title, author FROM youtube.videoswhere id="8410qUT4QtA"

Page 31: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Gather URL Datahttp://www.youtube.com/watch?v=8410qUT4QtA

Matches Video URL?

Is YouTube Video?

Yes, 8410qUT4QtA

Yes, Valid YouTube Video

Page 32: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Gather URL Datahttp://www.youtube.com/watch?v=8410qUT4QtA

Matches Video URL?

Is YouTube Video?

Yes, 8410qUT4QtA

Yes, Valid YouTube Video

Gather Video MetaData

Page 33: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Gather URL Datahttp://www.youtube.com/watch?v=8410qUT4QtA

Matches Video URL?

Is YouTube Video?

Yes, 8410qUT4QtA

Yes, Valid YouTube Video

Gather Video MetaData

{"author": "…","title": "…"

}

Page 34: TipTheWeb.org - Heavy Duty YUI 3 & YQL

• Cache Result for 1 hour

• Return Target Data:

Cache & Return Results

{! "link"! : "http://www.youtube.com/watch?v=8410qUT4QtA",! "title"!: "Chicken Techno by Oli Chang",! "target": "youtube:unicornhunters"}

Page 35: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Requests Made By YQL

1. Requested: http://bit.ly/Bb6g0

2. Redirected: http://www.youtube.com/watch?v=8410qUT4QtA

3. Included: store://youtube.js

4. Requested: Google GData Video Feed

Page 36: TipTheWeb.org - Heavy Duty YUI 3 & YQL

YQL via the Browser

• Thick-clients can do real work

• Off-load YQL requests

• Rate limits become a non-issue

• Server’s resources freed-up

Page 37: TipTheWeb.org - Heavy Duty YUI 3 & YQL

YQL via YUI 3

• Spread load and rate limits to browsers

• Guinea pig for Dav Glass’ YQL module for YUI

• Y.YQL(query, callback);

Y.YQL('SELECT * FROM targetresolver WHERE url="…"', ! function(r) {!! var results = r.query.results;!});

Page 39: TipTheWeb.org - Heavy Duty YUI 3 & YQL

• Cached results are not rate limited!

• ?_maxage=3600

• response.maxAge=3600;

Caching

Page 40: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Timeout

• Preventing table lock!

• request.timeout(25000);

• y.rest(url).timeout(25000);

• y.query(query, params, 25000);

Page 41: TipTheWeb.org - Heavy Duty YUI 3 & YQL

timer.getRemaining()

timer = (function(){! timeout = timeout > 29000 ? 29000 : timeout;! var start = new Date().getTime();!! return {! ! getRemaining : function () {! ! ! var now = new Date().getTime(),! ! ! ! elapsed = now - start,! ! ! ! remaining = timeout - elapsed;! ! ! !! ! ! return ( remaining > 0 ? remaining : 0 );! ! }! };}());

Page 42: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Summary

• YUI 3 & YQL— enabling small teams

• YUI 3 top-level components

• YQL— cache, timeout, access via browser

Page 43: TipTheWeb.org - Heavy Duty YUI 3 & YQL

Invite Code: yuiconf

Eric Ferraiuolo@ericf

http://tiptheweb.org