Skip to content

Commit 14d9dfd

Browse files
committed
chore(merge): merge AngularFirestore with master
2 parents f77d9fe + f277779 commit 14d9dfd

File tree

85 files changed

+6994
-1225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+6994
-1225
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ npm-debug.log
99
angularfire2-*.tgz
1010
*.ngfactory.ts
1111
*.ngsummary.json
12-
firestore-module.tgz
1312
.DS_Store
1413
yarn-error.log
14+
*.bak
15+
.DS_Store

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ language: node_js
22
sudo: false
33
node_js:
44
- 'node'
5-
dist: precise
65

76
addons:
8-
firefox: latest
7+
chrome: stable
98
apt:
109
sources:
1110
- ubuntu-toolchain-r-test
@@ -27,7 +26,7 @@ before_script:
2726

2827
script:
2928
- npm run build
30-
- ./node_modules/.bin/karma start --single-run --browsers Firefox --reporters mocha
29+
- ./node_modules/.bin/karma start --single-run --browsers Chrome --reporters mocha
3130
# Run integration test to make sure our typings are correct for user-land.
3231
- node tools/run-typings-test.js
3332

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Status: Release candidate
1010
## What is AngularFire?
1111

1212
- **Observable based** - Use the power of RxJS, Angular, and Firebase.
13-
- **Realtime bindings** - Synchronize data in reatime.
13+
- **Realtime bindings** - Synchronize data in realtime.
1414
- **Authentication** - Log users in with a variety of providers and monitor authentication state in realtime.
1515
- **Offline Data** - Store data offline automatically with AngularFirestore.
1616
- **ngrx friendly** - Integrate with ngrx using AngularFire's action based APIs.
@@ -20,7 +20,7 @@ Status: Release candidate
2020

2121
[Stackblitz Template](https://stackblitz.com/edit/angular-2ed5zx?) - Remember to set your Firebase configuration in `app/app.module.ts`.
2222

23-
[Upgrading to v4.0? Check out our guide.](docs/version-4-upgrade.md)
23+
[Upgrading to v5.0? Check out our guide.](docs/version-5-upgrade.md)
2424

2525
## Install
2626

@@ -70,9 +70,9 @@ export class MyApp {
7070
- [Retrieving data as lists](docs/3-retrieving-data-as-lists.md)
7171
- [Querying lists](docs/4-querying-lists.md)
7272

73+
### Deploy to Firebase Hosting
74+
- [Deploying AngularFire to Firebase Hosting](docs/7-deploying-angularfire-to-firebase.md)
75+
7376
### Ionic
7477
- [Using AngularFire with Ionic 2](docs/Auth-with-Ionic2.md)
7578
- [Using AngularFire with Ionic 3 and Angular 4](docs/Auth-with-Ionic3-Angular4.md)
76-
77-
### Deploy to Firebase Hosting
78-
- [Deploying AngularFire to Firebase Hosting](docs/7-deploying-angularfire-to-firebase.md)

docs/1-install-and-setup.md

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
11
# 1. Installation and Setup
22

3-
> Getting started with AngularFire2 is easy with the [Angular CLI](https://github.com/angular/angular-cli). Follow the 10 steps below to get started. Don't worry, we're always working to make this shorter.
4-
53
> Using Ionic and the Ionic CLI? Check out these [specific instructions](6-angularfire-and-ionic-cli.md) for Ionic and their CLI.
64
75
### 0. Prerequisites
86

9-
Before you start installing AngularFire2, make sure you have latest version of angular-cli installed.
10-
To verify run the command `ng -v` and ensure you see `angular-cli: 1.x.x-beta.xx`. The lowest compatible version is `1.x.x-beta.14`.
11-
12-
If not, you may need to do the following:
13-
14-
```bash
15-
# if you have the wrong cli version only
16-
npm uninstall -g angular-cli
17-
npm uninstall -g @angular/cli
18-
npm cache clean
19-
20-
# reinstall clean version
21-
npm install -g @angular/cli@latest
22-
```
23-
24-
You need the Angular CLI, typings, and TypeScript.
7+
AngularFire provides multiple module formats for different types of builds. The guide is based off the Angular CLI. It is possible to do a manual setup with Webpack or a SystemJS build as well.
258

269
```bash
27-
npm install -g @angular/cli@latest
28-
# or install locally
29-
npm install @angular/cli --save-dev
30-
# make sure you have typings installed
31-
npm install -g typings
32-
npm install -g typescript
10+
npm install @angular/cli
3311
```
3412

3513
### 1. Create a new project
@@ -50,13 +28,13 @@ open http://localhost:4200
5028

5129
You should see a message that says *App works!*
5230

53-
### 3. Install AngularFire 2 and Firebase
31+
### 3. Install AngularFire and Firebase
5432

5533
```bash
5634
npm install angularfire2 firebase --save
5735
```
5836

59-
Now that you have a new project setup, install AngularFire2 and Firebase from npm.
37+
Now that you have a new project setup, install AngularFire and Firebase from npm.
6038

6139
### 4. Add Firebase config to environments variable
6240

@@ -79,6 +57,7 @@ export const environment = {
7957
### 5. Setup @NgModule for the AngularFireModule
8058

8159
Open `/src/app/app.module.ts`, inject the Firebase providers, and specify your Firebase configuration.
60+
8261
This can be found in your project at [the Firebase Console](https://console.firebase.google.com):
8362

8463
```ts

docs/2-retrieving-data-as-objects.md

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
# 2. Retrieving data as objects
22

3-
> AngularFire2 synchronizes data as objects using the `FirebaseObjectObservable`.
4-
The `FirebaseObjectObservable` is not created by itself, but through the `AngularFireDatabase` service.
3+
> The `AngularFireObject` is a service for manipulating and streaming object data.
4+
5+
The `AngularFireObject` service is not created by itself, but through the `AngularFireDatabase` service.
6+
57
The guide below demonstrates how to retrieve, save, and remove data as objects.
68

79
## Injecting the AngularFireDatabase service
810

9-
**Make sure you have bootstrapped your application for AngularFire2. See the Installation guide for bootstrap setup.**
11+
**Make sure you have bootstrapped your application for AngularFire. See the Installation guide for bootstrap setup.**
1012

1113
`AngularFireDatabase` is a service which can be injected through the constructor of your Angular component or `@Injectable()` service.
1214

1315
If you've followed the earlier step "Installation and Setup" your `/src/app/app.component.ts` should look like below.
1416

1517
```ts
1618
import { Component } from '@angular/core';
17-
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
19+
import { AngularFireDatabase } from 'angularfire2/database';
20+
import { Observable } from 'rxjs/Observable';
1821

1922
@Component({
2023
selector: 'app-root',
2124
templateUrl: 'app.component.html',
2225
styleUrls: ['app.component.css']
2326
})
2427
export class AppComponent {
25-
items: FirebaseListObservable<any[]>;
28+
items: Observable<any[]>;
2629
constructor(db: AngularFireDatabase) {
27-
this.items = db.list('items');
30+
this.items = db.list('items').valueChanges();
2831
}
2932
}
3033
```
@@ -33,31 +36,20 @@ In this section, we're going to modify the `/src/app/app.component.ts` to retre
3336

3437
## Create an object binding
3538

36-
Data is retrieved through the `AngularFireDatabase` service.
37-
38-
There are two ways to create an object binding:
39-
40-
1. Relative URL
41-
1. Absolute URL
42-
4339
```ts
44-
// relative URL, uses the database url provided in bootstrap
45-
const relative = db.object('/item');
46-
// absolute URL
47-
const absolute = db.object('https://<your-app>.firebaseio.com/item');
40+
const relative = db.object('item').valueChanges();
4841
```
4942

5043
### Retrieve data
5144

5245
To get the object in realtime, create an object binding as a property of your component or service.
53-
Then in your template, you can use the `async` pipe to unwrap the binding.
5446

55-
Replace the `FirebaseListObservable` to `FirebaseObjectObservable` in your `/src/app/app.component.ts` as below.
56-
Also notice the templateUrl changed to inline template below:
47+
Then in your template, you can use the `async` pipe to unwrap the binding.
5748

5849
```ts
5950
import { Component } from '@angular/core';
60-
import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database';
51+
import { AngularFireDatabase } from 'angularfire2/database';
52+
import { Observable } from 'rxjs/Observable';
6153

6254
@Component({
6355
selector: 'app-root',
@@ -68,7 +60,7 @@ import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/data
6860
export class AppComponent {
6961
item: FirebaseObjectObservable<any>;
7062
constructor(db: AngularFireDatabase) {
71-
this.item = db.object('/item');
63+
this.item = db.object('item').valueChanges();
7264
}
7365
}
7466
```
@@ -77,24 +69,23 @@ export class AppComponent {
7769

7870
### API Summary
7971

80-
The table below highlights some of the common methods on the `FirebaseObjectObservable`.
72+
The table below highlights some of the common methods on the `AngularFireObject`.
8173

8274
| method | |
8375
| ---------|--------------------|
84-
| `set(value: any)` | Replaces the current value in the database with the new value specified as the parameter. This is called a **destructive** update, because it deletes everything currently in place and saves the new value. |
85-
| `update(value: Object)` | Updates the current value with in the database with the new value specified as the parameter. This is called a **non-destructive** update, because it only updates the values specified. Note: Only values at the key level are non-destructive. |
76+
| `set(value: T)` | Replaces the current value in the database with the new value specified as the parameter. This is called a **destructive** update, because it deletes everything currently in place and saves the new value. |
77+
| `update(value: T)` | Updates the current value with in the database with the new value specified as the parameter. This is called a **non-destructive** update, because it only updates the values specified. |
8678
| `remove()` | Deletes all data present at that location. Same as calling `set(null)`. |
8779

8880
## Returning promises
8981
Each data operation method in the table above returns a promise. However,
9082
you should rarely need to use the completion promise to indicate success,
9183
because the realtime database keeps the object in sync.
9284

93-
The promise can be useful to chain multiple operations, catching possible errors
94-
from security rules denials, or for debugging.
85+
The promise can be useful to chain multiple operations, catching possible errors from security rules denials, or for debugging.
9586

9687
```ts
97-
const promise = db.object('/item').remove();
88+
const promise = db.object('item').remove();
9889
promise
9990
.then(_ => console.log('success'))
10091
.catch(err => console.log(err, 'You dont have access!'));
@@ -105,17 +96,17 @@ promise
10596
Use the `set()` method for **destructive updates**.
10697

10798
```ts
108-
const itemObservable = db.object('/item');
109-
itemObservable.set({ name: 'new name!'});
99+
const itemRef = db.object('item');
100+
itemRef.set({ name: 'new name!'});
110101
```
111102

112103
### Updating data
113104

114105
Use the `update()` method for **non-destructive updates**.
115106

116107
```ts
117-
const itemObservable = db.object('/item');
118-
itemObservable.update({ age: newAge });
108+
const itemRef = db.object('item');
109+
itemRef.update({ age: newAge });
119110
```
120111

121112
**Only objects are allowed for updates, not primitives**. This is because
@@ -125,15 +116,15 @@ using an update with a primitive is the exact same as doing a `.set()` with a pr
125116
Use the `remove()` method to remove data at the object's location.
126117

127118
```ts
128-
const itemObservable = db.object('/item');
129-
itemObservable.remove();
119+
const itemRef = db.object('item');
120+
itemRef.remove();
130121
```
131122

132123
**Example app**:
133124

134125
```ts
135126
import { Component } from '@angular/core';
136-
import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database';
127+
import { AngularFireDatabase, AngularFireObject } from 'angularfire2/database';
137128

138129
@Component({
139130
selector: 'app-root',
@@ -148,18 +139,20 @@ import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/data
148139
`,
149140
})
150141
export class AppComponent {
142+
itemRef: AngularFireObject<any>;
151143
item: FirebaseObjectObservable<any>;
152144
constructor(db: AngularFireDatabase) {
153-
this.item = db.object('/item');
145+
this.itemRef = db.object('item');
146+
this.item = this.itemRef.valueChanges();
154147
}
155148
save(newName: string) {
156-
this.item.set({ name: newName });
149+
this.itemRef.set({ name: newName });
157150
}
158151
update(newSize: string) {
159-
this.item.update({ size: newSize });
152+
this.itemRef.update({ size: newSize });
160153
}
161154
delete() {
162-
this.item.remove();
155+
this.itemRef.remove();
163156
}
164157
}
165158
```
@@ -177,15 +170,16 @@ Data retrieved from the object binding contains special properties retrieved fro
177170
AngularFire2 unwraps the Firebase DataSnapshot by default, but you can get the data as the original snapshot by specifying the `preserveSnapshot` option.
178171

179172
```ts
180-
this.item = db.object('/item', { preserveSnapshot: true });
181-
this.item.subscribe(snapshot => {
182-
console.log(snapshot.key)
183-
console.log(snapshot.val())
173+
this.itemRef = db.object('item');
174+
this.itemRef.snapshotChanges().subscribe(action => {
175+
console.log(action.type);
176+
console.log(action.snapshot.key)
177+
console.log(action.snapshot.val())
184178
});
185179
```
186180

187181
## Querying?
188182

189-
Because `FirebaseObjectObservable` synchronizes objects from the realtime database, sorting will have no effect for queries that are not also limited by a range. For example, when paginating you would provide a query with a sort and filter. Both the sort operation and the filter operation affect which subset of the data is returned by the query; however, because the resulting object is simply json, the sort order will not be preseved locally. Hence, for operations that require sorting, you are probably looking for a [list](3-retrieving-data-as-lists.md)
183+
Because `AngularFireObject` synchronizes objects from the realtime database, sorting will have no effect for queries that are not also limited by a range. For example, when paginating you would provide a query with a sort and filter. Both the sort operation and the filter operation affect which subset of the data is returned by the query; however, because the resulting object is simply json, the sort order will not be preseved locally. Hence, for operations that require sorting, you are probably looking for a [list](3-retrieving-data-as-lists.md)
190184

191185
### [Next Step: Retrieving data as lists](3-retrieving-data-as-lists.md)

0 commit comments

Comments
 (0)