Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Larrenaga committed Aug 10, 2018
1 parent a81f412 commit 5e344fd
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 225 deletions.
28 changes: 15 additions & 13 deletions addon/mixins/resize-aware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Mixin from '@ember/object/mixin';
import { inject as service } from '@ember/service';
import { get, setProperties } from '@ember/object';
import { debounce, next } from '@ember/runloop';
import { debounce, next, scheduleOnce } from '@ember/runloop';
import { tryInvoke } from '@ember/utils';
import Ember from 'ember';

Expand All @@ -19,7 +19,7 @@ export default Mixin.create({
didInsertElement(...args) {
this._super(...args);
this._handleResizeEvent = this._handleResizeEvent.bind(this);
get(this, 'unifiedEventHandler').register('window', 'resize', this._handleResizeEvent);
scheduleOnce('afterRender', this, () => get(this, 'unifiedEventHandler').register('window', 'resize', this._handleResizeEvent));
},

willDestroyElement(...args) {
Expand All @@ -32,17 +32,19 @@ export default Mixin.create({
},

_debouncedResizeEvent() {
const boundingRect = this.element.getBoundingClientRect();

const newWidth = Math.floor(boundingRect.width);
const newHeight = Math.floor(boundingRect.height);

if ((get(this, '_previousWidth') !== newWidth) || (get(this, '_previousHeight') !== newHeight)) {
next(this, () => !get(this, 'isDestroyed') && tryInvoke(this, 'didResize', [newWidth, newHeight]));
setProperties(this, {
_previousWidth: newWidth,
_previousHeight: newHeight
});
if (this.element) {
const boundingRect = this.element.getBoundingClientRect();

const newWidth = Math.floor(boundingRect.width);
const newHeight = Math.floor(boundingRect.height);

if ((get(this, '_previousWidth') !== newWidth) || (get(this, '_previousHeight') !== newHeight)) {
next(this, () => !get(this, 'isDestroyed') && tryInvoke(this, 'didResize', [newWidth, newHeight]));
setProperties(this, {
_previousWidth: newWidth,
_previousHeight: newHeight
});
}
}
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-resize-aware",
"version": "1.1.0",
"version": "1.2.0",
"description": "Ember Component mixin to notify of size changes.",
"keywords": [
"ember-addon"
Expand Down

0 comments on commit 5e344fd

Please sign in to comment.