Skip to content

Commit 18946d1

Browse files
committed
Fixed datasbase ios off event
1 parent 6aceb3b commit 18946d1

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

ios/Firestack/Firestack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
- (void) debugLog:(NSString *)title
2727
msg:(NSString *)msg;
2828

29+
- (void) sendJSEvent:(NSString *)title
30+
props:(NSDictionary *)props;
31+
2932

3033
@property (nonatomic) BOOL debug;
3134
@property (atomic) BOOL configured;

ios/Firestack/FirestackDatabase.m

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright © 2016 Facebook. All rights reserved.
77
//
88

9+
#import "Firestack.h"
910
#import "FirestackDatabase.h"
1011
#import "FirestackEvents.h"
1112

@@ -215,18 +216,20 @@ - (int) eventTypeFromName:(NSString *)name
215216
}
216217

217218
- (void) cleanup {
218-
FIRDatabaseReference *ref = [self getRef];
219+
if (self.childValueHandler > 0) {
220+
[self removeEventHandler:DATABASE_VALUE_EVENT];
221+
}
219222
if (self.childAddedHandler > 0) {
220-
[ref removeObserverWithHandle:self.childAddedHandler];
223+
[self removeEventHandler:DATABASE_CHILD_ADDED_EVENT];
221224
}
222225
if (self.childModifiedHandler > 0) {
223-
[ref removeObserverWithHandle:self.childModifiedHandler];
226+
[self removeEventHandler:DATABASE_CHILD_MODIFIED_EVENT];
224227
}
225228
if (self.childRemovedHandler > 0) {
226-
[ref removeObserverWithHandle:self.childRemovedHandler];
229+
[self removeEventHandler:DATABASE_CHILD_REMOVED_EVENT];
227230
}
228231
if (self.childMovedHandler > 0) {
229-
[ref removeObserverWithHandle:self.childMovedHandler];
232+
[self removeEventHandler:DATABASE_CHILD_MOVED_EVENT];
230233
}
231234
}
232235

@@ -377,7 +380,7 @@ @implementation FirestackDatabase
377380
[r setEventHandler:handle
378381
forName:eventName];
379382

380-
[self saveDBHandle:path dbRef:r];
383+
// [self saveDBHandle:path dbRef:r];
381384

382385
callback(@[[NSNull null], @{
383386
@"result": @"success",
@@ -425,14 +428,15 @@ @implementation FirestackDatabase
425428
FirestackDBReference *r = [self getDBHandle:path];
426429
if (eventName == nil || [eventName isEqualToString:@""]) {
427430
[r cleanup];
431+
[self removeDBHandle:path];
428432
} else {
429433
[r removeEventHandler:eventName];
430434
if (![r hasListeners]) {
431435
[self removeDBHandle:path];
432436
}
433437
}
434438

435-
[self saveDBHandle:path dbRef:r];
439+
// [self saveDBHandle:path dbRef:r];
436440

437441
callback(@[[NSNull null], @{
438442
@"result": @"success",

lib/modules/database.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,17 @@ class DatabaseRef extends ReferenceBase {
195195
});
196196
}
197197

198-
once(evt='once') {
198+
once(evt='once', cb) {
199199
const path = this.dbPath();
200200
const modifiers = this.dbModifiers();
201201
return promisify('onOnce', FirestackDatabase)(path, modifiers, evt)
202202
.then(({snapshot}) => new DataSnapshot(this, snapshot))
203+
.then(snapshot => {
204+
if (cb && typeof cb === 'function') {
205+
cb(snapshot);
206+
}
207+
return snapshot;
208+
})
203209
}
204210

205211
off(evt='') {
@@ -208,7 +214,7 @@ class DatabaseRef extends ReferenceBase {
208214
.then(({callback, subscriptions}) => {
209215
return promisify('off', FirestackDatabase)(path, evt)
210216
.then(() => {
211-
this.listeners[evt]
217+
// subscriptions.forEach(sub => sub.remove());
212218
delete this.listeners[evt];
213219
callback(this);
214220
return subscriptions;
@@ -388,7 +394,7 @@ export class Database extends Base {
388394
}
389395

390396
const callback = (ref) => {
391-
const key = this._pathKey(path);
397+
const key = this._pathKey(ref.path);
392398
this.refs[key] = ref;
393399
}
394400
const subscriptions = [this.successListener, this.errorListener];
@@ -399,7 +405,9 @@ export class Database extends Base {
399405
const key = this._pathKey(path);
400406
// Remove subscription
401407
if (dbSubscriptions[key]) {
402-
if (dbSubscriptions[key][evt]) {
408+
if (!evt || evt === "") {
409+
dbSubscriptions[key] = {};
410+
} else if (dbSubscriptions[key][evt]) {
403411
delete dbSubscriptions[key][evt];
404412
}
405413
if (Object.keys(dbSubscriptions[key]).length <= 0) {
@@ -419,7 +427,7 @@ export class Database extends Base {
419427
}
420428
}
421429
const callback = (ref) => {
422-
const key = this._pathKey(path);
430+
const key = this._pathKey(ref.path);
423431
delete this.refs[key];
424432
}
425433
const subscriptions = [this.successListener, this.errorListener];

0 commit comments

Comments
 (0)