Changes between Initial Version and Version 1 of Ticket #12924, comment 4


Ignore:
Timestamp:
Jan 6, 2012, 10:33:28 AM (10 years ago)
Author:
ykami
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12924, comment 4

    initial v1  
     1
     2== Dojo Mobile Data Handlers ==
     3
     4!ViewContoller was refactored to modularize the handlers, and the data handlers are structured as follows:
     5
     6[[Image(http://trac.dojotoolkit.org/raw-attachment/ticket/12924/data-handlers-class.png)]]
     7
     8The data handlers consist of the following components:
     9
     101. !DataHandler
     112. !FileTypeMap
     123. !DataSource
     134. !ContentTypeMap
     145. !ContentHandler
     15
     16All of the above components are loaded dynamically at run-time. You do not need to explicitly requre them in your application. If your application does not use the "url" property of _ItemBase, they will never be loaded.
     17
    118'''!DataHandler'''
    219
     
    1835
    1936!ContentHandler parses the given data, and creates a new view with the data.
     37
     38----
     39
     40'''The Overall Control-Flow'''
     41
     42[[Image(http://trac.dojotoolkit.org/raw-attachment/ticket/12924/data-handlers-flow.png)]]
     43
     44
     451. !ViewController accesses !FileTypeMap to get a content type (e.g. "html" or "json") by a file name suffix.
     462. !ViewController creates a !DataSource with the url property.
     473. !ViewController creates !DataHandler with the created !DataSource.
     484. !ViewController calls !DataHandler.processData() with the content type.
     495. !DataHandler accesses !ContentTypeMap to get a !ContentHandler class name by the given content type.
     506. !DataHandler calls !DataSource.getData().
     517. !DataSource gets external content.
     528. !DataHandler creates the !ContentHandler class.
     539. !DataHandler calls !ContentHandler.parse() to parse the content.
     5410. !ContentHandler.parse() parses the content.
     5511. !ContentHandler.parse() creates a new view.
     5612. !DataHandler calls a callback that is defined in !ViewController.
     5713. The callback makes a view transition to the new view.
     58
     59
     60'''How to replace !DataHandler'''
     61
     62
     63
     64The default !DataHandler class name is "dojox/mobile/dh/!DataHandler", which is defined as the dataHandlerClass property in !ViewController. It can be overridden by adding the dataHandlerClass property to transitionOptions. Below is an example of specifying your own !DataHandler in !ListItem.
     65
     66{{{
     67<li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.html",
     68 transitionOptions:{dataHandlerClass:"com/acme/MyDataHandler"}'>
     69    External View #1
     70</li>
     71}}}
     72
     73'''How to replace !FileTypeMap'''
     74
     75The default !FileTypeMap class name is "dojox/mobile/dh/!SuffixFileTypeMap", which is defined as the fileTypeMapClass property in !ViewController. It can be overridden by adding the fileTypeMapClass property to transitionOptions. Below is an example of specifying your own !FileTypeMap in !ListItem.
     76
     77{{{
     78<li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.html",
     79 transitionOptions:{fileTypeMapClass:"com/acme/MyFileTypeMap"}'>
     80    External View #1
     81</li>
     82}}}
     83
     84'''How to replace !DataSource'''
     85
     86The default !DataSource class name is "dojox/mobile/dh/UrlDataSource", which is defined as the dataSourceClass property in !ViewController. It can be overridden by adding the dataSourceClass property to transitionOptions. Below is an example of specifying your own !DataSource in !ListItem.
     87
     88{{{
     89<li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.html",
     90 transitionOptions:{dataSourceClass:"com/acme/MyDataSource"}'>
     91    External View #1
     92</li>
     93}}}
     94
     95'''How to replace !ContentTypeMap'''
     96
     97Usually, !ContentTypeMap does not need to be replaced. If you have your own !DataHandler, however, you can have your own !ContentTypeMap as well, since !DataHandler has dependency on !ContentTypeMap.
     98
     99'''How to override !ContentType'''
     100
     101Usually, content type is determined by looking up the matching entry in a !ContentTypeMap. If you want to skip the look-up, and explicitly specify a particular content type, you can give the contentType property to transitionOptions. Below is an example of specifying a content type in !ListItem.
     102
     103{{{
     104<li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='url:"data/view1.data",
     105 transitionOptions:{contentType:"data"}'>
     106    External View #1
     107</li>
     108}}}
     109
     110'''How to register !ContentType'''
     111
     112Content type is determined by a !FileTypeMap. For example, !SuffixFileTypeMap uses the file name suffix to determine content type. For !SuffixFileTypeMap, you can register "suffix to content type" entries into the map. !SuffixFileTypeMap is a singleton module. You can simply get its module return value and use the add() method to register your entries.
     113
     114{{{
     115require([
     116    "dojox/mobile/dh/SuffixFileTypeMap",
     117    "dojox/mobile/parser",
     118    "dojox/mobile",
     119    "dojox/mobile/compat"
     120], function(SuffixFileTypeMap){
     121    SuffixFileTypeMap.add("acme", "data"); // regard *.acme as "data" type
     122});
     123}}}
     124
     125If you use the old dojo.require() API, you can register entries as follows.
     126
     127{{{
     128dojo.require("dojox/mobile/parser");
     129dojo.require("dojox/mobile");
     130dojo.require("dojox/mobile/compat");
     131dojo.require("dojox/mobile/dh/SuffixFileTypeMap");
     132
     133dojox.mobile.dh.SuffixFileTypeMap.add("acme", "data");
     134}}}
     135
     136If a given suffix does not match any of the entries in the map, !ViewController uses "html" as the default content type.
     137
     138'''How to register !ContentHandler'''
     139
     140Which !ContentHandler to use is managed by !ContentTypeMap. In your application, you can register "content type to content handler class" entries into the map. !ContentTypeMap is a singleton module. You can simply get its module return value and use the add() method to register your entries.
     141
     142{{{
     143require([
     144    "dojox/mobile/dh/ContentTypeMap",
     145    "dojox/mobile/parser",
     146    "dojox/mobile",
     147    "dojox/mobile/compat"
     148], function(ContentTypeMap){
     149    ContentTypeMap.add("html", "dojox/mobile/dh/MyHtmlContentHandler");
     150});
     151}}}
     152
     153If you use the old dojo.require() API, you can register entries as follows.
     154
     155{{{
     156dojo.require("dojox/mobile/parser");
     157dojo.require("dojox/mobile");
     158dojo.require("dojox/mobile/compat");
     159dojo.require("dojox/mobile/dh/ContentTypeMap");
     160
     161dojox.mobile.dh.ContentTypeMap.add("html", "dojox/mobile/dh/MyHtmlContentHandler");
     162}}}