Fix type errors in LazySet.

I think the only place that was broken is where
we copy users from streams.
This commit is contained in:
Steve Howell 2020-01-14 22:29:54 +00:00 committed by Tim Abbott
parent b65138c83f
commit 29e63c0417
4 changed files with 41 additions and 4 deletions

View File

@ -0,0 +1,23 @@
set_global('blueslip', global.make_zblueslip());
const LazySet = zrequire('lazy_set').LazySet;
/*
We mostly test LazySet indirectly. This code
may be short-lived, anyway, once we change
how we download subscribers in page_params.
*/
run_test('map', () => {
const ls = LazySet([1, 2]);
const triple = (n) => n * 3;
assert.deepEqual(ls.map(triple), [3, 6]);
});
run_test('conversions', () => {
blueslip.set_test_data('error', 'not a number');
const ls = LazySet([1, 2]);
ls.add('3');
assert(ls.has('3'));
});

View File

@ -53,18 +53,30 @@ exports.LazySet = function (vals) {
self.has = function (v) {
make_set();
return self.set.has(v);
const val = self._clean(v);
return self.set.has(val);
};
self.add = function (v) {
make_set();
self.set.add(v);
const val = self._clean(v);
self.set.add(val);
};
self.del = function (v) {
make_set();
self.set.delete(v);
const val = self._clean(v);
self.set.delete(val);
};
self._clean = function (v) {
if (typeof v !== 'number') {
blueslip.error('not a number');
return parseInt(v, 10);
}
return v;
};
return self;
};

View File

@ -288,7 +288,8 @@ exports.show_new_stream_modal = function () {
$('#user-checkboxes label.checkbox').each(function () {
const user_elem = $(this);
const user_id = user_elem.attr('data-user-id');
const str_user_id = user_elem.attr('data-user-id');
const user_id = parseInt(str_user_id, 10);
if (subscriber_ids.has(user_id)) {
user_elem.find('input').prop('checked', checked);

View File

@ -52,6 +52,7 @@ enforce_fully_covered = {
'static/js/keydown_util.js',
'static/js/input_pill.js',
'static/js/int_dict.ts',
'static/js/lazy_set.js',
'static/js/list_cursor.js',
'static/js/markdown.js',
'static/js/message_store.js',