Skip to content

Commit 67b7463

Browse files
authored
Merge pull request #2 from alexlafroscia/better-runloop-integration
Better runloop integration
2 parents 048d6ac + 20d68b8 commit 67b7463

File tree

11 files changed

+97
-3
lines changed

11 files changed

+97
-3
lines changed

addon/initializers/nprogress.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Ember from 'ember';
2+
import nprogress from 'ember-cli-nprogress';
3+
4+
const { run } = Ember;
5+
6+
export const scheduler = run.later.bind(undefined, undefined);
7+
8+
export function initialize() {
9+
nprogress.configure({ scheduler });
10+
}
11+
12+
export default {
13+
name: 'nprogress',
14+
initialize
15+
};

app/initializers/nprogress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default, initialize } from 'ember-cli-nprogress/initializers/nprogress';

blueprints/ember-cli-nprogress/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module.exports = {
22
normalizeEntityName: function() {}, // no-op since we're just adding dependencies
33

44
afterInstall: function() {
5-
return this.addBowerPackageToProject('nprogress', '^0.2.0');
5+
return this.addBowerPackageToProject('nprogress', 'alexlafroscia/nprogress#allow-alternate-scheduler');
66
}
77
};

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"dependencies": {
44
"ember": "~2.10.0",
55
"ember-cli-shims": "0.1.3",
6-
"nprogress": "^0.2.0"
6+
"nprogress": "alexlafroscia/nprogress#allow-alternate-scheduler"
77
}
88
}

tests/acceptance/run-loop-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { test } from 'qunit';
2+
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
3+
4+
import nprogress from 'ember-cli-nprogress';
5+
6+
// Note: This somewhat unorthidox test setup will throw an error when running the tests in Chrome,
7+
// if `nprogress` isn't configured to run within the Ember run loop
8+
moduleForAcceptance('Acceptance | run loop', {
9+
beforeEach() {
10+
nprogress.configure({
11+
parent: '#nprogress-parent'
12+
});
13+
}
14+
});
15+
16+
// This is required to get the app set up
17+
test('loading an initial route', function(assert) {
18+
assert.expect(0);
19+
20+
visit('/');
21+
});
22+
23+
// This test just verifies that an error is not produced in cases where `nprogress`
24+
// is running while the app is being torn down
25+
test('it fires the `start` event within the run loop', function(assert) {
26+
visit('/');
27+
28+
click('a');
29+
30+
andThen(function() {
31+
assert.equal(currentURL(), '/some-other-route');
32+
});
33+
});

tests/dummy/app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Router = Ember.Router.extend({
77
});
88

99
Router.map(function() {
10+
this.route('some-other-route');
1011
});
1112

1213
export default Router;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Ember from 'ember';
2+
import nprogress from 'ember-cli-nprogress';
3+
4+
const { Route } = Ember;
5+
6+
export default Route.extend({
7+
actions: {
8+
willTransition() {
9+
nprogress.start();
10+
},
11+
12+
didTransition() {
13+
nprogress.done();
14+
}
15+
}
16+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<h2 id="title">Welcome to Ember</h2>
1+
<div id='nprogress-parent'></div>
22

33
{{outlet}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Hello, world!</h1>
2+
3+
{{link-to 'Some other route' 'some-other-route'}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>Some Other Route</h1>
2+

0 commit comments

Comments
 (0)