From f4fc53fa193f7fe3fc9c1328c0c4d677f754826d Mon Sep 17 00:00:00 2001 From: Edward Shen <6173958+edward-shen@users.noreply.github.com> Date: Mon, 7 May 2018 13:05:52 -0400 Subject: [PATCH] added support for changing by a certain amount of pages --- MMM-pages.js | 13 ++++++++++--- readme.md | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/MMM-pages.js b/MMM-pages.js index 713f6b1..ea9097c 100644 --- a/MMM-pages.js +++ b/MMM-pages.js @@ -55,11 +55,12 @@ Module.register('MMM-pages', { * @param {number} payload the page to change to */ notificationReceived: function(notification, payload) { + const isValidPayload = typeof payload === 'number'; switch (notification) { case 'PAGE_CHANGED': Log.log(`${this.name} recieved a notification` + `to change to page ${payload} of type ${typeof payload}`); - if (typeof payload === 'number') { + if (isValidPayload) { this.curPage = payload; } else { Log.error('Was asked to change to an invalid number!'); @@ -70,12 +71,18 @@ Module.register('MMM-pages', { break; case 'PAGE_INCREMENT': Log.log(`${this.name} recieved a notification to increment pages!`); - this.curPage = this.mod(this.curPage + 1, this.config.modules.length); + this.curPage = this.mod( + this.curPage + (isValidPayload) ? payload : 1, + this.config.modules.length + ); this.updatePages(true); break; case 'PAGE_DECREMENT': Log.log(`${this.name} recieved a notification to decrement pages!`); - this.curPage = this.mod(this.curPage - 1, this.config.modules.length); + this.curPage = this.mod( + this.curPage - (isValidPayload) ? payload : 1, + this.config.modules.length + ); this.updatePages(true); break; case 'DOM_OBJECTS_CREATED': diff --git a/readme.md b/readme.md index 6832b05..cbc11c8 100644 --- a/readme.md +++ b/readme.md @@ -76,9 +76,10 @@ this.sendNotification("PAGE_CHANGED", 2); ``` This would cause the module to change show that you are on page 3. -You can also just send `PAGE_INCREMENT` or `PAGE_DECREMENT` without any payloads - (or with, but it will be ignored) to have the module change the displayed page - by one. +Sending a `PAGE_INCREMENT` or `PAGE_DECREMENT` without any parameters will +increase or decrease the page by one. Attaching a valid payload to the +aforementioned notifications will increase or decrease the pages by that amount. +Remember that this module **strictly checks** for a number. This module keeps internal track of how many pages you have, defined by your config in the config file. There is no way to dynamically change the pages you