Changeset 703

Show
Ignore:
Timestamp:
04/23/06 22:13:23 (2 years ago)
Author:
bob@redivi.com
Message:

checkin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • presentations/2006/ajax_experience/slides.txt

    r702 r703  
    268268    Convert ``iterable`` to a new Array 
    269269 
    270 sorted(iterable[, cmp]): 
    271     Return a sorted Array from ``iterable``, optionally using ``cmp`` for 
    272     the comparator 
     270sorted(iterable, cmp=compare): 
     271    Return a sorted Array from ``iterable`` using ``cmp`` as the comparator 
    273272 
    274273sum(iterable, start=0): 
    275274    Return the sum of each item in ``iterable`` plus the ``start``. 
    276     If ``iterable`` is empty, ``start`` will be returned. 
    277275 
    278276 
     
    289287        } 
    290288    } catch (e) { 
    291         if (e != StopIteration) { 
    292             throw e; 
    293         } 
     289        if (e != StopIteration) throw e; 
    294290    } 
    295291 
     
    604600    Set the node attributes based on the object attrs 
    605601     
     602 
     603MochiKit.Color 
     604============== 
     605 
     606* Full CSS3 color model with alpha 
     607* NSColor-like API (from Cocoa) 
     608* Works in RGB, HSV, HSL 
     609* Normalized, all components from [0.0, 1.0] 
     610 
     611 
     612Creating colors from components 
     613=============================== 
     614 
     615* Color.fromRGB(r, g, b, alpha=1.0) 
     616* Color.fromHSL(h, s, l, alpha=1.0) 
     617* Color.fromHSV(h, s, v, alpha=1.0) 
     618 
     619Will also take objects, e.g. {r: 1, g: 0, b: 0, a: 1} 
     620 
     621 
     622Creating colors from strings 
     623============================ 
     624 
     625Color.fromString(str): 
     626    Generally "does what you mean" with any valid CSS color description. 
     627    "rgb(...)", "hsl(...)", "#RRGGBB", "blue" 
     628 
     629Implementations in fromRGBString, fromHSLString, fromHexString, fromName. 
     630 
     631 
     632Creating colors from DOM elements 
     633================================= 
     634 
     635Color.fromBackground(node) 
     636Color.fromComputedStyle(node, style, css) 
     637Color.fromText(node) 
     638 
     639 
     640Built-in NSColor colors 
     641======================= 
     642 
     643NSColor-based constructors for basic colors 
     644 
     645- Color.whiteColor() 
     646- Color.blueColor() 
     647- Color.transparentColor() 
     648- ... 
     649 
     650 
     651Mixing colors 
     652============= 
     653 
     654- color.blendedColor(otherColor, fraction) 
     655- color.colorWithHue(hue) 
     656- color.colorWithLevel(level) 
     657- color.colorWithSaturation(saturation) 
     658- color.colorWithAlpha(alpha) 
     659 
     660 
     661Getting color values 
     662==================== 
     663 
     664Objects: 
     665 
     666- color.asRGB() 
     667- color.asHSL() 
     668- color.asHSV() 
     669 
     670Strings: 
     671 
     672- color.toHexString() 
     673- color.toRGBString() 
     674- color.toHSLString() 
     675 
     676 
     677MochiKit.Async 
     678============== 
     679 
     680* Yes, there is AJAX 
     681* Generalized asynchronous model based on Twisted 
     682* Handles XMLHttpRequest and timed events (setTimeout) 
     683 
     684 
     685WTF is a Deferred? 
     686================== 
     687 
     688* A "promise" to call back exactly once with a single result (or error) 
     689  at some time (could be immediately!) 
     690* Can be chained 
     691* Model works in any asynchronous platform with nearly any language 
     692* Not "ideal" API, but without threads or anything resembling coroutines 
     693  it's the best you can do. 
     694 
     695 
     696Trivial Deferreds 
     697================= 
     698 
     699succeed(value): 
     700    A successful deferred that will callback with value 
     701 
     702fail(error): 
     703    A failed deferred that will errback with value 
     704 
     705maybeDeferred(func, arguments..): 
     706    Call a function and make sure it returns a Deferred.  Non-deferred return 
     707    values get wrapped with succeed, and errors get wrapped with fail. 
     708     
     709 
     710Timed Events 
     711============ 
     712 
     713wait(seconds, value): 
     714    Return a Deferred that calls back with value after seconds have passed 
     715 
     716callLater(seconds, func, arguments...): 
     717    Return a Deferred that will call func(arguments) after seconds have passed 
     718 
     719 
     720Network Events 
     721============== 
     722 
     723doSimpleXMLHttpRequest(url[, queryArguments]): 
     724    Set up a GET XMLHttpRequest to url and return a Deferred.  The Deferred 
     725    will callback with the XMLHttpRequest instance. 
     726 
     727loadJSONDoc(url[, queryArguments]): 
     728    Set up a simple XMLHttpRequest, process its responseText as JSON, and 
     729    callback with the JSON object. 
     730 
     731 
     732Deferred Usage 
     733============== 
     734 
     735Fetch a JSON document:: 
     736 
     737    function gotDocument(json) { 
     738        // ... 
     739    } 
     740    var d = loadJSONDoc("example.json"); 
     741    d.addCallback(gotDocument); 
     742    d.addErrback(logError); 
     743 
     744Result Chaining 
     745=============== 
     746 
     747The implementation of loadJSONDoc looks like this:: 
     748 
     749    var d = doSimpleXMLHttpRequest(url); 
     750    d.addCallback(evalJSONDoc); 
     751    return d; 
     752 
     753Further callbacks get the result of evalJSONDoc, not the original 
     754doSimpleXMLHttpRequest result. 
     755 
     756 
     757Deferred Chaining 
     758================= 
     759 
     760Returning a Deferred from a callback will "pause" the callback chain:: 
     761     
     762    function gotDocument(json) { 
     763        // ... 
     764    } 
     765    function delay(res) { 
     766        return wait(2.0, res); 
     767    } 
     768    var d = loadJSONDoc("example.json"); 
     769    d.addCallback(delay); 
     770    d.addCallback(gotDocument); 
     771    d.addErrback(logError); 
     772