Skip to content

Commit

Permalink
Fix for issue #16 - unstick model each time bindings are initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
delambo committed Oct 21, 2012
1 parent e7d3b18 commit 4e79ec4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions backbone.stickit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
// [{model,event,fn}, ...]
_modelBindings: null,

// Unbind the model bindings that are referenced in `this._modelBindings`.
unstickModel: function() {
_.each(this._modelBindings, function(binding) {
// Unbind the model bindings that are referenced in `this._modelBindings`. If
// the optional `model` parameter is defined, then only delete bindings for
// the given `model`.
unstickModel: function(model) {
_.each(this._modelBindings, _.bind(function(binding, i) {
if (model && binding.model !== model) return false;
binding.model.off(binding.event, binding.fn);
});
this._modelBindings = [];
delete this._modelBindings[i];
}, this));
this._modelBindings = _.compact(this._modelBindings);
},

// Using `this.bindings` configuration or the `optionalBindingsConfig`, binds `this.model`
Expand All @@ -28,6 +32,7 @@
props = ['autofocus', 'autoplay', 'async', 'checked', 'controls', 'defer', 'disabled', 'hidden', 'loop', 'multiple', 'open', 'readonly', 'required', 'scoped', 'selected'];

this._modelBindings || (this._modelBindings = []);
this.unstickModel(model);

this.events || (this.events = {});

Expand Down

0 comments on commit 4e79ec4

Please sign in to comment.