Permalink
Browse files

Handle adding attributes/values/properties/verbs better.

  • Loading branch information...
1 parent ec1db3f commit 73d00acdd6180ac8b5e3ec52cb9431aae57a6fd1 @toddsundsted committed Mar 27, 2012
Showing with 223 additions and 134 deletions.
  1. +1 −1 files/public/SpecRunner.html
  2. +32 −4 files/public/js/moo-0.0.1.js
  3. +1 −1 files/public/js/moo-0.0.1.min.js
  4. +189 −128 files/public/spec/MooSpec.js
@@ -18,7 +18,7 @@
<script type="text/javascript" src="js/jquery.ui.core-1.8.18.min.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget-1.8.18.min.js"></script>
<script type="text/javascript" src="js/underscore-1.3.1.min.js"></script>
- <script type="text/javascript" src="js/backbone-0.9.1.min.js"></script>
+ <script type="text/javascript" src="js/backbone-0.9.2.min.js"></script>
<script type="text/javascript" src="js/moo-0.0.1.min.js"></script>
<script type="text/javascript">
@@ -226,19 +226,47 @@ var Moo = {};
}
});
- Moo.Attributes = Backbone.Collection.extend({
+ Moo.Collection = Backbone.Collection.extend({
+
+ add: function(models, opts) {
+ models = _.isArray(models) ? models.slice() : [models];
+
+ var mapped = this instanceof Moo.Attributes || this instanceof Moo.Values;
+
+ models = _.chain(models).map(function (model) {
+ if (!('id' in model))
+ if (mapped) {
+ /* transform attributes and values from {foo: {...}}} to {id: foo, ...} */
+ return _.map(model, function(v, k) {
+ v.id = k;
+ return v;
+ });
+ }
+ else {
+ /* add an id to properties and verbs */
+ model.id = models.length;
+ return model;
+ }
+ return model;
+ }).flatten().value();
+
+ return Backbone.Collection.prototype.add.call(this, models, opts);
+ }
+ });
+
+ Moo.Attributes = Moo.Collection.extend({
model: Moo.Attribute
});
- Moo.Values = Backbone.Collection.extend({
+ Moo.Values = Moo.Collection.extend({
model: Moo.Value
});
- Moo.Properties = Backbone.Collection.extend({
+ Moo.Properties = Moo.Collection.extend({
model: Moo.Property
});
- Moo.Verbs = Backbone.Collection.extend({
+ Moo.Verbs = Moo.Collection.extend({
model: Moo.Verb
});
Oops, something went wrong.

0 comments on commit 73d00ac

Please sign in to comment.