Skip to content

Commit 1fc1c9e

Browse files
jamesdanielsdavideast
authored andcommitted
docs(afs): AngularFire docs and more (angular#2)
* docs(db): updating the querying docs for the new API (angular#1170) * docs(db): updating the querying docs for the new API * docs(db): cleanup some of the formatting * docs(db): kill unneeded quote character * docs(db): adding a clear filter + show all results first * docs(db): allow null in the filterBy example * docs(readme): Callout 5.0 docs * docs(): Update Auth-with-Ionic3-Augular4.md (angular#1171) Fix promise-polyfill instruction and make tutorial less verbose * Rearranging the docs a bit * Fixes * Moved Ionic CLI * AngularFireDatabase/store headers * Rearrange docs and lists * Split querying collections into its own doc * Databases as h4 and getting started with auth * Right auth link * Add a choose a database header * Reformatting that a bit more * Rarranged those, change header numbers * Fixing syntax and app-root issues * Cleaner * Drop the 5.0@next note and 2 from more AF2 refs * Removing the meta section from RTDB * Querying example and doc titles * Revamp firestore dynamic querying * Adding an offline data doc * Small language / typos * Type
1 parent 14d9dfd commit 1fc1c9e

17 files changed

+377
-241
lines changed

Diff for: CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Contributing to AngularFire2
1+
# Contributing to AngularFire
22

3-
We would love for you to contribute to AngularFire2 and help make it even better than it is
3+
We would love for you to contribute to AngularFire and help make it even better than it is
44
today! As a contributor, here are the guidelines we would like you to follow:
55

66
- [Code of Conduct](#coc)
@@ -50,7 +50,7 @@ and help you to craft the change so that it is successfully accepted into the pr
5050

5151
## <a name="setup"></a> Initial Setup
5252

53-
1) Create a fork of AngularFire2 (See [Forking a Project][github-fork])
53+
1) Create a fork of AngularFire (See [Forking a Project][github-fork])
5454

5555
2) CD into your clone and install dependencies
5656

Diff for: README.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { AngularFirestore } from 'angularfire2/firestore';
3636
import { Observable } from 'rxjs/Observable';
3737

3838
@Component({
39-
selector: 'project-name-app',
39+
selector: 'app-root',
4040
template: `
4141
<ul>
4242
<li *ngFor="let item of items | async">
@@ -56,23 +56,40 @@ export class MyApp {
5656
## Developer Guide
5757

5858
### Getting started
59+
5960
- [Installation & Setup](docs/1-install-and-setup.md)
6061

61-
### AngularFirestore
62-
- [Using collections](docs/firestore/collections.md)
63-
- [Using documents](docs/firestore/documents.md)
62+
### Interacting with your database(s)
63+
64+
Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing. [Learn about the differences between them in the Firebase Documentation](https://firebase.google.com/docs/firestore/rtdb-vs-firestore).
65+
66+
#### Cloud Firestore
67+
68+
> `AngularFirestore` allows you to work with Cloud Firestore, the new flagship database for mobile app development. It improves on the successes of Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales better than Realtime Database.
69+
70+
- [Documents](docs/firestore/documents.md)
71+
- [Collections](docs/firestore/collections.md)
72+
- [Querying Collections](docs/firestore/querying-collections.md)
73+
- [Offline data](docs/firestore/offline-data.md)
6474

65-
### AngularFireAuth
66-
- [User Authentication](docs/5-user-authentication.md)
75+
#### Realtime Database
6776

68-
### AngularFireDatabase
69-
- [Retrieving data as objects](docs/2-retrieving-data-as-objects.md)
70-
- [Retrieving data as lists](docs/3-retrieving-data-as-lists.md)
71-
- [Querying lists](docs/4-querying-lists.md)
77+
> `AngularFireDatabase` allows you to work with the Realtime Database, Firebase's original database. It's an efficient, low-latency solution for mobile apps that require synced states across clients in realtime.
78+
79+
- [Objects](docs/rtdb/objects.md)
80+
- [Lists](docs/rtdb/lists.md)
81+
- [Querying lists](docs/rtdb/querying-lists.md)
82+
83+
### Authenticate users
84+
85+
- [Getting started with Firebase Authentication](docs/auth/getting-started.md)
7286

7387
### Deploy to Firebase Hosting
74-
- [Deploying AngularFire to Firebase Hosting](docs/7-deploying-angularfire-to-firebase.md)
88+
89+
- [Deploying AngularFire to Firebase Hosting](docs/deploying-angularfire-to-firebase.md)
7590

7691
### Ionic
77-
- [Using AngularFire with Ionic 2](docs/Auth-with-Ionic2.md)
78-
- [Using AngularFire with Ionic 3 and Angular 4](docs/Auth-with-Ionic3-Angular4.md)
92+
93+
- [Installation and Setup with Ionic CLI](docs/ionic/cli.md)
94+
- [Using AngularFire with Ionic 2](docs/ionic/v2.md)
95+
- [Using AngularFire with Ionic 3](docs/ionic/v3.md)

Diff for: docs/5-user-authentication.md renamed to docs/auth/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 5. User authentication
1+
# 5. Getting started with Firebase Authentication
22

33
`AngularFireAuth.authState` provides you an `Observable<firebase.User>` to monitor your application's authentication State.
44

Diff for: docs/7-deploying-angularfire-to-firebase.md renamed to docs/deploying-angularfire-to-firebase.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 7. Deploy AngularFire2 to Firebase
1+
# 7. Deploy AngularFire to Firebase
22

33
### 0. Build your Angular project for prod
44

Diff for: docs/firestore/collections.md

+17-85
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
# Using Collections with AngularFirestore
1+
# 3. Collections in AngularFirestore
22

3-
## Understanding Collections
4-
Every Firestore application starts with a collection. Firestore is structured in a `Collection > Document > Collection > Document` manner. This provides you with a flexible data structure. When you query a collection you only pull back the documents and not their collections. This is different from the Firebase Realtime Database where a query at a top-level location pulls back the entire tree. No more worrying about pulling back all the way down the tree 😎.
3+
> Cloud Firestore is a NoSQL, document-oriented database. Unlike a SQL database, there are no tables or rows. Instead, you store data in *documents*, which are organized into *collections*.
4+
Each *document* contains a set of key-value pairs. Cloud Firestore is optimized for storing large collections of small documents.
55

6-
## Using an AngularFirestoreCollection
6+
## Using `AngularFirestoreCollection`
77

8-
The `AngularFirestoreCollection` service is a wrapper around the native Firestore SDK's `CollectionReference` and `Query` types. It is a generic service that provides you with a strongly typed set of methods for manipulating and streaming data. This service is designed for use as an `@Injectable()`.
8+
The `AngularFirestoreCollection` service is a wrapper around the native Firestore SDK's [`CollectionReference`](https://firebase.google.com/docs/reference/js/firebase.firestore.CollectionReference) and [`Query`](https://firebase.google.com/docs/reference/js/firebase.firestore.Query) types. It is a generic service that provides you with a strongly typed set of methods for manipulating and streaming data. This service is designed for use as an `@Injectable()`.
99

1010
```ts
1111
import { Component } from '@angular/core';
1212
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
1313
import { Observable } from 'rxjs/Observable';
1414

1515
@Component({
16-
selector: 'afs-app',
16+
selector: 'app-root',
1717
template: `
1818
<ul>
19-
<li *ngFor="item of items | async">
19+
<li *ngFor="let item of items | async">
2020
{{ item.name }}
2121
</li>
2222
</ul>
2323
`
2424
})
2525
export class AppComponent {
26-
private itemsCollection: AngularFirestoreCollection<Item>:
26+
private itemsCollection: AngularFirestoreCollection<Item>;
2727
items: Observable<Item[]>;
28-
constructor(private afs: AngularFirestore): {
28+
constructor(private afs: AngularFirestore) {
2929
this.itemsCollection = afs.collection<Item>('items');
30-
this.items = this.itemsCollection.snapshotChanges(['added', 'removed']);
30+
this.items = this.itemsCollection.valueChanges();
3131
}
3232
addItem(item: Item) {
3333
this.itemsCollection.add(item);
@@ -118,93 +118,25 @@ import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/fires
118118
import { Observable } from 'rxjs/Observable';
119119

120120
@Component({
121-
selector: 'afs-app',
121+
selector: 'app-root',
122122
template: `
123123
<ul>
124-
<li *ngFor="item of items | async">
124+
<li *ngFor="let item of items | async">
125125
{{ item.name }}
126126
</li>
127127
</ul>
128128
`
129129
})
130130
export class AppComponent {
131-
private itemsCollection: AngularFirestoreCollection<Item>:
131+
private itemsCollection: AngularFirestoreCollection<Item>;
132132
items: Observable<Item[]>;
133-
constructor(private afs: AngularFirestore): {
133+
constructor(private afs: AngularFirestore) {
134134
this.itemsCollection = afs.collection<Item>('items');
135-
this.items = this.itemsCollection.snapshotChanges(['added', 'removed']);
135+
this.items = this.itemsCollection.valueChanges();
136136
}
137137
}
138138
```
139139

140-
### Querying
141-
142-
Firestore has powerful querying syntax and the `AngularFirestoreCollection` provides a thin wrapper around it. This keeps you from having to learn two query syntax systems. If you know the Firestore query API then you know it for AngularFirestore ‼
143-
144-
When creating an `AngularFirestoreCollection`, use the optional callback to create a queried reference.
145-
146-
#### Basic Sample
147-
```ts
148-
constructor(private afs: AngularFirestore): {
149-
this.itemsCollection = afs.collection<Item>('items', ref => ref.where('size', '==', 'large'));
150-
this.items = this.itemsCollection.snapshotChanges();
151-
}
152-
```
153-
154-
#### Component Sample
155-
```ts
156-
import { Component } from '@angular/core';
157-
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
158-
import { Observable } from 'rxjs/Observable';
159-
160-
@Component({
161-
selector: 'afs-app',
162-
template: `
163-
<ul>
164-
<li *ngFor="item of items | async">
165-
{{ item.name }}
166-
</li>
167-
</ul>
168-
`
169-
})
170-
export class AppComponent {
171-
private itemsCollection: AngularFirestoreCollection<Item>:
172-
items: Observable<Item[]>;
173-
constructor(private afs: AngularFirestore): {
174-
this.itemsCollection = afs.collection<Item>('items', ref => {
175-
return ref.where('size', '==', 'large').where('price', '>', 10);
176-
});
177-
this.items = this.itemsCollection.snapshotChanges(['added', 'removed']);
178-
}
179-
}
180-
```
181-
182-
### Dynamic querying
183-
184-
Imagine you're querying a list of T-Shirts. Every facet of the query should be parameterized. Sometimes the user will search small sizes, prices less than $20, or by a specific brand. AngularFirestore intergrates with RxJS to make this easy.
185-
186-
#### Basic Sample
187-
```ts
188-
constructor(private afs: AngularFirestore): {
189-
// import { of } from 'rxjs/observable/of;
190-
// You'll use an Observable source from a ReactiveForm control or even
191-
// an AngularFirestoreDocument
192-
const criteria$ = of({
193-
size: 'large',
194-
price: 10
195-
});
196-
this.items = criteria$.switchMap(criteria => {
197-
return this.afs
198-
.collection<Item>('tshirts', ref => {
199-
return ref
200-
.where('size', '==', criteria.size)
201-
.where('price', '>', criteria.price)
202-
})
203-
.snapshotChanges();
204-
});
205-
}
206-
```
207-
208140
## Adding documents to a collection
209141

210142
To add a new document to a collection with a generated id use the `add()` method. This method uses the type provided by the generic class to validate it's type structure.
@@ -219,6 +151,6 @@ To add a new document to a collection with a generated id use the `add()` method
219151

220152
## Manipulating individual documents
221153

222-
To retrieve, update, or delete an individual document you can use the `doc()` method. This method returns an `AngularFirestoreDocument`, which provides methods for streaming, updating, and deleting.
154+
To retrieve, update, or delete an individual document you can use the `doc()` method. This method returns an `AngularFirestoreDocument`, which provides methods for streaming, updating, and deleting. [See Using Documents with AngularFirestore for more information on how to use documents](documents.md).
223155

224-
See the [Documents page for complete documentation]((docs/firestore/documents.md).
156+
### [Next Step: Querying Collections in AngularFirestore](querying-collections.md)

Diff for: docs/firestore/documents.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
# Using Documents with Firestore
1+
# 2. Documents in AngularFirestore
22

3-
## Understanding Documents
3+
> Cloud Firestore is a NoSQL, document-oriented database. Unlike a SQL database, there are no tables or rows. Instead, you store data in *documents*, which are organized into *collections*.
4+
Each *document* contains a set of key-value pairs. Cloud Firestore is optimized for storing large collections of small documents.
45

5-
A Document is apart of a Collection. Firestore follows a `Collection > Document > Collection > Document` structure. Collections nested under a Document are not retrieved with a Document. You must explicitly retrieve the Collection underneath that path. This gives you a much more flexible structure. Gone are the days of worrying about pulling back the whole tree.
6+
## Using `AngularFirestoreDocument`
67

7-
## Using an AngularFirestoreDocument
8-
9-
The `AngularFirestoreDocument` service is a wrapper around the native Firestore SDK's `DocumentReference` type. It is a generic service that provides you with a strongly typed set of methods for manipulating and streaming data. This service is designed for use as an `@Injectable()`.
8+
The `AngularFirestoreDocument` service is a wrapper around the native Firestore SDK's [`DocumentReference` type](https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference). It is a generic service that provides you with a strongly typed set of methods for manipulating and streaming data. This service is designed for use as an `@Injectable()`.
109

1110
```ts
1211
import { Component } from '@angular/core';
1312
import { AngularFirestore, AngularFirestoreDocument } from 'angularfire2/firestore';
1413
import { Observable } from 'rxjs/Observable';
1514

1615
@Component({
17-
selector: 'afs-app',
16+
selector: 'app-root',
1817
template: `
1918
<div>
2019
{{ (item | async)?.name }}
2120
</div>
2221
`
2322
})
2423
export class AppComponent {
25-
private itemDoc: AngularFirestoreDocument<Item>:
24+
private itemDoc: AngularFirestoreDocument<Item>;
2625
item: Observable<Item>;
27-
constructor(private afs: AngularFirestore): {
26+
constructor(private afs: AngularFirestore) {
2827
this.itemDoc = afs.doc<Item>('items/1');
2928
this.item = this.itemDoc.valueChanges();
3029
}
@@ -101,10 +100,10 @@ Nesting collections is a great way to structure your data. This allows you to gr
101100
To retrieve a nested collection use the `collection(path: string)` method.
102101

103102
```ts
104-
constructor(private afs: AngularFirestore): {
103+
constructor(private afs: AngularFirestore) {
105104
this.userDoc = afs.doc<Item>('user/david');
106105
this.tasks = this.userDoc.collection<Task>('tasks').valueChanges();
107106
}
108107
```
109108

110-
For more information about using collections read the [collection documentation](docs/firestore/collection.md).
109+
### [Next Step: Collections in AngularFirestore](collections.md)

Diff for: docs/firestore/ngrx.md

Whitespace-only changes.

Diff for: docs/firestore/offline-data.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Offline Data in Firestore
2+
3+
> Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the data stored remotely in Cloud Firestore.
4+
5+
**Offline persistence is an experimental feature that is supported only by the Chrome, Safari, and Firefox web browsers.** If a user opens multiple browser tabs that point to the same Cloud Firestore database, and offline persistence is enabled, Cloud Firestore will work correctly only in the first tab.
6+
7+
## Enable Offline Data in AngularFirestore
8+
9+
To enable offline persistence in your AngularFire application, call `enablePersistence()` when you are importing `AngularFirestoreModule` into your `@NgModule`:
10+
11+
```ts
12+
import { BrowserModule } from '@angular/platform-browser';
13+
import { NgModule } from '@angular/core';
14+
import { AppComponent } from './app.component';
15+
import { AngularFireModule } from 'angularfire2';
16+
import { AngularFirestoreModule } from 'angularfire2/firestore';
17+
import { AngularFireAuthModule } from 'angularfire2/auth';
18+
import { environment } from '../environments/environment';
19+
20+
@NgModule({
21+
imports: [
22+
BrowserModule,
23+
AngularFireModule.initializeApp(environment.firebase),
24+
AngularFirestoreModule.enablePersistence(),
25+
],
26+
declarations: [ AppComponent ],
27+
bootstrap: [ AppComponent ]
28+
})
29+
export class AppModule {}
30+
31+
```
32+
33+
While offline your listeners will receive listen events when the locally cached data changes. You can use to Documents and Collections normally.
34+
35+
To check whether you're receiving data from the server or the cache, use the `fromCache` property on the `SnapshotMetadata` in your snapshot event. If `fromCache` is true, the data came from the cache and might be stale or incomplete. If `fromCache` is false, the data is complete and current with the latest updates on the server.
36+
37+
[To learn more about Offline Persistence in Firestore, check out the Firebase documentation](https://firebase.google.com/docs/firestore/enable-offline).

0 commit comments

Comments
 (0)