atriusmaps-node-sdk
Version:
This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information
46 lines (35 loc) • 1.45 kB
JavaScript
;
var app = require('./app.js');
/**
* This manages the creation and organization of your App instances.
* Each instance is created via the create function - passing in a configuration
* object, which extends any existing configuration template.
*/
// Note, we are no longer using IOBject - but we can freeze apps via Object.freeze(apps)
// IObject.freeze = 'DEEP'
// This is a list of "instances" of your full app stack. Often this will be only one.
// If you wish to give it a name, use the appName property. Else one will be assigned.
const apps = {};
const sendAlert = msg => (typeof window !== 'undefined' && window.alert ? window.alert(msg) : console.error(msg));
/**
* Create a new instance of the engine. Pass in a configuration object which will
* extend the config template.
* @param {} config Configuration for this instance. Will be shallow copied.
*/
async function create(config) {
if (!config) {
throw Error('Attempt to create App instance with no configuration');
}
// If no name was defined for this instance, create one.
const appName = config.appName || 'Instance' + (Object.keys(apps).length + 1);
config.appName = appName;
try {
const app$1 = await app.create(config);
apps[appName] = app$1;
return app$1;
} catch (e) {
console.error(e);
e.message ? sendAlert(e.message) : sendAlert('Error creating map. Please try again later.');
}
}
exports.create = create;