component / model

Minimalistic extensible data models
122 stars 40 forks source link

Update model locally after save #49

Open cristiandouce opened 11 years ago

cristiandouce commented 11 years ago

A use case:

var Post = model('Post')
  .attr('id')
  .attr('title')
  .attr('slug')
  .attr('content')
  .attr('author');

var post = new Post({
  title: "My new post",
  content: "My awesome post content"
});

post.save(function(err, res) {
  post.slug() // undefined
  res.body.slug // "my-new-post"

  post.author() // undefined
  res.body.author // "Cristian Douce"
});

It would be nice to have this kind of sync between model instance and server response object. Now I have to manually set an onsave callback and update model manually with the con of having my model dirty after that. Not nice :(

yocontra commented 10 years ago

:+1: