mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
drafts: Avoid callback mechanism.
We had an anonymous callback for drafts that was hard to read. It's much easier to flatten the code, give functions actual names, and stub them as needed in the unit tests.
This commit is contained in:
@@ -319,6 +319,8 @@ run_test('format_drafts', () => {
|
||||
return '<draft table stub>';
|
||||
};
|
||||
|
||||
drafts.setup_page();
|
||||
drafts.open_modal = noop;
|
||||
drafts.set_initial_element = noop;
|
||||
drafts.launch();
|
||||
timerender.render_now = stub_render_now;
|
||||
});
|
||||
|
||||
@@ -200,7 +200,7 @@ function remove_old_drafts() {
|
||||
// Exporting for testing purpose
|
||||
exports.remove_old_drafts = remove_old_drafts;
|
||||
|
||||
exports.setup_page = function (callback) {
|
||||
exports.launch = function () {
|
||||
function format_drafts(data) {
|
||||
var drafts = {};
|
||||
var data_array = [];
|
||||
@@ -291,10 +291,6 @@ exports.setup_page = function (callback) {
|
||||
if ($("#drafts_table .draft-row").length > 0) {
|
||||
$('#drafts_table .no-drafts').hide();
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function setup_event_handlers() {
|
||||
@@ -321,6 +317,8 @@ exports.setup_page = function (callback) {
|
||||
|
||||
remove_old_drafts();
|
||||
populate_and_fill();
|
||||
exports.open_modal();
|
||||
exports.set_initial_element();
|
||||
setup_event_handlers();
|
||||
};
|
||||
|
||||
@@ -448,8 +446,7 @@ exports.drafts_handle_events = function (e, event_key) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.launch = function () {
|
||||
exports.setup_page(function () {
|
||||
exports.open_modal = function () {
|
||||
overlays.open_overlay({
|
||||
name: 'drafts',
|
||||
overlay: $('#draft_overlay'),
|
||||
@@ -457,7 +454,9 @@ exports.launch = function () {
|
||||
hashchange.exit_overlay();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
exports.set_initial_element = function () {
|
||||
var draft_list = drafts.draft_model.get();
|
||||
var draft_id_list = Object.getOwnPropertyNames(draft_list);
|
||||
if (draft_id_list.length > 0) {
|
||||
@@ -467,7 +466,6 @@ exports.launch = function () {
|
||||
activate_element(focus_element);
|
||||
$(".drafts-list")[0].scrollTop = $('.drafts-list')[0].scrollHeight - $('.drafts-list').height();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.initialize = function () {
|
||||
|
||||
Reference in New Issue
Block a user