FR: Support MMM-pages
RStadlmair opened this issue · comments
Hi !
The module works great on a single-page MM², but doesnt show up on my MM² with multiple pages, done by MMM-pages.
It would be great to see this working.
R.
[enhancement]
@SamLewis0602, I took a look at your source and you're mutating the module.data
object when it should be immutable. See this PR for more information, with MichMich providing this explaination:
I just wanted to clarify that all the properties in the module.data objects should be handled as read only. On instantiating, the class name will be added to this class list. Overwriting this value will result in unexpected behaviour (like the case @edward-shen described).
If you're interested in the details, that issue provides the full context as well. As for an immediate fix, you can just append the bright medium
to the end, but the correct way would be to remove those lines entirely and put those classes on the DOM object instead.
What prompted you to put that code in? Is there some template/tutorial that does this? The PR I mentioned had the exact lines of code as well, so I'm suspecting there's some bad advice going around. Might be a good idea to file an issue on if it's on GitHub.
Thanks for finding that! Truthfully I've got no idea why I originally did that as I originally wrote this back in May of 2016 lol. I'll strip that out and check that everything still works as expected.
@edward-shen Thanks for doing the tough part of debugging and leaving the easy fix to me, I moved applying the className = 'bright medium'
to the getDom
method and now MMM-Traffic appears with Pages active.
There's one more snag though, it looks like the frontend of Traffic is missing the notification from the backend with traffic info the first time it gets sent, so it is stuck in the loading state for 2 minutes until the next update rolls around. It only happens when Pages is active. I'm speculating here, but based on the order of notifications in the screenshot below, I'm wondering if it's a race condition. AKA Traffic is calling updateDom before I see the resumed notification from Pages. What do you think? I've pushed this to master if you want to test for yourself.
I'm not sure how suspension and resumption work with node_helper
sockets. It sounds reasonable, but I'm surprised there aren't more modules that report similar problems.
I'm not sure of the best solution here, but what you could do (off the top of my head) would to be to subclass .resume()
to check if it's the first time it's resumed, and if so, to update the DOM again. Not the best solution, but probably the most direct way.
I didn't take a deep look into how your code is structured, but it might be worth seeing if it's also possible to remove the node_helper
code entirely and have one central file. That might fix the race condition as well (if it is one), since you no longer can race between the socket notification and MMM-pages, but that might be more substantial in terms of a fix.
Thanks for the link, I'll likely go the subclass route to see if I can get a quick fix and then consider ditching the node_helper entirely down the road.
@edward-shen .resume()
worked beautifully, appreciate your help today!
@RStadlmair to close the loop, MMM-Traffic has now been updated to be fully functional with MMM-Pages. Re-open this issue if you see any issues after updating your module. Thanks!
Glad to be of help.