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 1+ 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 @@ -1105,5 +1105,40 @@ describe('ReactFire', function() {
11051105
11061106 shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
11071107 } ) ;
1108+
1109+ it ( 'handles already unbound state when the component unmounts' , function ( done ) {
1110+ var TestComponent = React . createClass ( {
1111+ mixins : [ ReactFireMixin ] ,
1112+
1113+ componentWillMount : function ( ) {
1114+ sinon . spy ( this , 'unbind' ) ;
1115+
1116+ this . bindAsArray ( firebaseRef , 'items0' ) ;
1117+ this . bindAsObject ( firebaseRef , 'items1' ) ;
1118+
1119+ firebaseRef . set ( {
1120+ first : { index : 0 } ,
1121+ second : { index : 1 } ,
1122+ third : { index : 2 }
1123+ } , function ( ) {
1124+ this . unbind ( 'items0' ) ;
1125+
1126+ shallowRenderer . unmount ( ) ;
1127+
1128+ expect ( this . unbind ) . to . have . been . calledTwice ;
1129+ expect ( this . unbind . args [ 0 ] [ 0 ] ) . to . equal ( 'items0' ) ;
1130+ expect ( this . unbind . args [ 1 ] [ 0 ] ) . to . equal ( 'items1' ) ;
1131+
1132+ done ( ) ;
1133+ } . bind ( this ) ) ;
1134+ } ,
1135+
1136+ render : function ( ) {
1137+ return React . DOM . div ( null ) ;
1138+ }
1139+ } ) ;
1140+
1141+ shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
1142+ } ) ;
11081143 } ) ;
11091144} ) ;
You can’t perform that action at this time.
0 commit comments