Skip to content

Commit 6678e05

Browse files
jamesdanielsdavideast
authored andcommitted
Adding more examples
1 parent 77ca293 commit 6678e05

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

docs/version-4-upgrade.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,59 @@
33
AngularFire2 4.0 is a refactor of the AngularFire2 package which implements
44
@NgModule, simplifies authentication, and better supports Angular 4.
55

6-
The proposal was introduced by David East in [Release Candidate API proposal
7-
#854](https://github.com/angular/angularfire2/issues/854).
8-
96
### Removing `AngularFire` for Modularity
107

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:
149

1510
* `AngularFireModule`
1611
* `AngularFireDatabaseModule`
1712
* `AngularFireAuthModule`
1813

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+
1926
### Simplified Authentication API
2027

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.
2229

23-
To this effect, we've cut the auth module down to an obverser for state changes.
30+
```
31+
import { AngularFireAuth } from 'angularfire2/auth';
2432
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+
```
2640

2741
### Removing pre-configured login
2842

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.
3044

31-
### FirebaseListFactory and FirebaseObjectFactory API Changes
45+
In 4.0 you can now trigger login using the Firebase SDK:
3246

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+
```
3455

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
3657

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.
3859

3960
## Putting this all together
4061

0 commit comments

Comments
 (0)