Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

impswitch

1.0.3 • Public • Published

ImpSwitch

npm version dependencies Build Status Pledge To Arupex!

Install

npm install impswitch --save

Switch Between Implementations

Assumptions:

    implementation functions should follow
        function(options, successCallback, failureCallback)

Example:

var ImpSwitch = require('impswitch');

var switch = ImpSwitch({
    real : {
        go: function go(options, success, failure) {
            success('Real Implementation');
        }
    },
    mock : {
        go : function go(options, success, failure) {
            success('Mock Implementation');
        }
    },
    {
        selector : function selector(options) {
            return options.id > 0 ? 'real' : 'mock';
        }
    }
});

Call

function success(data){
    console.log(data);
}

function failure(err){
    console.error(err);
}

switch('go')({ id : -1 }, success, failure)

switch('go')({ id : 1 }, success, failure)

Expected Output (ignoring any asynchronous operations):

Mock Implementation

Real Implementation

Alternative Calls! By Request

var superSwitch = switch('__SuperSwitch'); // '__SuperSwitch' create a switcher that doesnt require function name

superSwitch.go({ id : -1 }, success, failure)

superSwitch.go({ id : 1 }, success, failure)

Expected Output (ignoring any asynchronous operations):

Mock Implementation

Real Implementation

Or

var mock = switch('mock');
mock.go({ id : -1 });
mock.go({ id : 1 });

Expected Output:

Mock Implementation

Mock Implementation

Keywords

none

install

npm i impswitch

Downloadsweekly downloads

0

version

1.0.3

license

UNLICENSED

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability