First up, I’m new to both javascript and MM, so if you find yourself thinking, “well, surely he’s taken care of X” or “having tried X already…” —no, please assume the worst about my knowledge base. ••• There’s nothing like looking at a Magic Mirror with an empty edge to fire the imagination. Thanks in advance for your patience.
Q1:
I need my module to be able to handle multiple instances. I have read its possible to duplicate and rename everything, but I’d like it to work… “natively”. If my module’s programming is designed for it, a module can have multiple instances running from the same Module directory, just with different entries and options in config.js, yes?
Q2:
My node_helper.js really runs the show. I read in the docs that I only get one helper, so it now registers socket communication by module identifier. When it has content ready, it sends the corresponding id back with it, so other instances can ignore it. Does this sound like the right approach?
So I’ll only have one helper. Will I also “only have one module_name_here.js”? I naïvely just added a few global variables outside Module.register and they seem to be colliding between instances. I don’t really understand the MM magic and Module.register functionality under the hood.
Q3: If I use the js ‘this’ keyword inside that .register, what does ‘this’ refer to, precisely?
Q4: Where should I declare variables for one-instance scope?
Q5: Or should I store them all together, and explicitly associate returning helper payloads to an instance identifier inside module.js just like I do to module payloads inside node_helper.js?