summaryrefslogtreecommitdiff
path: root/js/dojo-1.7.2/dojox/mvc/_base.js
blob: cbdad32e5d2f3296165762f78062ca3070b0a537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//>>built
define("dojox/mvc/_base", [
	"dojo/_base/kernel",
	"dojo/_base/lang",
	"./StatefulModel",
	"./Bind",
	"./_DataBindingMixin",
	"./_patches"
], function(kernel, lang, StatefulModel){
	// module:
	//		dojox/mvc/_base
	// summary:
	//		Pulls in essential MVC dependencies such as basic support for
	//		data binds, a data model and data binding mixin for dijits.
	kernel.experimental("dojox.mvc");

	var mvc = lang.getObject("dojox.mvc", true);
	/*=====
		mvc = dojox.mvc;
	=====*/

	// Factory method for dojox.mvc.StatefulModel instances
	mvc.newStatefulModel = function(/*Object*/args){
		// summary:
		//		Factory method that instantiates a new data model that view
		//		components may bind to.
		//	args:
		//		The mixin properties.
		// description:
		//		Factory method that returns a client-side data model, which is a
		//		tree of dojo.Stateful objects matching the initial data structure
		//		passed as input:
		//		- The mixin property "data" is used to provide a plain JavaScript
		//		  object directly representing the data structure.
		//		- The mixin property "store", along with an optional mixin property
		//		  "query", is used to provide a data store to query to obtain the
		//		  initial data.
		//		This function returns an immediate dojox.mvc.StatefulModel instance or
		//		a Promise for such an instance as follows:
		//		- if args.data: returns immediate
		//		- if args.store:
		//			- if store returns immediate: this function returns immediate
		//			- if store returns a Promise: this function returns a model
		//			  Promise
		if(args.data){
			return new StatefulModel({ data : args.data });
		}else if(args.store && lang.isFunction(args.store.query)){
			var model;
			var result = args.store.query(args.query);
			if(result.then){
				return (result.then(function(data){
					model = new StatefulModel({ data : data });
					model.store = args.store;
					return model;
				}));
			}else{
				model = new StatefulModel({ data : result });
				model.store = args.store;
				return model;
			}
		}
	};

	return mvc;
});