File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 11feature - Upgraded Firebase dependency to 2.x.x.
2+ fixed - Fixed bug which caused `unbind()` to be called on a previously unbound reference when a component was unmounted.
Original file line number Diff line number Diff line change 351351 this . firebaseRefs [ bindVar ] . off ( event , offListener ) ;
352352 }
353353 }
354- this . firebaseRefs [ bindVar ] = undefined ;
355- this . firebaseListeners [ bindVar ] = undefined ;
354+ delete this . firebaseRefs [ bindVar ] ;
355+ delete this . firebaseListeners [ bindVar ] ;
356356
357357 // Update state
358358 var newState = { } ;
Original file line number Diff line number Diff line change @@ -1104,5 +1104,40 @@ describe('ReactFire', function() {
11041104
11051105 shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
11061106 } ) ;
1107+
1108+ it ( 'handles already unbound state when the component unmounts' , function ( done ) {
1109+ var TestComponent = React . createClass ( {
1110+ mixins : [ ReactFireMixin ] ,
1111+
1112+ componentWillMount : function ( ) {
1113+ sinon . spy ( this , 'unbind' ) ;
1114+
1115+ this . bindAsArray ( firebaseRef , 'items0' ) ;
1116+ this . bindAsObject ( firebaseRef , 'items1' ) ;
1117+
1118+ firebaseRef . set ( {
1119+ first : { index : 0 } ,
1120+ second : { index : 1 } ,
1121+ third : { index : 2 }
1122+ } , function ( ) {
1123+ this . unbind ( 'items0' ) ;
1124+
1125+ shallowRenderer . unmount ( ) ;
1126+
1127+ expect ( this . unbind ) . to . have . been . calledTwice ;
1128+ expect ( this . unbind . args [ 0 ] [ 0 ] ) . to . equal ( 'items0' ) ;
1129+ expect ( this . unbind . args [ 1 ] [ 0 ] ) . to . equal ( 'items1' ) ;
1130+
1131+ done ( ) ;
1132+ } . bind ( this ) ) ;
1133+ } ,
1134+
1135+ render : function ( ) {
1136+ return React . DOM . div ( null ) ;
1137+ }
1138+ } ) ;
1139+
1140+ shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
1141+ } ) ;
11071142 } ) ;
11081143} ) ;
You can’t perform that action at this time.
0 commit comments