Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
feature - Upgraded Firebase dependency to 2.x.x.
fixed - Fixed bug which caused `unbind()` to be called on a previously unbound reference when a component was unmounted.
4 changes: 2 additions & 2 deletions src/reactfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@
this.firebaseRefs[bindVar].off(event, offListener);
}
}
this.firebaseRefs[bindVar] = undefined;
this.firebaseListeners[bindVar] = undefined;
delete this.firebaseRefs[bindVar];
delete this.firebaseListeners[bindVar];

// Update state
var newState = {};
Expand Down
35 changes: 35 additions & 0 deletions tests/reactfire.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,5 +1104,40 @@ describe('ReactFire', function() {

shallowRenderer.render(React.createElement(TestComponent));
});

it('handles already unbound state when the component unmounts', function(done) {
var TestComponent = React.createClass({
mixins: [ReactFireMixin],

componentWillMount: function() {
sinon.spy(this, 'unbind');

this.bindAsArray(firebaseRef, 'items0');
this.bindAsObject(firebaseRef, 'items1');

firebaseRef.set({
first: { index: 0 },
second: { index: 1 },
third: { index: 2 }
}, function() {
this.unbind('items0');

shallowRenderer.unmount();

expect(this.unbind).to.have.been.calledTwice;
expect(this.unbind.args[0][0]).to.equal('items0');
expect(this.unbind.args[1][0]).to.equal('items1');

done();
}.bind(this));
},

render: function() {
return React.DOM.div(null);
}
});

shallowRenderer.render(React.createElement(TestComponent));
});
});
});