Skip to content

Commit 5186389

Browse files
committed
fix(database): fix Zone.js issues by running ref-gen outside angular
1 parent f8830d1 commit 5186389

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

sample/src/app/database/database.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class DatabaseComponent implements OnInit {
2121
public readonly testObjectValue$: Observable<any>;
2222

2323
constructor(state: TransferState, database: AngularFireDatabase, @Inject(PLATFORM_ID) platformId: object) {
24-
// TODO fix the Zone.js issue with AngularFireDatabase
2524
if (isPlatformServer(platformId)) {
2625
this.testObjectValue$ = EMPTY;
2726
} else {

sample/src/app/home/home.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FirebaseApp } from '@angular/fire';
66
template: `
77
Hello world!
88
{{ firebaseApp.name }}
9-
<!-- TODO wrap the Zone issue <app-database></app-database> -->
9+
<app-database></app-database>
1010
<app-firestore></app-firestore>
1111
<app-firestore-offline></app-firestore-offline>
1212
<app-storage></app-storage>

src/database/database.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class AngularFireDatabase {
6565
}
6666

6767
list<T>(pathOrRef: PathReference, queryFn?: QueryFn): AngularFireList<T> {
68-
const ref = getRef(this.database, pathOrRef);
68+
const ref = this.schedulers.ngZone.runOutsideAngular(() => getRef(this.database, pathOrRef));
6969
let query: DatabaseQuery = ref;
7070
if (queryFn) {
7171
query = queryFn(ref);
@@ -74,12 +74,13 @@ export class AngularFireDatabase {
7474
}
7575

7676
object<T>(pathOrRef: PathReference): AngularFireObject<T> {
77-
const ref = getRef(this.database, pathOrRef);
77+
const ref = this.schedulers.ngZone.runOutsideAngular(() => getRef(this.database, pathOrRef));
7878
return createObjectReference<T>(ref, this);
7979
}
8080

8181
createPushId() {
82-
return this.database.ref().push().key;
82+
const ref = this.schedulers.ngZone.runOutsideAngular(() => this.database.ref());
83+
return ref.push().key;
8384
}
8485

8586
}

0 commit comments

Comments
 (0)