mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
refactor: Avoid triggers in stream_edit.
We extract stream_edit.rerender to make the live-update code easier to follow. The function should eventually be inlined, but I want to clean up some other stuff first.
This commit is contained in:
@@ -6,7 +6,6 @@ const event_fixtures = events.fixtures;
|
||||
const test_message = events.test_message;
|
||||
const test_user = events.test_user;
|
||||
|
||||
set_global('document', 'document-stub');
|
||||
set_global('$', global.make_zjquery());
|
||||
|
||||
global.patch_builtin('setTimeout', func => func());
|
||||
@@ -646,6 +645,9 @@ with_overrides(function (override) {
|
||||
});
|
||||
});
|
||||
|
||||
const stream_edit_stub = global.make_stub();
|
||||
override('stream_edit.rerender', stream_edit_stub.f);
|
||||
|
||||
const compose_fade_stub = global.make_stub();
|
||||
override('compose_fade.update_faded_users', compose_fade_stub.f);
|
||||
|
||||
@@ -658,6 +660,7 @@ with_overrides(function (override) {
|
||||
assert_same(args.user_id, 555);
|
||||
});
|
||||
assert.equal(compose_fade_stub.num_calls, 1);
|
||||
assert.equal(stream_edit_stub.num_calls, 1);
|
||||
|
||||
event = event_fixtures.subscription__peer_remove;
|
||||
global.with_stub(function (stub) {
|
||||
@@ -668,6 +671,7 @@ with_overrides(function (override) {
|
||||
assert_same(args.user_id, 555);
|
||||
});
|
||||
assert.equal(compose_fade_stub.num_calls, 2);
|
||||
assert.equal(stream_edit_stub.num_calls, 2);
|
||||
|
||||
event = event_fixtures.subscription__remove;
|
||||
let stream_id_looked_up;
|
||||
|
||||
@@ -334,7 +334,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||
return;
|
||||
}
|
||||
|
||||
$(document).trigger('peer_subscribe.zulip', {stream_name: stream_name});
|
||||
stream_edit.rerender(stream_name);
|
||||
}
|
||||
for (const stream_name of event.subscriptions) {
|
||||
add_peer(stream_name, event.user_id);
|
||||
@@ -346,7 +346,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||
blueslip.warn('Cannot process peer_remove event.');
|
||||
return;
|
||||
}
|
||||
$(document).trigger('peer_unsubscribe.zulip', {stream_name: stream_name});
|
||||
stream_edit.rerender(stream_name);
|
||||
}
|
||||
for (const stream_name of event.subscriptions) {
|
||||
remove_peer(stream_name, event.user_id);
|
||||
|
||||
@@ -36,6 +36,15 @@ exports.settings_for_sub = function (sub) {
|
||||
return $("#subscription_overlay .subscription_settings[data-stream-id='" + sub.stream_id + "']");
|
||||
};
|
||||
|
||||
exports.rerender = function (stream_name) {
|
||||
// This is a shim--our caller should call
|
||||
// rerender_subscriptions_settings directly,
|
||||
// but we are in the middle of a stream_name -> stream_id
|
||||
// refactoring.
|
||||
const sub = stream_data.get_sub(stream_name);
|
||||
subs.rerender_subscriptions_settings(sub);
|
||||
};
|
||||
|
||||
exports.is_sub_settings_active = function (sub) {
|
||||
// This function return whether the provided given sub object is
|
||||
// currently being viewed/edited in the stream edit UI. This is
|
||||
@@ -678,11 +687,6 @@ exports.initialize = function () {
|
||||
exports.open_edit_panel_for_row(this);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('peer_subscribe.zulip peer_unsubscribe.zulip', function (e, data) {
|
||||
const sub = stream_data.get_sub(data.stream_name);
|
||||
subs.rerender_subscriptions_settings(sub);
|
||||
});
|
||||
};
|
||||
|
||||
window.stream_edit = exports;
|
||||
|
||||
Reference in New Issue
Block a user