Skip to content

Commit

Permalink
fix(utils): Make object $key and $exists properties non-enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
byrondover authored and davideast committed Jan 23, 2017
1 parent 404aa3d commit 253401f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/database/firebase_object_factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ describe('FirebaseObjectFactory', () => {


it('should emit unwrapped data by default', (done: any) => {
ref.set({ data: 'bar' }, () => {
const fixtureData = { data: 'bar' };
ref.set(fixtureData, () => {
subscription = observable.subscribe(unwrapped => {
if (!unwrapped) return;
const expectedObject = { $key: ref.key, data: 'bar' };
expect(unwrapped.$key).toEqual(expectedObject.$key);
expect(unwrapped.data).toEqual(expectedObject.data);
expect(unwrapped.$key).toEqual(ref.key);
expect(unwrapped).toEqual(fixtureData);
expect(unwrapped.$exists()).toEqual(true);
done();
});
Expand Down
2 changes: 1 addition & 1 deletion src/database/firebase_object_observable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('FirebaseObjectObservable', () => {
});
inject([FirebaseApp, AngularFire], (firebaseApp: firebase.app.App, _af: AngularFire) => {
app = firebaseApp;
ref = firebase.database().ref()
ref = firebase.database().ref();
O = new FirebaseObjectObservable((observer:Observer<any>) => {
}, ref);
})();
Expand Down
11 changes: 7 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ export function unwrapMapFn (snapshot:firebase.database.DataSnapshot): AFUnwrapp
$value: unwrapped
};
}
unwrapped.$key = snapshot.ref.key;
unwrapped.$exists = () => {
return snapshot.exists();
};
Object.defineProperty(unwrapped, '$key', {value: snapshot.ref.key, enumerable: false});
Object.defineProperty(unwrapped, '$exists', {
value: () => {
return snapshot.exists();
},
enumerable: false
});
return unwrapped;
}

Expand Down

0 comments on commit 253401f

Please sign in to comment.