From 248bd9b5cc5b24496da8458679624ff24d64d7be Mon Sep 17 00:00:00 2001 From: Edward Shen <6173958+edward-shen@users.noreply.github.com> Date: Sat, 21 Oct 2017 01:49:19 -0400 Subject: [PATCH] changed some code to use modulo instead of the stupid thing I was doing before fixed scope --- MMM-pages.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/MMM-pages.js b/MMM-pages.js index f1aef64..e53175e 100644 --- a/MMM-pages.js +++ b/MMM-pages.js @@ -28,12 +28,11 @@ Module.register("MMM-pages", { this.updatePages(true); } else if (notification === "PAGE_INCREMENT") { Log.log(this.name + " recieved a notification to increment pages!"); - if (this.curPage === this.config.modules.length - 1) { - this.curPage = 0; - } else { this.curPage++ } + this.curPage = (this.curPage++) % this.config.modules.length; this.updatePages(true); } else if (notification === "PAGE_DECREMENT") { Log.log(this.name + " recieved a notification to decrement pages!"); + // Javascript doesn't support negative modulo (-1 % 5 != 4) if (this.curPage === 0) { this.curPage = this.config.modules.length - 1; } else { this.curPage-- } @@ -74,9 +73,7 @@ Module.register("MMM-pages", { setTimeout(() => { self.timer = setInterval(() => { // Incrementing page - if (self.curPage === self.config.modules.length - 1) { - self.curPage = 0; - } else { self.curPage++ } + self.curPage = (self.curPage++) % self.config.modules.length; self.sendNotification("PAGE_INCREMENT"); self.updatePages(false); }, self.config.rotationTime, false);