@blockdrops/air
v1.0.1
Published
An high level, simple and clean library to achieve variable sharing between modules (and scripts eventually)
Downloads
5
Maintainers
Readme
Air.js
A socket based organized and handy way to communicate between modules
Simplified schema of the below example
main.js <--- module_a.js main.js <--- module_b.js in main.js we have variable x = 1 by using imc.broadcast("x", 1) we can send the variable to all the modules we can do the same to change it later: imc.broadcast("x", 2)
How to use it
For every module that will share informations with us, it needs to import air.js and initialize it with a name, then export the imc interface In module.js var air = require("./air.js") var imc = new air() imc.initialize("module_name")
Now in main.js (or any controller script anyway) we can import the module and register it In main.js const module = require("./module.js") imc.registered_modules.push({ name: "module_name", registered: true, socket: module.imc })
Now we can set variables valid for all the modules we registered In main.js imc.states["variable"] = "value" Registering locally imc.broadcast("variable", "value") Broadcasting to all the modules
After this point, the module can access the variable with imc.states["variable"] In module.js module.writeFile(imc.states["variable"])