Skip to content

chore(providers): shortcut for configuring DEFAULT_FIREBASE provider #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/
dist/
typings/

npm-debug.log
65 changes: 44 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ import {FIREBASE_PROVIDERS} from 'angularfire2';
bootstrap(App, FIREBASE_PROVIDERS);
```

### defaultFirebase

Define the root url for the library, to resolve relative paths.

Type: `string`

Usage:

```
import {bootstrap} from 'angular2/core';
import {FIREBASE_PROVIDERS, defaultFirebase} from 'angularfire2';

bootstrap(App, [
FIREBASE_PROVIDERS,
defaultFirebase('https://my.firebaseio.com')
]);
```

### FirebaseRef

Injectable symbol to create a Firebase reference based on
Expand All @@ -42,27 +60,6 @@ class MyComponent {
}
```

### FirebaseUrl

URL for the app's default Firebase database.

Type: `string`

Usage:

```
import {App} from './app';
import {bootstrap, provide} from 'angular2/core';
import {FirebaseUrl, FIREBASE_PROVIDERS} from 'angularfire2';

bootstrap(App, [
FIREBASE_PROVIDERS,
provide(FirebaseUrl, {
useValue: 'https://my.firebaseio.com'
})
]);
```

### FirebaseList

A convenient provider to inject a remote list of
Expand Down Expand Up @@ -106,6 +103,32 @@ class QuestionsList {
}
```

### FirebaseUrl

URL for the app's default Firebase database.

Type: `string`

Usage:

```
import {bootstrap, Inject} from 'angular2/core';
import {FirebaseUrl, FIREBASE_PROVIDERS, defaultFirebase} from 'angularfire2';

@Component({
selector: 'app',
template: `<a [href]="url">{{ url }}</a>`
})
class App {
constructor(@Inject(FirebaseUrl) public url: string) {}
}

bootstrap(App, [
FIREBASE_PROVIDERS,
defaultFirebase('https://my.firebaseio.com')
]);
```

### FirebaseListConfig

Interface for config object that can be provided to `FirebaseList`
Expand Down
23 changes: 19 additions & 4 deletions src/angularfire.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import {describe,it,beforeEach} from 'angular2/testing';
import {Injector, provide} from 'angular2/core';
import {FIREBASE_PROVIDERS, FirebaseUrl, FirebaseRef} from './angularfire';
import {describe,it,beforeEach, expect, inject} from 'angular2/testing';
import {Injector, provide, Provider} from 'angular2/core';
import {FIREBASE_PROVIDERS, FirebaseUrl, FirebaseRef, defaultFirebase} from './angularfire';

const testUrl = 'https://ng2-forum-demo.firebaseio.com/';

describe('angularfire', () => {
describe('FIREBASE_REF', () => {
it('should provide a FirebaseRef for the FIREBASE_REF binding', () => {
var injector = Injector.resolveAndCreate([
provide(FirebaseUrl, {
useValue: 'https://ng2-forum-demo.firebaseio.com'
useValue: testUrl
}),
FIREBASE_PROVIDERS
]);
expect(typeof injector.get(FirebaseRef).on).toBe('function');
})
});

describe('defaultFirebase', () => {
it('should create a provider', () => {
const provider = defaultFirebase(testUrl);
expect(provider).toBeAnInstanceOf(Provider);
});

it('should inject a FIR reference', () => {
const injector = Injector.resolveAndCreate([defaultFirebase(testUrl), FIREBASE_PROVIDERS]);
expect(injector.get(FirebaseRef).toString()).toBe(testUrl);
});
});

});
8 changes: 7 additions & 1 deletion src/angularfire.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {OpaqueToken, provide} from 'angular2/core';
import {OpaqueToken, provide, Provider} from 'angular2/core';
import * as Firebase from 'firebase';

export const FirebaseUrl = new OpaqueToken('FirebaseUrl');
Expand All @@ -10,6 +10,12 @@ export const FIREBASE_PROVIDERS:any[] = [
deps: [FirebaseUrl]})
];

export const defaultFirebase = (url: string):Provider => {
return provide(FirebaseUrl, {
useValue: url
});
};

export {FirebaseList, FirebaseListConfig} from './providers/firebase_list';
export {FirebaseObservable} from './utils/firebase_observable';

Expand Down