UNPKG

831 BJavaScriptView Raw
1'use strict';
2
3var Application = require('./core/Application');
4var package_json = require('./package.json');
5
6var _applications_cache = {};
7var _default_app_key = null;
8
9/**
10 * Creates or/and return application instance
11 *
12 * @param {string|ApplicationOptions} [options]
13 * @returns {Application}
14 */
15function IFNode(options) {
16 if(_default_app_key && !options) {
17 return _applications_cache[_default_app_key];
18 }
19
20 if(typeof options === 'string') {
21 return _applications_cache[options];
22 }
23
24 var app = new Application(options || {});
25 var key = app.alias || app.id;
26
27 if(!_default_app_key) {
28 _default_app_key = key;
29 }
30
31 _applications_cache[key] = app;
32
33 return app;
34}
35
36Object.defineProperty(IFNode, 'VERSION', {
37 value: package_json.version
38});
39
40module.exports = IFNode;