Skip to content

Commit

Permalink
featI(firestore): add firestore to factory
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredoperez committed Jan 4, 2018
1 parent c7d636c commit f5ab518
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/services/firestore-repository.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

import { Injectable } from '@angular/core';
import {
AngularFirestore, AngularFirestoreCollection,
AngularFirestoreDocument
Expand All @@ -10,10 +10,13 @@ import { FirebaseEntity } from '../models/firebase-entity.model';
import { Repository } from '../models/repository.model';
import * as _ from 'lodash';

@Injectable()
export class FirestoreRepository<T extends FirebaseEntity>
implements Repository<FirebaseEntity> {

constructor(public entity: FirebaseEntity, private readonly afs: AngularFirestore) { }
constructor(
public entity: FirebaseEntity,
private afs: AngularFirestore) { }

// TODO: include firestore configuration to opt-in for snapshotChanges().
// Defaulting to valueChanges() instead.
Expand Down
10 changes: 8 additions & 2 deletions src/services/repository-factory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { FirebaseApp } from 'angularfire2';
import { AngularFireDatabase } from 'angularfire2/database';

import { AngularFirestore } from 'angularfire2/firestore';
import { FirebaseRepository } from './firebase-repository.service';
import { BaseEntity } from '../models/entity.model';
import { DataSource, DataSourceType } from '../models/datasource.model';
import { Repository } from '../models/repository.model';
import { FirebaseEntity } from '../models/firebase-entity.model';
import { FirestoreRepository } from './firestore-repository.service';

@Injectable()
export class DataServiceFactory {
constructor(
private http: HttpClient,
private fbDb?: AngularFireDatabase,
private fb?: FirebaseApp
private fb?: FirebaseApp,
private fbStore?: AngularFirestore
) { }

create(
Expand All @@ -33,6 +35,10 @@ export class DataServiceFactory {
case DataSourceType.rest:
break;
case DataSourceType.firestore:
service = new FirestoreRepository(
entity as FirebaseEntity,
this.fbStore
);
break;
default:
break;
Expand Down

0 comments on commit f5ab518

Please sign in to comment.