aboutsummaryrefslogtreecommitdiff
path: root/src/global.js
blob: c837b44ca87df7fbc47882027262c1b539463b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Global storage section
//global object stores data which is dependent on different modules
//to release an object from memory specify global.destroy("variablename")
define(['lodash'], function(_) {


    var global = {
        destroy: function(objectName) {
            global[objectName] = null;
        },
        destroyAll: function() {
            var _keysExceptMethods = _.omitBy(global, function(value, key) {
                return (
                    _.eq(key, 'destroy') ||
                    _.eq(key, 'destroyAll') ||
                    _.eq(key, 'find')
                );
            });

            _.forEach(_keysExceptMethods, function(value, key) {
                global[key] = null;
            })
        },
        find: function(key) {
            var pickedVar = _.pick(global, key);
            return pickedVar;
        }
    }

    return global;
});