Skip to content

Commit b0d2de7

Browse files
committed
Make NProgress play nicely with Ember’s run loop
1 parent c5163bb commit b0d2de7

File tree

6 files changed

+43
-2
lines changed

6 files changed

+43
-2
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 function initialize() {
7+
const scheduler = run.later.bind(this, this);
8+
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ moduleForAcceptance('Acceptance | run loop', {
1313
}
1414
});
1515

16+
// This is required to get the app set up
1617
test('loading an initial route', function(assert) {
1718
assert.expect(0);
1819

1920
visit('/');
2021
});
2122

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
2225
test('it fires the `start` event within the run loop', function(assert) {
2326
visit('/');
2427

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Ember from 'ember';
2+
import NprogressInitializer from 'dummy/initializers/nprogress';
3+
import { module, test } from 'qunit';
4+
5+
let application;
6+
7+
module('Unit | Initializer | nprogress', {
8+
beforeEach() {
9+
Ember.run(function() {
10+
application = Ember.Application.create();
11+
application.deferReadiness();
12+
});
13+
}
14+
});
15+
16+
// Replace this with your real tests.
17+
test('it works', function(assert) {
18+
NprogressInitializer.initialize(application);
19+
20+
// you would normally confirm the results of the initializer here
21+
assert.ok(true);
22+
});

0 commit comments

Comments
 (0)