|
3 | 3 | AngularFire2 4.0 is a refactor of the AngularFire2 package which implements
|
4 | 4 | @NgModule, simplifies authentication, and better supports Angular 4.
|
5 | 5 |
|
6 |
| -The proposal was introduced by David East in [Release Candidate API proposal |
7 |
| -#854](https://github.com/angular/angularfire2/issues/854). |
8 |
| - |
9 | 6 | ### Removing `AngularFire` for Modularity
|
10 | 7 |
|
11 |
| -AngularFire2 does not take advantage of the Firebase SDK's modularity. Users who only need authentication receive database code and vice versa. The `AngularFire` service is a central part of this problem. The class includes each feature whether you are using it or not. Even worse, this cannot be tree-shaken. As the library grows to include more features, this will only become more of a problem. |
12 |
| - |
13 |
| -The way to fix this is to remove the `AngularFire` service and break up the library into smaller @NgModules. |
| 8 | +Prior to 4.0, AngularFire2 not take advantage of the Firebase SDK's modularity for tree shaking. The way we fixed this is to remove the `AngularFire` service and break up the library into smaller @NgModules: |
14 | 9 |
|
15 | 10 | * `AngularFireModule`
|
16 | 11 | * `AngularFireDatabaseModule`
|
17 | 12 | * `AngularFireAuthModule`
|
18 | 13 |
|
| 14 | +Rather than inject `AngularFire` you should now inject each module independently: |
| 15 | + |
| 16 | +``` |
| 17 | +import { AngularFireDatabase } from 'angularfire2/database'; |
| 18 | +
|
| 19 | +... |
| 20 | +
|
| 21 | +constructor(db: AngularFireDatabase) { |
| 22 | + db.list('foo'); |
| 23 | +} |
| 24 | +``` |
| 25 | + |
19 | 26 | ### Simplified Authentication API
|
20 | 27 |
|
21 |
| -The goal of AngularFire is not to wrap the Firebase SDK. **The goal is to provide Angular-specific functionality.** |
| 28 | +In 4.0 we've further cut the complexity of the package by auth module down to an obverser for state changes to simplify the package. |
22 | 29 |
|
23 |
| -To this effect, we've cut the auth module down to an obverser for state changes. |
| 30 | +``` |
| 31 | +import { AngularFireAuth } from 'angularfire2/auth'; |
24 | 32 |
|
25 |
| -Most of the custom authentication methods were simply wrapper calls around the official SDK. Rather than creating more bytes for no value, the Firebase Auth instance is available as a property named `auth` where the same functionality exists. |
| 33 | +... |
| 34 | +
|
| 35 | +user: Observable<firebase.User>; |
| 36 | +constructor(afAuth: AngularFireAuth) { |
| 37 | + this.user = afAuth.authState; |
| 38 | +} |
| 39 | +``` |
26 | 40 |
|
27 | 41 | ### Removing pre-configured login
|
28 | 42 |
|
29 |
| -While convenient, the pre-configure login feature added unneeded complexity into our codebase. You can now trigger login as expected with the Firebase SDK. |
| 43 | +While convenient, the pre-configure login feature added unneeded complexity into our codebase. |
30 | 44 |
|
31 |
| -### FirebaseListFactory and FirebaseObjectFactory API Changes |
| 45 | +In 4.0 you can now trigger login using the Firebase SDK: |
32 | 46 |
|
33 |
| -This change only affects a few users who directly use `FirebaseListFactory`. Most people inject `AngularFireDatabase` directly or use the `AngularFire` service. |
| 47 | +``` |
| 48 | +login() { |
| 49 | + this.afAuth.auth.signInWithPopup(new GoogleAuthProvider()); |
| 50 | +} |
| 51 | +logout() { |
| 52 | + this.afAuth.auth.signOut(); |
| 53 | +} |
| 54 | +``` |
34 | 55 |
|
35 |
| -If you directly use `FirebaseListFactory` you will no longer be able to pass in a string. **The `AngularFireDatabase` module will still take paths for .list() and .object().** With the `FirebaseApp` now easily injectable, you can create a reference while still adhering to DI. |
| 56 | +### FirebaseListFactory and FirebaseObjectFactory API Changes |
36 | 57 |
|
37 |
| -This is a minor change, but again it prioritizes simplicity. It keeps the library from writing check logic at multiple abstractions. This again reduces complexity and maintenance. |
| 58 | +If you directly use `FirebaseListFactory` or `FirebaseObjectFactory` you will no longer be able to pass in a string, it will instead expect a Firebase database reference. |
38 | 59 |
|
39 | 60 | ## Putting this all together
|
40 | 61 |
|
|
0 commit comments