feat(AngularFire): single injectable service for all APIs
In order to simplify getting a hold of AngularFire APIs via DI, a single service could contain all AngularFire APIs (authentication, getting a list, getting a root reference, etc).
With the current API surface, the service could look like:
interface AngularFire {
auth: AuthObservable; // Pending merge of #33
list: FirebaseListFactory;
object: FirebaseObjectFactory; // Not yet implemented
ref: RefFactory; // Not yet implemented
}
@Component(...)
class QuestionsList {
this.orderProp: string = 'askedTime';
this.pageSize: Observable<number>;
constructor(private af:AngularFire) {
this.questions = af.list('/questions', {
query: {
orderBy: this.orderProp
limitToFirst: this.pageSize
}]
})
}
}
@Component({
template: `
<h1 *ngIf="af.auth | async">Welcome, {{(af.auth | async).github.userName}}</h1>
`
})
class Login {
constructor(private af:AngularFire) {
}
}
BTW the biggest sore spot with the current API is the required usage of @Inject to get dependencies. That, and the current Provider-based design of FirebaseList requires two steps: declaring the provider in a Component's providers list as providers: [FirebaseList('/path')], and then injecting the configured provider via constructor(@Inject('/path').
I like the idea of creating a top level API. This will improve the discoverability using TypeScript's code completion.
As authentication goes, I'm most concerned with making sure you can inject the currently authenticated user into the component.
@Component({
template: `
<h1>Welcome, {{ user.github.username }}</h1>
`
})
class Login {
constructor(private af:AngularFire, private user: FirebaseUser) {
}
}
With the user injected you can depend on it's existence. That means no if checks, and simplifying your component.
However, that work will likely come with the router integration. Otherwise I'm down with this interface.
An additional design goal: have a pipe equivalent of each API, without having to inject the service into the component. I.e. <li *ngFor="#question in '/questions' | afList | async">
What is a FirebaseListFactory? An Observable?
@blesh it returns an observable
An observable of an array for the given path.
FirstbaseListObservableFactory then? Because FirebaseListFactory just makes me think it's giving me an Array or some sort of static collection.
How to get FirebaseUser?
As the current version does Angularfire 2 setup to be a singleton? That way only one instance is initiated? If not should it be?
Thanks.