Skip to content

Commit

Permalink
WIP: fix error when checking EventRegistration callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayol authored and Josep Sayol [email protected] committed Jun 16, 2017
1 parent 1d228fa commit 521e26a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/database/core/view/EventRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataSnapshot } from '../../api/DataSnapshot';
import { DataEvent, CancelEvent, Event } from './Event';
import { contains, getCount, getAnyKey } from '../../../utils/obj';
import { contains, getCount, getAnyKey, every } from '../../../utils/obj';
import { assert } from '../../../utils/assert';
import { Path } from '../util/Path';
import { Change } from './Change';
Expand Down Expand Up @@ -241,9 +241,7 @@ export class ChildEventRegistration implements EventRegistration {
);
} else {
// Exact match on each key.
return this.callbacks_.every(<any>function (cb, eventType) {
return other.callbacks_[eventType] === cb;
});
return every(this.callbacks_, (eventType, cb) => other.callbacks_[eventType] === cb);
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/utils/obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,23 @@ export const getValues = function(obj) {
res[i++] = obj[key];
}
return res;
};
};

/**
* Tests whether every key/value pair in an object pass the test implemented
* by the provided function
*
* @param {?Object.<K,V>} obj Object to test.
* @param {!function(K, V)} fn Function to call for each key and value.
* @template K,V
*/
export const every = function<V>(obj: Object, fn: (k: string, v?: V) => boolean): boolean {
for (let key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
if (!fn(key, obj[key])) {
return false;
}
}
}
return true;
};

0 comments on commit 521e26a

Please sign in to comment.