Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edifice-facade

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edifice-facade

Create facades to separate modules in your application

  • 0.3.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

edifice-facade

We can connect different parts of an application with an EventEmitter. Let's call this the core.

function initUserInterface(core) {
  form.onsubmit((data) => {
    core.emit("contentupdate", data);
  });
}

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.

function initUserInterface(core) {
  form.onsubmit((data) => {
    core.emit("contentupdate", data);
  }
  core.on("contentupdate", (data) => {
    form.update(data);
  });
}

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 = require("events").EventEmitter;
const Facade = require("edifice-facade");

const core = new EventEmitter();
const dbFacade = new Facade(core);
const uiFacade = new Facade(core);

But we don't want the database module firing an alertuser event. We create internal application security with permissions.

const dbFacade = new Facade(core, {
  on : ["contentupdate", "contentexpiry", "userloginattempt"],
  emit : ["contentupdate", "userloginsuccess", "userloginfailure"]
});

Now all that's left is to pass your facades to each of your modules.

require("./userInterface").init(uiFacade);

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.

Keywords

FAQs

Package last updated on 08 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc