Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades ember-app-scheduler to 1.0.1 #139

Merged
merged 2 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ historySupportMiddleware: true,
This location type inherits from Ember's `HistoryLocation`.

4. If using old style QUnit tests. If tests based on [RFC](https://github.com/emberjs/rfcs/pull/232), you can ignore this.
In your router and controller tests, add `'service:router-scroll'` and `'service:scheduler'` as dependencies in the `needs: []` block:
In your router and controller tests, add `'service:router-scroll'` as a dependency in the `needs: []` block:

```js
//{your-app}}/tests/unit/routes/{{your-route}}.js
needs:[ 'service:router-scroll', 'service:scheduler' ],
needs:[ 'service:router-scroll' ],
```

## Issues with nested routes
Expand Down
16 changes: 14 additions & 2 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ import { get, computed } from '@ember/object';
import { inject } from '@ember/service';
import { getOwner } from '@ember/application';
import { scheduleOnce } from '@ember/runloop';
import { setupRouter, reset, whenRouteIdle } from 'ember-app-scheduler';

export default Mixin.create({
scheduler: inject('scheduler'),
service: inject('router-scroll'),

isFastBoot: computed(function() {
const fastboot = getOwner(this).lookup('service:fastboot');
return fastboot ? fastboot.get('isFastBoot') : false;
}),

init() {
this._super(...arguments);

setupRouter(this);
},

destroy() {
reset();

this._super(...arguments);
},

willTransition(...args) {
this._super(...args);

Expand All @@ -33,7 +45,7 @@ export default Mixin.create({
} else {
// as described in ember-app-scheduler, this addon can be used to delay rendering until after First Meaningful Paint.
// If you loading your routes progressively, this may be a good option to delay scrollTop until the remaining DOM elements are painted.
this.get('scheduler').scheduleWork('afterContentPaint', () => {
whenRouteIdle().then(() => {
this.updateScrollPosition(transitions);
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"test:all": "ember try:each"
},
"dependencies": {
"ember-app-scheduler": "^0.2.2",
"ember-app-scheduler": "^1.0.1",
"ember-cli-babel": "^6.6.0",
"ember-getowner-polyfill": "^2.0.1"
},
Expand Down
39 changes: 11 additions & 28 deletions tests/unit/mixins/router-scroll-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { run, next } from '@ember/runloop';
import EmberObject from '@ember/object';
import Evented from '@ember/object/evented';
import RouterScroll from 'ember-router-scroll';
import { module, test } from 'qunit';

Expand All @@ -14,14 +15,6 @@ module('mixin:router-scroll', function(hooks) {
window.scrollTo = scrollTo;
});

function getSchedulerMock() {
return {
scheduleWork: (eventName, callback) => {
callback();
},
};
}

function getTransitionsMock (URL, isPreserveScroll, hasIntimateRouterAPI) {
return [
{
Expand All @@ -41,10 +34,9 @@ module('mixin:router-scroll', function(hooks) {
assert.expect(1);

const done = assert.async();
const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: true,
scheduler: getSchedulerMock(),
updateScrollPosition() {
assert.notOk(true, 'it should not call updateScrollPosition.');
done();
Expand All @@ -64,10 +56,9 @@ module('mixin:router-scroll', function(hooks) {
assert.expect(1);

const done = assert.async();
const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
delayScrollTop: false,
},
Expand All @@ -86,10 +77,9 @@ module('mixin:router-scroll', function(hooks) {
assert.expect(1);

const done = assert.async();
const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
targetElement: '#myElement',
},
Expand All @@ -108,10 +98,9 @@ module('mixin:router-scroll', function(hooks) {
assert.expect(1);

const done = assert.async();
const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
delayScrollTop: true,
},
Expand All @@ -132,10 +121,9 @@ module('mixin:router-scroll', function(hooks) {

window.scrollTo = () => assert.ok(false, 'Scroll To should not be called');

const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
position: null,
scrollElement: 'window',
Expand All @@ -158,10 +146,9 @@ module('mixin:router-scroll', function(hooks) {
window.scrollTo = (x, y) =>
assert.ok(x === elem.offsetLeft && y === elem.offsetTop, 'Scroll to called with correct offsets');

const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
position: null,
scrollElement: 'window',
Expand All @@ -184,10 +171,9 @@ module('mixin:router-scroll', function(hooks) {
window.scrollTo = (x, y) =>
assert.ok(x === elem.offsetLeft && y === elem.offsetTop, 'Scroll to called with correct offsets');

const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
position: null,
scrollElement: 'window',
Expand All @@ -207,10 +193,9 @@ module('mixin:router-scroll', function(hooks) {
window.scrollTo = (x, y) =>
assert.ok(x === 1 && y === 2, 'Scroll to called with correct offsets');

const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
position: { x: 1, y: 2 },
scrollElement: 'window',
Expand All @@ -233,10 +218,9 @@ module('mixin:router-scroll', function(hooks) {
window.scrollTo = (x, y) =>
assert.ok(x === 1 && y === 2, 'Scroll to called with correct offsets');

const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
position: { x: 1, y: 2 },
scrollElement: 'window',
Expand All @@ -256,10 +240,9 @@ module('mixin:router-scroll', function(hooks) {
window.scrollTo = (x, y) =>
assert.ok(x === 1 && y === 2, 'Scroll to was called with correct offsets');

const RouterScrollObject = EmberObject.extend(RouterScroll);
const RouterScrollObject = EmberObject.extend(Evented, RouterScroll);
const subject = RouterScrollObject.create({
isFastBoot: false,
scheduler: getSchedulerMock(),
service: {
position: { x: 1, y: 2 },
scrollElement: 'window',
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1966,9 +1966,9 @@ electron-to-chromium@^1.3.30:
version "1.3.42"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.42.tgz#95c33bf01d0cc405556aec899fe61fd4d76ea0f9"

ember-app-scheduler@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/ember-app-scheduler/-/ember-app-scheduler-0.2.2.tgz#e4a66275d1789d1b054815ee230c6f759b4b75eb"
ember-app-scheduler@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ember-app-scheduler/-/ember-app-scheduler-1.0.1.tgz#cc25e79d139525e440f2b26bcf8fdd60a3899878"
dependencies:
ember-cli-babel "^6.3.0"

Expand Down