Files
zulip/static/js/sub_store.js
Steve Howell d2bbb7d521 refactor: Extract sub_store module.
This is a prep commit to break dependencies.

The sub_store module is a thin layer on top of
our map of stream_id -> sub.
2021-04-15 17:26:17 -07:00

41 lines
936 B
JavaScript

import * as blueslip from "./blueslip";
const subs_by_stream_id = new Map();
export function get(stream_id) {
return subs_by_stream_id.get(stream_id);
}
export function validate_stream_ids(stream_ids) {
const good_ids = [];
const bad_ids = [];
for (const stream_id of stream_ids) {
if (subs_by_stream_id.has(stream_id)) {
good_ids.push(stream_id);
} else {
bad_ids.push(stream_id);
}
}
if (bad_ids.length > 0) {
blueslip.warn(`We have untracked stream_ids: ${bad_ids}`);
}
return good_ids;
}
export function clear() {
subs_by_stream_id.clear();
}
export function delete_sub(stream_id) {
subs_by_stream_id.delete(stream_id);
}
export function add_hydrated_sub(stream_id, sub) {
// The only code that should call this directly is
// in stream_data.js. Grep there to find callers.
subs_by_stream_id.set(stream_id, sub);
}