facade-factory

0.1.0 • Public • Published

js-facade-factory

npm install --save facade-factory

Demo

Releases:

A way to create facades that are guaranteed to have only the methods listed in their descriptions. This is a useful collaboration or organizational tool.

Sample usage:

In a shared file / module, describe the facade that will be used by multiple imlementations. The facade is described using key value pairs. The keys are the method names, and the values are the descriptions of the functionality.

var playerFacade = {
    play: 'method to play movies',
    stop: 'method to stop movies'
};

Create a facade implelemntation. Helper methods and fields may be used and will be functional, but they will not be exposed as part of the facade; they are essentially private.

var htmlPlayer = {
    time: 0,
    play: function() { ++this.time; this.helper(); return this; },
    stop: function() { console.log("html stop"); return this; },
    helper: function() { console.log("html play and play helper fired - time is now: " + this.time); },
};

Now create the facade using its description and implementation

var player = new Facade(playerFacade, htmlPlayer);

Use it:

player.play().stop();

Now you can use the same code that relies on a player for different types of players in different environments.

// Create a flash player
var player = new Facade(playerFacade, flashPlayer);
 
// Or create an html player
var player = new Facade(playerFacade, htmlPlayer);
 
// Use the player without caring which one you have.
player.play().stop();

Contributors

Changelog

  • 0.1.0 - 2017 Feb 06 - Publishing on NPM
  • 0.0.3 - 2013 Oct 15 - Support for AMD
  • 0.0.2 - 2013 Jan 10 - Support for properties
  • 0.0.1 - 2012 Nov 09 - Initial release

Readme

Keywords

none

Package Sidebar

Install

npm i facade-factory

Weekly Downloads

1

Version

0.1.0

License

none

Last publish

Collaborators

  • pajtai