documentcloud/backbone — Issue #1081: Binding model.save() to the 'change' event causes infinite loop (localstorage only)
Author: philipwalton
Created: 2012-03-09 00:27:38+00:00
State: open

If I bind `model.save()` to a model's `change` event and I'm saving to localstorage, an infinite loop results where the `save()` action triggers a `change` event that in turns invokes another save.

You can see this in action by adding the following code to the `initialize` method of the todos model in the sample app:

```
initialize: function() {
this.bind('change', function() {
this.save();
});
}
```

Strangely, this issue doesn't appear if I put the `save()` invokation inside a setTimeout, leading me to believe that the quickness of saving to localstorage causes it to finish before the change event dispatching is complete.