Skip to content

Commit 521e26a

Browse files
jsayolJosep Sayol josep.sayol@gmail.com
authored and
Josep Sayol josep.sayol@gmail.com
committed
WIP: fix error when checking EventRegistration callbacks
1 parent 1d228fa commit 521e26a

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/database/core/view/EventRegistration.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DataSnapshot } from '../../api/DataSnapshot';
22
import { DataEvent, CancelEvent, Event } from './Event';
3-
import { contains, getCount, getAnyKey } from '../../../utils/obj';
3+
import { contains, getCount, getAnyKey, every } from '../../../utils/obj';
44
import { assert } from '../../../utils/assert';
55
import { Path } from '../util/Path';
66
import { Change } from './Change';
@@ -241,9 +241,7 @@ export class ChildEventRegistration implements EventRegistration {
241241
);
242242
} else {
243243
// Exact match on each key.
244-
return this.callbacks_.every(<any>function (cb, eventType) {
245-
return other.callbacks_[eventType] === cb;
246-
});
244+
return every(this.callbacks_, (eventType, cb) => other.callbacks_[eventType] === cb);
247245
}
248246
}
249247
}

src/utils/obj.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,23 @@ export const getValues = function(obj) {
110110
res[i++] = obj[key];
111111
}
112112
return res;
113-
};
113+
};
114+
115+
/**
116+
* Tests whether every key/value pair in an object pass the test implemented
117+
* by the provided function
118+
*
119+
* @param {?Object.<K,V>} obj Object to test.
120+
* @param {!function(K, V)} fn Function to call for each key and value.
121+
* @template K,V
122+
*/
123+
export const every = function<V>(obj: Object, fn: (k: string, v?: V) => boolean): boolean {
124+
for (let key in obj) {
125+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
126+
if (!fn(key, obj[key])) {
127+
return false;
128+
}
129+
}
130+
}
131+
return true;
132+
};

0 commit comments

Comments
 (0)