This repository was archived by the owner on Mar 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-11
lines changed
Expand file tree Collapse file tree 2 files changed +29
-11
lines changed Original file line number Diff line number Diff line change 7272 } ,
7373
7474 $remove : function ( key ) {
75- var ref = this . _ref , self = this , promise ;
75+ var ref = this . _ref , self = this ;
7676 var def = $firebaseUtils . defer ( ) ;
7777 if ( arguments . length > 0 ) {
7878 ref = ref . ref ( ) . child ( key ) ;
7979 }
8080 if ( angular . isFunction ( ref . remove ) ) {
8181 // self is not a query, just do a flat remove
8282 ref . remove ( self . _handle ( def , ref ) ) ;
83- promise = def . promise ;
8483 }
8584 else {
86- var promises = [ ] ;
8785 // self is a query so let's only remove the
8886 // items in the query and not the entire path
8987 ref . once ( 'value' , function ( snap ) {
88+ var promises = [ ] ;
9089 snap . forEach ( function ( ss ) {
9190 var d = $firebaseUtils . defer ( ) ;
92- promises . push ( d ) ;
93- ss . ref ( ) . remove ( self . _handle ( d , ss . ref ( ) ) ) ;
91+ promises . push ( d . promise ) ;
92+ ss . ref ( ) . remove ( self . _handle ( d ) ) ;
9493 } , self ) ;
94+ $firebaseUtils . allPromises ( promises )
95+ . then ( function ( ) {
96+ def . resolve ( ref ) ;
97+ } ,
98+ function ( err ) {
99+ def . reject ( err ) ;
100+ }
101+ ) ;
95102 } ) ;
96- promise = $firebaseUtils . allPromises ( promises )
97- . then ( function ( ) {
98- return ref ;
99- } ) ;
100103 }
101- return promise ;
104+ return def . promise ;
102105 } ,
103106
104107 $update : function ( key , data ) {
Original file line number Diff line number Diff line change @@ -239,7 +239,8 @@ describe('$firebase', function () {
239239 var ref = new Firebase ( 'Mock://' ) . child ( 'ordered' ) . limit ( 2 ) ;
240240 var $fb = $firebase ( ref ) ;
241241 $fb . $remove ( ) . then ( spy ) ;
242- flushAll ( ) ;
242+ flushAll ( ref ) ;
243+ flushAll ( ref ) ;
243244 expect ( spy ) . toHaveBeenCalledWith ( ref ) ;
244245 } ) ;
245246
@@ -305,6 +306,20 @@ describe('$firebase', function () {
305306 }
306307 } ) ;
307308 } ) ;
309+
310+ it ( 'should wait to resolve promise until data is actually deleted' , function ( ) {
311+ var ref = new Firebase ( 'Mock://' ) . child ( 'ordered' ) . limit ( 2 ) ;
312+ var $fb = $firebase ( ref ) ;
313+ var resolved = false ;
314+ $fb . $remove ( ) . then ( function ( ) {
315+ resolved = true ;
316+ } ) ;
317+ try { $timeout . flush ( ) ; } catch ( e ) { } //this may actually throw an error
318+ expect ( resolved ) . toBe ( false ) ;
319+ flushAll ( ref ) ;
320+ flushAll ( ref ) ;
321+ expect ( resolved ) . toBe ( true ) ;
322+ } ) ;
308323 } ) ;
309324
310325 describe ( '$update' , function ( ) {
You can’t perform that action at this time.
0 commit comments