Top Banner
Bringing Data To Life in the Browser Jenny Han Donnelly YUI Library
35

Jenny Donnelly

Jan 20, 2015

Download

Education

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Jenny Donnelly

Bringing Data To Lifein the Browser

Jenny Han Donnelly

YUI Library

Page 2: Jenny Donnelly
Page 3: Jenny Donnelly
Page 4: Jenny Donnelly

Abstract data retrieval to support the mix-and-match of transports and formats

Page 5: Jenny Donnelly

101010101010101010101010101010

1. transport2. parse3. normalize

Page 6: Jenny Donnelly

The DataSource is YUI's data retreivalabstraction layer.

Page 7: Jenny Donnelly

Data Transports

Local

Application data

External sources

Page 8: Jenny Donnelly

Data Formats

Arrays

Hashes

Markup

XML

JSON

JSONP

Delimited text

Page 9: Jenny Donnelly
Page 10: Jenny Donnelly

Using YAHOO.util.DataSource

1. The transport

2. The response format

3. The schema

Page 11: Jenny Donnelly

DataSource provides aconsistent, predictable API to the data.

Page 12: Jenny Donnelly

DataSource subclasses

LocalDataSource

XHRDataSource

ScriptNodeDataSource

FunctionDataSource

Page 13: Jenny Donnelly

DataSource responseType

TYPE_JSARRAY TYPE_JSON TYPE_XMLTYPE_TEXT TYPE_HTMLTABLE

Page 14: Jenny Donnelly

{"query": {"count":"44", "created":"2009-09-10T01:08:04Z", "lang": "en-US", "updated":"2009-09-10T01:08:04Z", "results": { "Result": [ {"id":"28787054", "Title":"Jinmi Restaurant", "Address":"1627 Hollenbeck Ave", "City":"Sunnyvale", State:"CA", "Latitude":"xyz", "Longitude":"abc", "Rating":{"AverageRating":"4", "TotalRatings":"5"} }, {"id":"21323987", "Title":"Totoro", "Address":"841 Villa St ", "City":"Sunnyvale", State:"CA", "Latitude":"xyz", "Longitude":"abc", "Rating":{"AverageRating":"5", "TotalRatings":"9"}

}, ... ] } }}

{"results": [ {"Title":"Jinmi Restaurant", "City":"Sunnyvale", "Phone":"(408) 481-0709", "Rating":{"AverageRating":"4"} }, {"Title":"Totoro", "City":"Sunnyvale", "Phone":"(408) 481-0709", "Rating":{"AverageRating":"5"} }, ... ]}

Page 15: Jenny Donnelly

var ds = new YAHOO.util.LocalDataSource(portfolio);

ds.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;

ds.responseSchema = [ fields: ["company", "cost", "shares", "symbol", "value"]

];

Page 16: Jenny Donnelly

DataSources easily interface withAutoCompletes, Charts, andDataTables.

Page 17: Jenny Donnelly

var chart = new YAHOO.widget.Chart ("chart", ds, {...});

var ac = new YAHOO.widget.AutoComplete("input", "suggestions", ds, {...});

var dt = new YAHOO.widget.DataTable("container", cols, ds, {...});

Page 18: Jenny Donnelly

protocol

The data transaction lifecycle

widget

data

datasource

cache

responseEvent

requestEvent

doBeforeParseDatadoBeforeCallback

responseEvent

cacheRequestEventcacheResponseEvent

Page 19: Jenny Donnelly

Performance considerations

Keep it local

Or enable cachingds.maxCacheEntries = 100;

Perform cacheable data transformations with doBeforeParseData() or doBeforeCallback()

Keep request queries consistent

Page 20: Jenny Donnelly
Page 21: Jenny Donnelly

{"query": {"count":"44", "created":"2009-09-10T01:08:04Z", "lang": "en-US", "updated":"2009-09-10T01:08:04Z", "results": { "Result": [ {"id":"28787054", "Title":"Jinmi Restaurant", "Address":"1627 Hollenbeck Ave", ... "Rating":{"AverageRating":"4", "TotalRatings":"5"} }, {"id":"21323987", "Title":"Totoro", "Address":"841 Villa St ", ... "Rating":{"AverageRating":"5", "TotalRatings":"9"}

}, ... ] } }}

Page 22: Jenny Donnelly

var myDS = new YAHOO.util.ScriptNodeDataSource("http://query.yahooapis.com/v1/public/yql?format=json");

myDS.responseType = YAHOO.util.DataSource.TYPE_JSON;

myDS.responseSchema = { resultsList:"query.results.Result", fields: ["Title", "City", "Phone", "Rating.AverageRating"]

};

Page 23: Jenny Donnelly

var columns = [ {key:"Title"}, {key:"City"}, {key:"Phone"}, {key:"Rating.AverageRating"}]; var myDT = new YAHOO.widget.DataTable("datatable", columns, myDS, {initialRequest: "&q=select * from local.search(0) where query='korean restaurant' and location='sunnyvale, ca'"});

Page 24: Jenny Donnelly
Page 25: Jenny Donnelly

<?xml version="1.0" encoding="UTF-8"?><query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"

yahoo:count="44" yahoo:created="2009-09-10T06:00:20Z" yahoo:lang="en-US" yahoo:updated="2009-09-10T06:00:20Z">

<results> <Result xmlns="urn:yahoo:lcl" id="28787054"> <Title>Jinmi Restaurant</Title> <Address>1627 Hollenbeck Ave</Address> ... <Rating> <AverageRating>4</AverageRating> <TotalRatings>5</TotalRatings> </Rating> </Result> <Result xmlns="urn:yahoo:lcl" id="21323987"> <Title>Totoro</Title> <Address>841 Villa St</Address> ... <Rating> <AverageRating>5</AverageRating> <TotalRatings>10</TotalRatings> </Rating> </Result> ... </results></query>

Page 26: Jenny Donnelly

var myDS = new YAHOO.util.ScriptNodeDataSource("http://query.yahooapis.com/v1/public/yql?format=xml");

myDS.responseType = YAHOO.util.DataSource.TYPE_XML;

myDS.responseSchema = { resultNode:"Result", fields: ["Title", "City", "Phone", "Rating.AverageRating"]

};

Page 27: Jenny Donnelly

{"results": [ {"Title":"Jinmi Restaurant", "City":"Sunnyvale", "Phone":"(408) 481-0709", "Rating":{"AverageRating":"4"} }, {"Title":"Totoro", "City":"Sunnyvale", "Phone":"(408) 481-0709", "Rating":{"AverageRating":"5"} }, ... ]}

Page 28: Jenny Donnelly

Jinmi Restaurant|1627 Hollenbeck Ave|Sunnyvale|... Totoro|841 Villa St|Mountain View|......

Page 29: Jenny Donnelly

var myDS = new YAHOO.util.ScriptNodeDataSource("http://query.yahooapis.com/v1/public/yql?format=text");

myDS.responseType = YAHOO.util.DataSource.TYPE_TEXT;

myDS.responseSchema = { recordDelim : "\n", fieldDelim : "|", fields: ["Title", "City", "Phone"]};

Page 30: Jenny Donnelly

{"results": [ {"Title":"Jinmi Restaurant", "City":"Sunnyvale", "Phone":"(408) 481-0709"} }, {"Title":"Totoro", "City":"Sunnyvale", "Phone":"(408) 481-0709"} }, ... ]}

Page 31: Jenny Donnelly

101010101010101010101010101010

1. transport2. parse3. normalize

Page 32: Jenny Donnelly

YUI 3

http://developer.yahoo.com/yui/theater/

Page 33: Jenny Donnelly

0

5

10

15

20

25

30

35

KW

eig

ht

(min

, n

on

-gzi

p)

YUI 2 YUI 3 (rollup) YUI 3 (opt)

cache

datatype-xml

datatype-date

datatype-number

dataschema-text

dataschema-xml

dataschema-json

dataschema-array

dataschema-base

ds-textschema

ds-xmlschema

ds-jsonschema

ds-arrayschema

ds-polling

ds-cache

ds-function

ds-get

ds-io

ds-local

datasource

Page 34: Jenny Donnelly

Image Credits

http://www.flickr.com/photos/dan4th/301092024/

http://www.sxc.hu/photo/465451

http://www.sxc.hu/photo/548373

http://www.flickr.com/photos/wilhei/109403331/

http://www.flickr.com/photos/wilhei/109403357/

http://www.yuiblog.com/blog/2009/08/10/in-the-wild-for-august-10-2009/

http://yuiblog.com/blog/2009/04/23/wild-20090423

http://www.yuiblog.com/blog/2009/07/31/implementation-focus-short-reckonings/

http://www.yuiblog.com/blog/2009/05/26/in-the-wild-for-may-26-2009/

Page 35: Jenny Donnelly

Thanks!