News for hackers. Stuff that matters.
Re: Sproutcore vs jQuery +backbone.js by raganwald on Wednesday January 19, 2011 @12:22PM (#2120483)
If you have a models that contains other models. At first, I thought that would be builtin, but it is not. So, if you want to do that the backbone way, you really need to hack it so change in inner models propagate to outside models.

Can you expound on this requirement, perhaps give an example? I'm very interested in what you want to accomplish.

Re: Sproutcore vs jQuery +backbone.js by d0m on Wednesday January 19, 2011 @12:35PM (#2120541)
A post that contains comments. Say you have:

  { id: 3, text: 'test', comments: [{ cid:4, bleh:5}, {c id:6, bleh:4}] } 
You give that to a model. It won't automatically create a collection with comments.

The idea behind backbone is that I could insert a new comment in the page by simply .add() something to the comments collection. Automatically, that would trigger a add/change event so that my view could update itself. However, it was really quite complicated to obtain that behavior.

I know it's a simple example but the more I used backbone, the more "simple" things like that happened where I had to dig into things I shouldn't have to.

I feel that simple cases should be simple while I would understand that complicated case might be more complicated. However, with backbone.js, I really feel that simple cases aren't that simple.

Re: Sproutcore vs jQuery +backbone.js by raganwald on Wednesday January 19, 2011 @01:03PM (#2120624)
So given:

    window.Post = Backbone.Model.extend({...});
    window.Comments = Backbone.Collection.extend({...});
    var p = new Post(
      id: 3, 
      text: 'test', 
      comments: [
        { cid:4, bleh:5}, 
        {c id:6, bleh:4}
      ] 
    });
You want some way to declare that comments are Comments, so that it is always the case that:

    (p.attributes.comments instanceof Comments) === true 
And you also want:

    p.attributes.comments.add({...});
To trigger a 'change:comments' event on p, even though you aren't changing the reference to the comments collection, just changing its comments.

Do I understand you correctly?

Re: Sproutcore vs jQuery +backbone.js by elliottkember on Wednesday January 19, 2011 @04:33PM (#2121352)
I've found myself wanting this, too - I sometimes get confused as to which features I can use between models and collections.i
Re: Sproutcore vs jQuery +backbone.js by d0m on Thursday January 20, 2011 @07:51AM (#2123452)
Yes, perfectly.
Re: Sproutcore vs jQuery +backbone.js by raganwald on Saturday January 22, 2011 @12:01AM (#2129976)