Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix so it compiles

  • Loading branch information...
commit d684d42a334b5065f5487b8b79399bf13de1b813 1 parent 4a8e45b
Rhys Brett-Bowen authored April 03, 2012
2  collection.js
@@ -144,7 +144,7 @@ mvc.Collection.prototype.add = function(model, opt_ind, opt_silent) {
144 144
     }, this);
145 145
   }
146 146
   if (goog.isNumber(opt_ind) && opt_ind < 0) {
147  
-    opt_ind = this.models.length + opt_ind;
  147
+    opt_ind = this.models_.length + opt_ind;
148 148
   }
149 149
   var insert = false;
150 150
   if (!goog.array.find(this.models_, function(mod) {
9  mediator.js
@@ -86,7 +86,7 @@ mvc.Mediator.prototype.unregister = function(obj, opt_messages) {
86 86
  * @param {Function|Object} fn to run on message or object of functions to run
87 87
  * that can include init, fn and dispose.
88 88
  * @param {Object=} opt_handler to use as 'this' for the function.
89  
- * @return {number} the id to pass to off method.
  89
+ * @return {?number} the id to pass to off method.
90 90
  */
91 91
 mvc.Mediator.prototype.on = function(message, fn, opt_handler) {
92 92
   if (goog.isArrayLike(message)) {
@@ -101,8 +101,11 @@ mvc.Mediator.prototype.on = function(message, fn, opt_handler) {
101 101
       fn.init(this.available_[message][0]);
102 102
     }
103 103
   }
  104
+  if (goog.isFunction(fn)) {
  105
+    fn = {fn: fn};
  106
+  }
104 107
   goog.array.insert(this.listeners_[message],
105  
-      goog.bind(fn, opt_handler || this));
  108
+      goog.bind(fn.fn, opt_handler || this));
106 109
   return goog.getUid(fn);
107 110
 };
108 111
 
@@ -121,7 +124,7 @@ mvc.Mediator.prototype.once = function(message, handler) {
121 124
     this.off(uid);
122 125
   },this);
123 126
   uid = this.on(message, fn);
124  
-  return uid;
  127
+  return /** @type {number} */(uid);
125 128
 };
126 129
 
127 130
 
4  model.js
@@ -136,7 +136,7 @@ mvc.Model.prototype.parseSchemaFn_ = function(fn) {
136 136
             throw new Error();
137 137
     };
138 138
   }
139  
-  return val;
  139
+  return /** @type {Function} */(val);
140 140
 };
141 141
 
142 142
 
@@ -535,7 +535,7 @@ mvc.Model.prototype.change_ = function() {
535 535
 
536 536
 /**
537 537
  * @param {Function} fn function to run when model is disposed.
538  
- * @param {*=} opt_handler object for 'this' of function.
  538
+ * @param {Object=} opt_handler object for 'this' of function.
539 539
  * @return {number} id to use for unbind.
540 540
  */
541 541
 mvc.Model.prototype.bindUnload = function(fn, opt_handler) {
152  sync/ajax.js
@@ -7,136 +7,162 @@
7 7
 
8 8
 goog.provide('mvc.AjaxSync');
9 9
 
  10
+goog.require('goog.Uri.QueryData');
  11
+goog.require('goog.net.XhrManager');
10 12
 goog.require('mvc.Sync');
11 13
 
12  
-goog.require('goog.net.XhrManager');
13  
-goog.require('goog.Uri.QueryData');
  14
+
14 15
 
15 16
 /**
16 17
  * @constructor
17 18
  * @implements {mvc.Sync}
  19
+ * @param {Object|string|Function} url used to construct URLs.
18 20
  */
19 21
 mvc.AjaxSync = function(url) {
20 22
 
21  
-    var baseFunction = function(model){return "";};
22  
-
23  
-    this.baseUrls_ = {
24  
-        create: baseFunction,
25  
-        read: baseFunction,
26  
-        update: baseFunction,
27  
-        del: baseFunction
  23
+  var baseFunction = function(model) {return '';};
  24
+
  25
+  this.baseUrls_ = {
  26
+    create: baseFunction,
  27
+    read: baseFunction,
  28
+    update: baseFunction,
  29
+    del: baseFunction
  30
+  };
  31
+
  32
+  if (goog.isString(url) || goog.isFunction(url)) {
  33
+    url = {
  34
+      create: url,
  35
+      read: url,
  36
+      update: url,
  37
+      del: url
28 38
     };
29  
-
30  
-    if(goog.isString(url) || goog.isFunction(url)) {
31  
-        url = {
32  
-            create: url,
33  
-            read: url,
34  
-            update: url,
35  
-            del: url
36  
-        };
37  
-    }
38  
-    goog.object.extend(this.baseUrls_, goog.object.map(url, this.urlifyString));
39  
-    this.xhr_ = new goog.net.XhrManager();
40  
-    this.sendCount_ = 0;
  39
+  }
  40
+  goog.object.extend(this.baseUrls_, goog.object.map(url, this.urlifyString));
  41
+  this.xhr_ = new goog.net.XhrManager();
  42
+  this.sendCount_ = 0;
41 43
 };
42 44
 
  45
+
43 46
 /**
44 47
  * takes a string defining a url where :attribute will return that models
45 48
  * attribute. e.g.
46  
- * 
  49
+ *
47 50
  * var obj = new mvc.Model({attrs:{'id': 'fred'}});
48 51
  * var urlGen = urlifyString("/object=:id/blah");
49 52
  * urlGen(obj); // returns "/object=fred/blah"
50  
- * 
51 53
  *
52  
- * @param {string} val
53  
- * @return {function(mvc.Model):string}
  54
+ *
  55
+ * @param {string} val to be changed to a function.
  56
+ * @return {function(mvc.Model):string} function that gives URL.
54 57
  */
55 58
 mvc.AjaxSync.prototype.urlifyString = function(val) {
56  
-    if(goog.isString(val))
57  
-        return function(model) {
58  
-            return val.replace(/:(\w+)/g, function(id) {
59  
-                return model.get(id.substring(1));
60  
-        });};
61  
-    return /** @type {function(mvc.Model):string} */(val);
  59
+  if (goog.isString(val)) {
  60
+    return function(model) {
  61
+      return val.replace(/:(\w+)/g,
  62
+          function(id) {
  63
+            return model.get(id.substring(1));
  64
+          });
  65
+    };
  66
+  }
  67
+  return /** @type {function(mvc.Model):string} */(val);
62 68
 };
63 69
 
  70
+
64 71
 /**
65 72
  * @inheritDoc
66 73
  */
67  
-mvc.AjaxSync.prototype.create = function(model, callback) {
  74
+mvc.AjaxSync.prototype.create = function(model, opt_callback) {
68 75
 
69  
-    this.xhr_.send(""+(this.sendCount_++), this.baseUrls_.create(model),
70  
-        "POST", goog.Uri.QueryData.createFromMap(model.toJson()).toString(),
71  
-        undefined,  undefined,
72  
-        goog.bind(this.onCreateComplete_, this, model, callback));
  76
+  this.xhr_.send('' + (this.sendCount_++), this.baseUrls_.create(model),
  77
+      'POST', goog.Uri.QueryData.createFromMap(model.toJson()).toString(),
  78
+      undefined, undefined,
  79
+      goog.bind(this.onCreateComplete_, this, model,
  80
+          (opt_callback || goog.nullFunction)));
73 81
 };
74 82
 
  83
+
75 84
 /**
76 85
  * @inheritDoc
77 86
  */
78  
-mvc.AjaxSync.prototype.read = function(model, callback) {
79  
-    this.xhr_.send(""+(this.sendCount_++), this.baseUrls_.read(model),
80  
-        "GET", undefined, undefined, undefined,
81  
-        goog.bind(this.onReadComplete_, this, model, callback));
  87
+mvc.AjaxSync.prototype.read = function(model, opt_callback) {
  88
+  this.xhr_.send('' + (this.sendCount_++), this.baseUrls_.read(model),
  89
+      'GET', undefined, undefined, undefined,
  90
+      goog.bind(this.onReadComplete_, this, model,
  91
+          (opt_callback || goog.nullFunction)));
82 92
 };
83 93
 
  94
+
84 95
 /**
85 96
  * @inheritDoc
86 97
  */
87  
-mvc.AjaxSync.prototype.update = function(model, callback) {
88  
-    this.xhr_.send(""+(this.sendCount_++), this.baseUrls_.update(model),
89  
-        "PUT", goog.Uri.QueryData.createFromMap(model.toJson()).toString(),
90  
-        {'Content-Type' : 'application/x-www-form-urlencoded'}, undefined,
91  
-        goog.bind(this.onUpdateComplete_, this, model, callback));
  98
+mvc.AjaxSync.prototype.update = function(model, opt_callback) {
  99
+  this.xhr_.send('' + (this.sendCount_++), this.baseUrls_.update(model),
  100
+      'PUT', goog.Uri.QueryData.createFromMap(model.toJson()).toString(),
  101
+      {'Content-Type' : 'application/x-www-form-urlencoded'}, undefined,
  102
+      goog.bind(this.onUpdateComplete_, this, model,
  103
+          (opt_callback || goog.nullFunction)));
92 104
 };
93 105
 
  106
+
94 107
 /**
95 108
  * @inheritDoc
96 109
  */
97  
-mvc.AjaxSync.prototype.del = function(model, callback) {
98  
-    this.xhr_.send(""+(this.sendCount_++), this.baseUrls_.del(model),
99  
-        "DELETE", undefined, undefined, undefined, 
100  
-        goog.bind(this.onDelComplete_, this, model, callback));
  110
+mvc.AjaxSync.prototype.del = function(model, opt_callback) {
  111
+  this.xhr_.send('' + (this.sendCount_++), this.baseUrls_.del(model),
  112
+      'DELETE', undefined, undefined, undefined,
  113
+      goog.bind(this.onDelComplete_, this, model,
  114
+          (opt_callback || goog.nullFunction)));
101 115
 };
102 116
 
  117
+
103 118
 /**
104 119
  * override this to do processing on returned data
105 120
  *
106  
- * @param {mvc.Model} model
107  
- * @param {Function} callback
  121
+ * @private
  122
+ * @param {mvc.Model} model being processed.
  123
+ * @param {Function} callback to be called when done.
  124
+ * @param {goog.events.Event} e the completed xhr event.
108 125
  */
109 126
 mvc.AjaxSync.prototype.onCreateComplete_ = function(model, callback, e) {
110  
-    var xhr = e.target;
111  
-    model.set('id', xhr.getResponseJson()['result']['id']);
  127
+  var xhr = e.target;
  128
+  model.set('id', xhr.getResponseJson()['result']['id']);
112 129
 };
113 130
 
  131
+
114 132
 /**
115 133
  * override this to do processing on returned data
116 134
  *
117  
- * @param {mvc.Model} model
118  
- * @param {Function} callback
  135
+ * @private
  136
+ * @param {mvc.Model} model being processed.
  137
+ * @param {Function} callback to be called when done.
  138
+ * @param {goog.events.Event} e the completed xhr event.
119 139
  */
120 140
 mvc.AjaxSync.prototype.onReadComplete_ = function(model, callback, e) {
121  
-     var xhr = e.target;
122  
-    var json = xhr.getResponseJson()['result'];
123  
-    model.set(json);
  141
+  var xhr = e.target;
  142
+  var json = xhr.getResponseJson()['result'];
  143
+  model.set(json);
124 144
 };
125 145
 
  146
+
126 147
 /**
127 148
  * override this to do processing on returned data
128 149
  *
129  
- * @param {mvc.Model} model
130  
- * @param {Function} callback
  150
+ * @private
  151
+ * @param {mvc.Model} model being processed.
  152
+ * @param {Function} callback to be called when done.
  153
+ * @param {Event} e the completed xhr event.
131 154
  */
132 155
 mvc.AjaxSync.prototype.onUpdateComplete_ = function(model, callback, e) {
133 156
 };
134 157
 
  158
+
135 159
 /**
136 160
  * override this to do processing on returned data
137 161
  *
138  
- * @param {mvc.Model} model
139  
- * @param {Function} callback
  162
+ * @private
  163
+ * @param {mvc.Model} model being processed.
  164
+ * @param {Function} callback to be called when done.
  165
+ * @param {Event} e the completed xhr event.
140 166
  */
141 167
 mvc.AjaxSync.prototype.onDelComplete_ = function(model, callback, e) {
142  
-};
  168
+};
47  sync/local.js
@@ -9,32 +9,55 @@ goog.provide('mvc.LocalSync');
9 9
 goog.require('goog.storage.Storage');
10 10
 goog.require('goog.storage.mechanism.HTML5LocalStorage');
11 11
 
  12
+
  13
+
12 14
 /**
13 15
  * @constructor
14 16
  * @implements {mvc.Sync}
15 17
  */
16 18
 mvc.LocalSync = function() {
17  
-    this.store_ = new goog.storage.Storage(new goog.storage.mechanism.HTML5LocalStorage());
  19
+  this.store_ = new goog.storage.Storage(
  20
+      new goog.storage.mechanism.HTML5LocalStorage());
18 21
 };
19 22
 
  23
+
  24
+/**
  25
+ * @return {string} uid for object.
  26
+ */
20 27
 mvc.LocalSync.prototype.getUID = function() {
21  
-    this.counter_ = this.counter_||0;
22  
-    return (this.counter_++)+"|"+parseInt((new Date()).getTime(), 36);
  28
+  this.counter_ = this.counter_ || 0;
  29
+  return (this.counter_++) + '|' + parseInt((new Date()).getTime(), 36);
23 30
 };
24 31
 
25  
-mvc.LocalSync.prototype.create = function(model, callback) {
26  
-    var id = this.getUID();
27  
-    model.set('id', id);
  32
+
  33
+/**
  34
+ * @inheritDoc
  35
+ */
  36
+mvc.LocalSync.prototype.create = function(model, opt_callback) {
  37
+  var id = this.getUID();
  38
+  model.set('id', id);
28 39
 };
29 40
 
30  
-mvc.LocalSync.prototype.read = function(model, callback) {
31  
-    model.set(this.store_.get(model.get('id')));
  41
+
  42
+/**
  43
+ * @inheritDoc
  44
+ */
  45
+mvc.LocalSync.prototype.read = function(model, opt_callback) {
  46
+  model.set(this.store_.get(model.get('id')));
32 47
 };
33 48
 
34  
-mvc.LocalSync.prototype.update = function(model, callback) {
35  
-    this.store_.set(model.get('id'), model.toJson());
  49
+
  50
+/**
  51
+ * @inheritDoc
  52
+ */
  53
+mvc.LocalSync.prototype.update = function(model, opt_callback) {
  54
+  this.store_.set(model.get('id'), model.toJson());
36 55
 };
37 56
 
38  
-mvc.LocalSync.prototype.del = function(model, callback) {
39  
-    this.store_.remove(model.get('id'));
  57
+
  58
+/**
  59
+ * @inheritDoc
  60
+ */
  61
+mvc.LocalSync.prototype.del = function(model, opt_callback) {
  62
+  this.store_.remove(model.get('id'));
40 63
 };
48  sync/sync.js
@@ -43,38 +43,46 @@ mvc.Sync.Status = {
43 43
     GATEWAY_TIMEOUT: 504
44 44
 }*/
45 45
 
  46
+
46 47
 /**
47  
- * take in the model to push to server (use .toJson()) and call callback when done
48  
- * pass in the json and status (use HTTP status codes) as a number
  48
+ * take in the model to push to server (use .toJson())
  49
+ * and call callback when done
  50
+ * pass in the json and status (use HTTP status codes) as a number.
49 51
  *
50  
- * @param {mvc.Model} model
51  
- * @param {function(Object, number)} callback
  52
+ * @param {mvc.Model} model to create.
  53
+ * @param {function(Object, number)=} opt_callback optional.
52 54
  */
53  
-mvc.Sync.prototype.create = function(model, callback) {};
  55
+mvc.Sync.prototype.create = function(model, opt_callback) {};
  56
+
54 57
 
55 58
 /**
56  
- * take in the model to push to server (use .toJson()) and call callback when done
57  
- * pass in the json and status (use HTTP status codes) as a number
  59
+ * take in the model to push to server (use .toJson())
  60
+ * and call callback when done
  61
+ * pass in the json and status (use HTTP status codes) as a number.
58 62
  *
59  
- * @param {mvc.Model} model
60  
- * @param {function(Object, number)} callback
  63
+ * @param {mvc.Model} model to refresh.
  64
+ * @param {function(Object, number)=} opt_callback optional.
61 65
  */
62  
-mvc.Sync.prototype.read = function(model, callback) {};
  66
+mvc.Sync.prototype.read = function(model, opt_callback) {};
  67
+
63 68
 
64 69
 /**
65  
- * take in the model to push to server (use .toJson()) and call callback when done
66  
- * pass in the json and status (use HTTP status codes) as a number
  70
+ * take in the model to push to server (use .toJson())
  71
+ * and call callback when done
  72
+ * pass in the json and status (use HTTP status codes) as a number.
67 73
  *
68  
- * @param {mvc.Model} model
69  
- * @param {function(Object, number)} callback
  74
+ * @param {mvc.Model} model to update.
  75
+ * @param {function(Object, number)=} opt_callback optional.
70 76
  */
71  
-mvc.Sync.prototype.update = function(model, callback) {};
  77
+mvc.Sync.prototype.update = function(model, opt_callback) {};
  78
+
72 79
 
73 80
 /**
74  
- * take in the model to push to server (use .toJson()) and call callback when done
75  
- * pass in the status (use HTTP status codes) as a number
  81
+ * take in the model to push to server (use .toJson())
  82
+ * and call callback when done
  83
+ * pass in the status (use HTTP status codes) as a number.
76 84
  *
77  
- * @param {mvc.Model} model
78  
- * @param {function(number)} callback
  85
+ * @param {mvc.Model} model to delete.
  86
+ * @param {Function=} opt_callback optional.
79 87
  */
80  
-mvc.Sync.prototype.del = function(model, callback) {};
  88
+mvc.Sync.prototype.del = function(model, opt_callback) {};

0 notes on commit d684d42

Please sign in to comment.
Something went wrong with that request. Please try again.