Skip to content

Commit

Permalink
Improve pagination function name and define a constant to control the…
Browse files Browse the repository at this point in the history
… pagination jump
  • Loading branch information
llvieira committed Nov 5, 2017
1 parent d2396b3 commit 9e5bf77
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/listener/base-listener.js
Expand Up @@ -22,6 +22,9 @@ THE SOFTWARE.
const normalizeGroups = /\(:<(\w+)>/g;
const namedGroups = /\(:<(\w+)>|\((?!\?[:!]).*?\)/g;

// paginationJump controls the resources number displayed per message
const paginationJump = 10;

class NamedRegExp extends RegExp {
constructor(rgx) {
super(rgx.source.replace(normalizeGroups, '('), (rgx.global ? 'g' : '') + (rgx.ignoreCase ? 'i' : '') + (rgx.multiline ? 'm' : ''));
Expand Down Expand Up @@ -63,14 +66,14 @@ class Listener {
this.transform.text(msg, text);
}

this.aux_pagination(0, 10, response.members, msg, response);
this.makePagination(paginationJump, response.members, msg, response);
}

aux_pagination(start, jump, members, msg, response) {
if (jump < members.length + 10) {
response.members = members.slice(start, jump);
makePagination(jump, members, msg, response) {
if (jump < members.length + paginationJump) {
response.members = members.slice(jump - paginationJump, jump);
this.transform.send(msg, response);
this.aux_pagination(start + 10, jump + 10, members, msg, response);
this.makePagination(jump + paginationJump, members, msg, response);
}
}

Expand Down

0 comments on commit 9e5bf77

Please sign in to comment.