Skip to content

Commit

Permalink
fix(list): FirebaseListObservable shape (#321)
Browse files Browse the repository at this point in the history
* fix(list): FirebaseListObservable shape

* fix(typings)

* chore(typings): Update typings

* chore(reporter): Add Mocha report for Travis

* chore(tests): Add tests for shape

* chore(newline): plz

* chore(newline): plz

* fix(iit)
  • Loading branch information
davideast authored Jul 22, 2016
1 parent 9edf33a commit 35e8583
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ before_script:

script:
- npm run build
- ./node_modules/.bin/karma start --single-run --browsers Firefox
- ./node_modules/.bin/karma start --single-run --browsers Firefox --reporters mocha
# Can't run until https://github.com/angular/protractor/issues/2784 is resolved
#- ./node_modules/.bin/protractor protractor.conf.js --browser firefox

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"tsd": "^0.6.5",
"typedoc": "github:jeffbcross/typedoc",
"typescript": "^1.8.10",
"typings": "^0.6.2",
"typings": "^1.3.2",
"zone.js": "^0.6.6"
},
"typings": "dist/angularfire2.d.ts"
Expand Down
21 changes: 20 additions & 1 deletion src/database/firebase_list_factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
} from '../angularfire2';
import {
addProviders,
inject
inject,
iit
} from '@angular/core/testing';
import * as utils from '../utils';
import {Query} from '../interfaces';
Expand Down Expand Up @@ -339,6 +340,24 @@ describe('FirebaseListFactory', () => {

});

describe('shape', () => {

it('should have a a FirebaseListObservable shape when queried', () => {
const observable = FirebaseListFactory(rootFirebase, {
query: {
orderByChild: 'height',
equalTo: '1'
}
});

expect(observable.push instanceof Function).toBe(true);
expect(observable.update instanceof Function).toBe(true);
expect(observable.remove instanceof Function).toBe(true);
});


});

describe('methods', () => {

beforeEach((done: any) => {
Expand Down
11 changes: 7 additions & 4 deletions src/database/firebase_list_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function FirebaseListFactory (
}

const queryObs = observeQuery(query);
const listObs = <FirebaseListObservable<{}>>queryObs
.map(query => {
return new FirebaseListObservable(ref, subscriber => {
let sub = queryObs.map(query => {
let queried: firebase.database.Query = ref;
// Only apply the populated keys
// apply ordering and available querying options
Expand Down Expand Up @@ -93,8 +93,11 @@ export function FirebaseListFactory (
})
.mergeMap((queryRef: firebase.database.Reference, ix: number) => {
return firebaseListObservable(queryRef, { preserveSnapshot });
});
return listObs;
})
.subscribe(subscriber);

return () => sub.unsubscribe();
});
}

function firebaseListObservable(ref: firebase.database.Reference | firebase.database.Query, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"src/auth/auth.ts",
"src/auth/auth.spec.ts",
"src/auth/auth_backend.spec.ts",
"typings/main.d.ts",
"typings/index.d.ts",
"manual_typings/firebase3/firebase3.d.ts"
]
}
12 changes: 6 additions & 6 deletions typings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "angularfire2",
"dependencies": {
"es6-promise": "github:typed-typings/npm-es6-promise#fb04188767acfec1defd054fc8024fafa5cd4de7"
},
"devDependencies": {},
"ambientDependencies": {
"angular-protractor": "github:DefinitelyTyped/DefinitelyTyped/angular-protractor/angular-protractor.d.ts#f9c44651705f574f6d4258fe5e1c335462bdcc19",
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2",
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#64b25f63f0ec821040a5d3e049a976865062ed9d",
"selenium-webdriver": "github:DefinitelyTyped/DefinitelyTyped/selenium-webdriver/selenium-webdriver.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
"globalDependencies": {
"angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
"es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
}
}

0 comments on commit 35e8583

Please sign in to comment.