# all files / app/initializers/ export-application-global.js

4.76% Statements 1/21
0% Branches 0/14
0% Functions 0/2
4.76% Lines 1/21

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47

    1×

     import Ember from 'ember';
    import config from '../config/environment';

    export function initialize() {
      var application = arguments[1] || arguments[0];
      if (config.exportApplicationGlobal !== false) {
        var theGlobal;
        if (typeof window !== 'undefined') {
            theGlobal = window;
        } else if (typeof global !== 'undefined') {
            theGlobal = global
        } else if (typeof self !== 'undefined') {
            theGlobal = self;
        } else {
           // no reasonable global, just bail
           return;
        }

        var value = config.exportApplicationGlobal;
        var globalName;

        if (typeof value === 'string') {
          globalName = value;
        } else {
          globalName = Ember.String.classify(config.modulePrefix);
        }

        if (!theGlobal[globalName]) {
          theGlobal[globalName] = application;

          application.reopen({
            willDestroy: function() {
              this._super.apply(this, arguments);
              delete theGlobal[globalName];
            }
          });
        }
      }
    }

    export default {
      name: 'export-application-global',

      initialize: initialize
    };