Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Incremental style checkin.

  • Loading branch information...
commit d992d3133854e36745c05574f87e5fcbc9da25d1 1 parent f413f19
@whiteinge authored
View
0  ...10-10-07_ajax-fragments/facebook-ajaxify-form.png → ...0-07_ajax-fragments/img/facebook-ajaxify-form.png
File renamed without changes
View
92 utosc_2010-10-07_ajax-fragments/presentation.rst
@@ -274,6 +274,38 @@ Signal the Googlebot to try::
.. ............................................................................
+jQuery Code Organization
+========================
+
+* Use classes to organize your code
+* Write methods that do exactly one thing
+* Use ``$.proxy()`` to define ``this``
+
+.. ............................................................................
+
+Encapsulating Behavior with pub/sub
+===================================
+
+.. class:: handout
+
+ “[I]magine a standard three-pane email client. … When you click on a
+ message you just received, several things happen:
+
+ The mailbox unread count gets decremented
+ The message’s unread indicator goes away
+ The message row text goes from bold to plain
+ The message content appears in the viewer pane”
+
+ […]
+
+ “In general, it's a good idea to have a "view" layer which simply deals
+ with displaying the data and sending events about user actions on that data
+ (ie. clicks, etc.) to a "controller" layer, which then decides what to do.”
+
+…
+
+.. ............................................................................
+
Performance
===========
@@ -463,6 +495,8 @@ Performance
.. _`Even Faster Web Sites`: http://oreilly.com/catalog/9780596522315
+.. ............................................................................
+
Performance
===========
@@ -475,7 +509,8 @@ Performance
.. class:: incremental
* Put JavaScript at the bottom of the page. (Sometimes!)
- * Load only necessary JS up-front and lazy-load the rest. This is a challenege.
+ * Load only necessary JS up-front and lazy-load the rest. This is a
+ challenege.
* Use “stub” functions to avoid undefined errors for not-yet-downloaded
dependencies.
@@ -485,38 +520,51 @@ Performance
.. ............................................................................
-jQuery Code Organization
-========================
-
-* Use classes to organize your code
-* Write methods that do exactly one thing
-* Use ``$.proxy()`` to define ``this``
+JsonResponse
+============
-.. ............................................................................
+.. class:: handout
-Encapsulating Behavior with pub/sub
-===================================
+ NOTE: Basic JSON encoder doesn't handle some Django datatypes. DateTimes,
+ lazy translation strings.
-.. class:: handout
+ http://docs.djangoproject.com/en/1.2/topics/serialization/#id2::
- “[I]magine a standard three-pane email client. … When you click on a
- message you just received, several things happen:
+ from django.utils.functional import Promise
+ from django.utils.encoding import force_unicode
- The mailbox unread count gets decremented
- The message’s unread indicator goes away
- The message row text goes from bold to plain
- The message content appears in the viewer pane”
+ class LazyEncoder(simplejson.JSONEncoder):
+ def default(self, obj):
+ if isinstance(obj, Promise):
+ return force_unicode(obj)
+ return super(LazyEncoder, self).default(obj)
- […]
+::
- “In general, it's a good idea to have a "view" layer which simply deals
- with displaying the data and sending events about user actions on that data
- (ie. clicks, etc.) to a "controller" layer, which then decides what to do.”
+ import json
+ from django import http
-…
+ class JsonResponse(http.HttpResponse):
+ def __init__(self, data, **kwargs):
+ http.HttpResponse.__init__(self,
+ content=json.JSONEncoder().encode(data),
+ mimetype='application/json',
+ **kwargs)
.. ............................................................................
+Piston
+======
+
+::
+
+ |- settings.py
+ |- urls.py
+ +- api/
+ |- __init__.py
+ |- urls.py
+ `- handlers.py
+
.. ............................................................................
Proof of Concept
Please sign in to comment.
Something went wrong with that request. Please try again.