edifice-facade
We can connect different parts of an application with an EventEmitter. Let's
call this the core
.
{ form;}
If a contentupdate
can also come from a database update, we want to listen for
these in the user interface module. This can cause an annoying event loop.
{ form
Facades create a separate "view" of the core for each module. Facades don't fire their own events, only those of other facades.
const EventEmitter = EventEmitter;const Facade = ; const core = ;const dbFacade = core;const uiFacade = core;
But we don't want the database module firing an alertuser
event. We create
internal application security with permissions.
const dbFacade = core on : "contentupdate" "contentexpiry" "userloginattempt" emit : "contentupdate" "userloginsuccess" "userloginfailure";
Now all that's left is to pass your facades to each of your modules.
;
Top tips:
- Make sure that each module has only the bits in scope that it needs. Your central app module should intialise the core and facades, and then pass the facades to the other modules.
- Each event should have a documented arguments list.
Why the name edifice-facade?
I originally planned on making a module called edifice as the core, then realised the core could just be a plain old EventEmitter. So ediface is no more. Long live facade.
License
MIT.