multiappacitive

0.1.2 • Public • Published

This module returns a new instance of the Appacitive Javascript SDK on every include, overriding the default Singleton-like behaviour. This is achieved by clearing node's require.cache of the Appacitive module.

npm install multiappacitive

Usage

//Include multiAppacitive
var multiAppacitive = require('multiappacitive').Appacitive;
 
//Get a new instance of Appacitive
var Appacitive = new multiAppacitive();
 
//Get another new instance of Appacitive
var otherAppacitive = new multiAppacitive();

After getting a new instance, you need to intialize the SDK, as we do for normal singleton behaviour.

Example

The only place where we may need to change the singleton behaviour of SDK is performing actions on behalf of a loggged-in user, using his user-token.

export.js

// This script will be used to setup Appacitive usertoken in the SDK, if supplied, and return a new instance of Appacitive.
// If you provide a user object then that object will be set as current user. 
// You can always fetch a user by his token and set it as current user afterwards.
 
var multiAppacitive = require('multiappacitive').Appacitive;
 
exports.init = function (userToken, user) {
        
        var Appacitive = new multiAppacitive();
        
        Appacitive.initialize({ 
            apikey: {apikey}, 
            env: "{env}",
            appId: "{appId}",
            userToken: userToken, 
            user: user
        });
 
        return Appacitive;
};
 

sample.js

var app = require('./exports.js');
 
var userToken = "{usertoken}";
 
var Appacitive = app.init(userToken);

Package Sidebar

Install

npm i multiappacitive

Weekly Downloads

3

Version

0.1.2

License

none

Last publish

Collaborators

  • chiragsanghvi