Rename filter.callback to filter.predicate.

The filter "callback" was only a "callback" in the
most general sense of the word.

It's just a filter predicate that returns a bool.

This is to prepare for another filtering option,
where the caller can filter the whole list
themselves.  I haven't figured out what I will name
the new option yet, but I know I want to make the
two options have specific names.
This commit is contained in:
Steve Howell 2019-12-30 16:44:24 +00:00 committed by Tim Abbott
parent 3f3b9c3b70
commit 110c15737f
11 changed files with 19 additions and 19 deletions

View File

@ -109,7 +109,7 @@ run_test('list_render', () => {
const opts = {
filter: {
element: search_input,
callback: (item, value) => {
predicate: (item, value) => {
return _.contains(item, value);
},
},
@ -223,7 +223,7 @@ run_test('filtering', () => {
const opts = {
filter: {
callback: (item, value) => {
predicate: (item, value) => {
return item.length === value;
},
},
@ -261,7 +261,7 @@ run_test('sorting', () => {
return div(item.name) + div(item.salary);
},
filter: {
callback: () => true,
predicate: () => true,
},
};

View File

@ -68,7 +68,7 @@ function render_attachments_ui() {
},
filter: {
element: $search_input,
callback: function (item, value) {
predicate: function (item, value) {
return item.name.toLocaleLowerCase().indexOf(value) >= 0;
},
onupdate: function () {

View File

@ -10,10 +10,10 @@ exports.filter = (value, list, opts) => {
but we split it out to make it a bit easier
to test.
*/
const callback = opts.filter.callback;
const predicate = opts.filter.predicate;
return list.filter(function (item) {
return callback(item, value);
return predicate(item, value);
});
};
@ -58,8 +58,8 @@ exports.create = function ($container, list, opts) {
return;
}
if (typeof opts.filter.callback !== 'function') {
blueslip.error('Filter callback function is missing.');
if (typeof opts.filter.predicate !== 'function') {
blueslip.error('Filter predicate function is missing.');
return;
}

View File

@ -76,7 +76,7 @@ exports.populate_emoji = function (emoji_data) {
},
filter: {
element: emoji_table.closest(".settings-section").find(".search"),
callback: function (item, value) {
predicate: function (item, value) {
return item.name.toLowerCase().indexOf(value) >= 0;
},
onupdate: function () {

View File

@ -46,7 +46,7 @@ exports.populate_exports_table = function (exports) {
},
filter: {
element: exports_table.closest(".settings-section").find(".search"),
callback: function (item, value) {
predicate: function (item, value) {
return people.get_full_name(item.acting_user_id).toLowerCase().indexOf(value) >= 0;
},
onupdate: function () {

View File

@ -63,7 +63,7 @@ function populate_invites(invites_data) {
},
filter: {
element: invites_table.closest(".settings-section").find(".search"),
callback: function (item, value) {
predicate: function (item, value) {
const referrer_email_matched = item.ref.toLowerCase().indexOf(value) >= 0;
if (item.is_multiuse) {
return referrer_email_matched;

View File

@ -37,7 +37,7 @@ exports.populate_filters = function (filters_data) {
},
filter: {
element: filters_table.closest(".settings-section").find(".search"),
callback: function (item, value) {
predicate: function (item, value) {
return (
item[0].toLowerCase().indexOf(value) >= 0 ||
item[1].toLowerCase().indexOf(value) >= 0

View File

@ -446,7 +446,7 @@ exports.populate_notifications_stream_dropdown = function (stream_list) {
},
filter: {
element: search_input,
callback: function (item, value) {
predicate: function (item, value) {
return item.name.toLowerCase().indexOf(value) >= 0;
},
onupdate: function () {
@ -475,7 +475,7 @@ exports.populate_signup_notifications_stream_dropdown = function (stream_list) {
},
filter: {
element: search_input,
callback: function (item, value) {
predicate: function (item, value) {
return item.name.toLowerCase().indexOf(value) >= 0;
},
},

View File

@ -37,7 +37,7 @@ exports.build_default_stream_table = function (streams_data) {
},
filter: {
element: table.closest(".settings-section").find(".search"),
callback: function (item, value) {
predicate: function (item, value) {
return item.name.toLowerCase().indexOf(value) >= 0;
},
onupdate: function () {

View File

@ -173,7 +173,7 @@ function populate_users(realm_people_data) {
},
filter: {
element: $bots_table.closest(".settings-section").find(".search"),
callback: function (item, value) {
predicate: function (item, value) {
return (
item.full_name.toLowerCase().indexOf(value) >= 0 ||
item.email.toLowerCase().indexOf(value) >= 0
@ -220,7 +220,7 @@ function populate_users(realm_people_data) {
},
filter: {
element: $users_table.closest(".settings-section").find(".search"),
callback: people.matches_user_settings_search,
predicate: people.matches_user_settings_search,
onupdate: reset_scrollbar($users_table),
},
parent_container: $("#admin-user-list").expectOne(),
@ -254,7 +254,7 @@ function populate_users(realm_people_data) {
},
filter: {
element: $deactivated_users_table.closest(".settings-section").find(".search"),
callback: people.matches_user_settings_search,
predicate: people.matches_user_settings_search,
onupdate: reset_scrollbar($deactivated_users_table),
},
parent_container: $("#admin-deactivated-users-list").expectOne(),

View File

@ -181,7 +181,7 @@ function show_subscription_settings(sub_row) {
},
filter: {
element: $("[data-stream-id='" + stream_id + "'] .search"),
callback: function (item, value) {
predicate: function (item, value) {
const person = people.get_by_email(item);
if (person) {