source: Dev/trunk/src/client/dojox/mvc/_base.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.1 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/lang",
4        "./getStateful",
5        "./StatefulModel",
6        "./Bind",
7        "./_DataBindingMixin",
8        "./_patches"
9], function(kernel, lang, getStateful, StatefulModel){
10        // module:
11        //              dojox/mvc/_base
12        // summary:
13        //              Pulls in essential MVC dependencies such as basic support for
14        //              data binds, a data model and data binding mixin for dijits.
15        kernel.experimental("dojox.mvc");
16
17        var mvc = lang.getObject("dojox.mvc", true);
18        /*=====
19                mvc = dojox.mvc;
20        =====*/
21
22        // Factory method for dojox.mvc.StatefulModel instances
23        mvc.newStatefulModel = function(/*Object*/args){
24                // summary:
25                //              Factory method that instantiates a new data model that view
26                //              components may bind to.
27                // args:
28                //              The mixin properties.
29                // description:
30                //              Factory method that returns a client-side data model, which is a
31                //              tree of dojo/Stateful objects matching the initial data structure
32                //              passed as input:
33                //
34                //              - The mixin property "data" is used to provide a plain JavaScript
35                //                object directly representing the data structure.
36                //              - The mixin property "store", along with an optional mixin property
37                //                "query", is used to provide a data store to query to obtain the
38                //                initial data.
39                //
40                //              This function returns an immediate dojox.mvc.StatefulModel instance or
41                //              a Promise for such an instance as follows:
42                //
43                //              - if args.data: returns immediately
44                //              - if args.store: if store returns immediately, this function returns immediately;
45                //                      if store returns a Promise, this function returns a model Promise
46
47                if(args.data){
48                        return getStateful(args.data, StatefulModel.getStatefulOptions);
49                }else if(args.store && lang.isFunction(args.store.query)){
50                        var model;
51                        var result = args.store.query(args.query);
52                        if(result.then){
53                                return (result.then(function(data){
54                                        model = getStateful(data, StatefulModel.getStatefulOptions);
55                                        model.store = args.store;
56                                        return model;
57                                }));
58                        }else{
59                                model = getStateful(result, StatefulModel.getStatefulOptions);
60                                model.store = args.store;
61                                return model;
62                        }
63                }
64        };
65
66        return mvc;
67});
Note: See TracBrowser for help on using the repository browser.