Skip to content

Commit 5d24525

Browse files
authored
Merge branch 'master' into patch-1
2 parents b2a28b2 + 5d60375 commit 5d24525

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# [0.1.0](https://github.com/mike-north/ember-resize/compare/v0.0.16...v0.1.0) (2018-08-23)
2+
3+
4+
### Bug Fixes
5+
6+
* remove travis-CI npm deploy ([e547a88](https://github.com/mike-north/ember-resize/commit/e547a88))
7+
* semantic-release ([2b3c864](https://github.com/mike-north/ember-resize/commit/2b3c864))
8+
* semantic-release in travis-ci ([245e2a2](https://github.com/mike-north/ember-resize/commit/245e2a2))
9+
* upgrade ember ([e191fed](https://github.com/mike-north/ember-resize/commit/e191fed))
10+
11+
12+
### Features
13+
14+
* code formatting ([4fed02d](https://github.com/mike-north/ember-resize/commit/4fed02d))
15+
* semantic-release setup ([e0b0d61](https://github.com/mike-north/ember-resize/commit/e0b0d61))
16+
117
## [0.0.17](https://github.com/mike-north/ember-resize/compare/v0.0.16...v0.0.17) (2018-08-22)
218

319

addon/mixins/resize-aware.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import Mixin from '@ember/object/mixin';
2+
import { readOnly } from '@ember/object/computed';
23
const { floor } = Math;
34

45
export default Mixin.create({
56
resizeEventsEnabled: true,
67
resizeDebouncedEventsEnabled: true,
78

9+
screenWidth: readOnly('resizeService.screenWidth'),
10+
screenHeight: readOnly('resizeService.screenHeight'),
11+
812
_oldViewWidth: null,
913
_oldViewHeight: null,
1014
_oldViewWidthDebounced: null,

addon/services/resize.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { keys as emberKeys } from '@ember/polyfills';
22
import Service from '@ember/service';
33
import Evented from '@ember/object/evented';
44
import { classify } from '@ember/string';
5-
import { oneWay } from '@ember/object/computed';
5+
import { oneWay, readOnly } from '@ember/object/computed';
66
import { debounce, cancel } from '@ember/runloop';
77
import EmberObject, { set, getWithDefault } from '@ember/object';
88

@@ -11,16 +11,17 @@ const Base = Service || EmberObject;
1111
const keys = Object.keys || emberKeys;
1212

1313
export default Base.extend(Evented, {
14-
_oldWidth: null,
15-
_oldHeight: null,
16-
_oldWidthDebounced: null,
17-
_oldHeightDebounced: null,
18-
_scheduledDebounce: null,
19-
14+
_oldWidth: window.innerWidth,
15+
_oldHeight: window.innerHeight,
16+
_oldWidthDebounced: window.innerWidth,
17+
_oldHeightDebounced: window.innerHeight,
2018
debounceTimeout: oneWay('defaultDebounceTimeout'),
2119
widthSensitive: oneWay('defaultWidthSensitive'),
2220
heightSensitive: oneWay('defaultHeightSensitive'),
2321

22+
screenWidth: readOnly('_oldWidth'),
23+
screenHeight: readOnly('_oldHeight'),
24+
2425
init() {
2526
this._super(...arguments);
2627
this._setDefaults();

app/initializers/resize.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export function initialize() {
1212
});
1313
const injectionFactories = getWithDefault(resizeServiceDefaults, 'injectionFactories', ['view', 'component']) ;
1414

15+
application.unregister('config:resize-service');
16+
application.unregister('service:resize');
17+
1518
application.register('config:resize-service', resizeServiceDefaults, { instantiate: false });
1619
application.register('service:resize', ResizeService);
1720
application.inject('service:resize', 'resizeServiceDefaults', 'config:resize-service');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@
6767
"release": {
6868
"extends": "@mike-north/js-lib-semantic-release-config"
6969
}
70-
}
70+
}

tests/unit/services/resize-test.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,28 @@ test('it fires "didResize" when the window is resized', function(assert) {
2020
let evt = new window.Event('resize');
2121

2222
window.dispatchEvent(evt);
23-
assert.equal(didResizeCallCount, 1, 'didResize called 1 time on event firing');
23+
assert.equal(didResizeCallCount, 0, 'didResize called 0 time on event firing');
2424
service.incrementProperty('_oldHeight', -20);
2525
window.dispatchEvent(evt);
26-
assert.equal(didResizeCallCount, 2, 'didResize called another time on event firing again');
26+
assert.equal(didResizeCallCount, 1, 'didResize called 1 time on event firing');
2727
service.set('heightSensitive', false);
2828
service.incrementProperty('_oldHeight', -20);
2929
window.dispatchEvent(evt);
30-
assert.equal(didResizeCallCount, 2, 'didResize shouldn\'t be called again if heightSensitive is false');
30+
assert.equal(didResizeCallCount, 1, 'didResize shouldn\'t be called again if heightSensitive is false');
31+
32+
});
33+
34+
test('screenHeight is bound to the non debounced resize', function(assert) {
35+
36+
let service = this.subject({
37+
widthSensitive: false,
38+
heightSensitive: true
39+
});
40+
41+
let evt = new window.Event('resize');
42+
43+
window.dispatchEvent(evt);
44+
assert.equal(service.get('screenHeight'), window.innerHeight);
3145

3246
});
3347

@@ -55,6 +69,7 @@ test('it fires "debouncedDidResize" when the window is resized', function(asser
5569
later(triggerEvent, 10);
5670
}
5771

72+
service.incrementProperty('_oldHeightDebounced', -20);
5873
assert.equal(debouncedDidResizeCallCount, 0, 'debouncedDidResize not called yet');
5974
later(() => {
6075
assert.equal(debouncedDidResizeCallCount, 1, 'debouncedDidResize called 1 time after 500ms');

0 commit comments

Comments
 (0)