github.com/kjdelisle/consul@v1.4.5/ui-v2/app/mixins/with-resizing.js (about)

     1  import Mixin from '@ember/object/mixin';
     2  import { get } from '@ember/object';
     3  import { assert } from '@ember/debug';
     4  export default Mixin.create({
     5    resize: function(e) {
     6      assert('with-resizing.resize needs to be overridden', false);
     7    },
     8    win: window,
     9    init: function() {
    10      this._super(...arguments);
    11      this.handler = e => {
    12        const win = e.target;
    13        this.resize({
    14          detail: { width: win.innerWidth, height: win.innerHeight },
    15        });
    16      };
    17    },
    18    didInsertElement: function() {
    19      this._super(...arguments);
    20      get(this, 'win').addEventListener('resize', this.handler, false);
    21      this.didAppear();
    22    },
    23    didAppear: function() {
    24      this.handler({ target: get(this, 'win') });
    25    },
    26    willDestroyElement: function() {
    27      get(this, 'win').removeEventListener('resize', this.handler, false);
    28      this._super(...arguments);
    29    },
    30  });