Skip to content

Commit 594502d

Browse files
authored
Merge pull request #90 from intercom/gj/router-service
Use router service polyfill
2 parents 47173f0 + c27f1ca commit 594502d

File tree

6 files changed

+55
-42
lines changed

6 files changed

+55
-42
lines changed

addon/helpers/href-to.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import Helper from '@ember/component/helper';
22
import { getOwner } from '@ember/application';
33

44
function hrefTo(context, targetRouteName, ...rest) {
5-
let router = getOwner(context).lookup('router:main');
6-
if (router === undefined ||
7-
(router._routerMicrolib === undefined && router.router === undefined)) {
5+
let router = getOwner(context).lookup('service:router');
6+
7+
if(router === undefined) {
88
return;
99
}
1010

@@ -19,7 +19,7 @@ function hrefTo(context, targetRouteName, ...rest) {
1919
args.push.apply(args, rest);
2020
args.push({ queryParams: queryParams.values });
2121

22-
return router.generate.apply(router, args);
22+
return router.urlFor.apply(router, args);
2323
}
2424

2525
export { hrefTo };

addon/href-to.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ export default class {
2828

2929
handle() {
3030
let router = this._getRouter();
31-
let urlWithoutRoot = this.getUrlWithoutRoot();
32-
let routerMicrolib = router._routerMicrolib || router.router;
33-
34-
router.handleURL(urlWithoutRoot);
35-
routerMicrolib.updateURL(urlWithoutRoot);
31+
router.transitionTo(this.url);
3632
this.event.preventDefault();
3733
}
3834

@@ -63,7 +59,7 @@ export default class {
6359
let isLinkComponent = false;
6460
let id = this.target.id;
6561
if (id) {
66-
let componentInstance = this._getContainer(this.applicationInstance).lookup('-view-registry:main')[id];
62+
let componentInstance = this.applicationInstance.lookup('-view-registry:main')[id];
6763
isLinkComponent = componentInstance && componentInstance instanceof LinkComponent;
6864
}
6965

@@ -75,11 +71,11 @@ export default class {
7571
let didRecognize = false;
7672

7773
if (url) {
78-
let router = this._getContainer().lookup('router:main');
74+
let router = this._getRouter();
7975
let rootUrl = this._getRootUrl();
8076
let isInternal = url.indexOf(rootUrl) === 0;
8177
let urlWithoutRoot = this.getUrlWithoutRoot();
82-
let routerMicrolib = router._routerMicrolib || router.router;
78+
let routerMicrolib = router._router._routerMicrolib || router._router.router;
8379

8480
didRecognize = isInternal && routerMicrolib.recognizer.recognize(urlWithoutRoot);
8581
}
@@ -94,16 +90,12 @@ export default class {
9490
}
9591

9692
_getRouter() {
97-
return this._getContainer().lookup('router:main');
98-
}
99-
100-
_getContainer() {
101-
return 'lookup' in this.applicationInstance ? this.applicationInstance : this.applicationInstance.container;
93+
return this.applicationInstance.lookup('service:router');
10294
}
10395

10496
_getRootUrl() {
10597
let router = this._getRouter();
106-
let rootURL = router.rootURL;
98+
let rootURL = router.get('rootURL');
10799

108100
if (rootURL.charAt(rootURL.length - 1) !== '/') {
109101
rootURL = rootURL + '/';

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"ember-addon"
4444
],
4545
"dependencies": {
46-
"ember-cli-babel": "^6.8.2"
46+
"ember-cli-babel": "^6.8.2",
47+
"ember-router-service-polyfill": "^1.0.2"
4748
},
4849
"ember-addon": {
4950
"configPath": "tests/dummy/config"

tests/integration/component-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { moduleForComponent, test } from 'ember-qunit';
22
import hbs from 'htmlbars-inline-precompile';
3+
import { getOwner } from '@ember/application';
34

45
moduleForComponent('component-with-a-link', 'Integration | Component | component-with-a-link', {
5-
integration: true
6+
integration: true,
7+
8+
beforeEach() {
9+
getOwner(this).lookup('router:main').setupRouter();
10+
}
611
});
712

813
test('should change colors', function(assert) {

tests/integration/href-to-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { moduleForComponent, test } from 'ember-qunit';
22
import hbs from 'htmlbars-inline-precompile';
33
import HrefTo from 'ember-href-to/href-to';
4+
import { getOwner } from '@ember/application';
45

56
moduleForComponent('a-link', 'Integration | HrefTo', {
6-
integration: true
7+
integration: true,
8+
9+
beforeEach() {
10+
getOwner(this).lookup('router:main').setupRouter();
11+
}
712
});
813

914
function leftClickEvent() {

yarn.lock

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,8 @@ can-symlink@^1.0.0:
14371437
tmp "0.0.28"
14381438

14391439
caniuse-lite@^1.0.30000744:
1440-
version "1.0.30000747"
1441-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000747.tgz#da86e78e12d0641abeeaee6ecd55d81bd9bd3b5d"
1440+
version "1.0.30000748"
1441+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000748.tgz#44c8d6da52ad65a5d7b9dca4efebd0bdd982ba09"
14421442

14431443
capture-exit@^1.1.0:
14441444
version "1.2.0"
@@ -1671,10 +1671,10 @@ component-inherit@0.0.3:
16711671
resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143"
16721672

16731673
compressible@~2.0.11:
1674-
version "2.0.11"
1675-
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.11.tgz#16718a75de283ed8e604041625a2064586797d8a"
1674+
version "2.0.12"
1675+
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.12.tgz#c59a5c99db76767e9876500e271ef63b3493bd66"
16761676
dependencies:
1677-
mime-db ">= 1.29.0 < 2"
1677+
mime-db ">= 1.30.0 < 2"
16781678

16791679
compression@^1.4.4:
16801680
version "1.7.1"
@@ -1951,8 +1951,8 @@ ee-first@1.1.1:
19511951
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
19521952

19531953
electron-to-chromium@^1.3.24:
1954-
version "1.3.26"
1955-
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.26.tgz#996427294861a74d9c7c82b9260ea301e8c02d66"
1954+
version "1.3.27"
1955+
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.27.tgz#78ecb8a399066187bb374eede35d9c70565a803d"
19561956

19571957
ember-ajax@^3.0.0:
19581958
version "3.0.0"
@@ -2323,6 +2323,12 @@ ember-router-generator@^1.0.0, ember-router-generator@^1.2.3:
23232323
dependencies:
23242324
recast "^0.11.3"
23252325

2326+
ember-router-service-polyfill@^1.0.2:
2327+
version "1.0.2"
2328+
resolved "https://registry.yarnpkg.com/ember-router-service-polyfill/-/ember-router-service-polyfill-1.0.2.tgz#6e5565f196fa7045cbe06a6fab861f9e766fe62a"
2329+
dependencies:
2330+
ember-cli-babel "^6.8.2"
2331+
23262332
ember-source@~2.16.0:
23272333
version "2.16.0"
23282334
resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-2.16.0.tgz#2becd7966278fe453046b91178ede665c2cf241a"
@@ -2644,8 +2650,8 @@ filename-regex@^2.0.0:
26442650
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"
26452651

26462652
filesize@^3.1.3:
2647-
version "3.5.10"
2648-
resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.5.10.tgz#fc8fa23ddb4ef9e5e0ab6e1e64f679a24a56761f"
2653+
version "3.5.11"
2654+
resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.5.11.tgz#1919326749433bb3cf77368bd158caabcc19e9ee"
26492655

26502656
fill-range@^2.1.0:
26512657
version "2.2.3"
@@ -3855,10 +3861,10 @@ make-array@^0.1.2:
38553861
resolved "https://registry.yarnpkg.com/make-array/-/make-array-0.1.2.tgz#335e36ebb0c5a43154d21213a1ecaeae2a1bb3ef"
38563862

38573863
make-dir@^1.0.0:
3858-
version "1.0.0"
3859-
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.0.0.tgz#97a011751e91dd87cfadef58832ebb04936de978"
3864+
version "1.1.0"
3865+
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.1.0.tgz#19b4369fe48c116f53c2af95ad102c0e39e85d51"
38603866
dependencies:
3861-
pify "^2.3.0"
3867+
pify "^3.0.0"
38623868

38633869
makeerror@1.0.x:
38643870
version "1.0.11"
@@ -3947,7 +3953,7 @@ micromatch@^2.1.5, micromatch@^2.3.7:
39473953
parse-glob "^3.0.4"
39483954
regex-cache "^0.4.2"
39493955

3950-
"mime-db@>= 1.29.0 < 2", mime-db@~1.30.0:
3956+
"mime-db@>= 1.30.0 < 2", mime-db@~1.30.0:
39513957
version "1.30.0"
39523958
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.30.0.tgz#74c643da2dd9d6a45399963465b26d5ca7d71f01"
39533959

@@ -4316,9 +4322,9 @@ performance-now@^0.2.0:
43164322
version "0.2.0"
43174323
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
43184324

4319-
pify@^2.3.0:
4320-
version "2.3.0"
4321-
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
4325+
pify@^3.0.0:
4326+
version "3.0.0"
4327+
resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"
43224328

43234329
pinkie-promise@^2.0.0:
43244330
version "2.0.1"
@@ -4382,8 +4388,8 @@ punycode@^1.4.1:
43824388
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
43834389

43844390
q@^1.1.2:
4385-
version "1.5.0"
4386-
resolved "https://registry.yarnpkg.com/q/-/q-1.5.0.tgz#dd01bac9d06d30e6f219aecb8253ee9ebdc308f1"
4391+
version "1.5.1"
4392+
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
43874393

43884394
qs@6.5.1, qs@^6.4.0:
43894395
version "6.5.1"
@@ -4406,8 +4412,8 @@ qunit-notifications@^0.1.1:
44064412
resolved "https://registry.yarnpkg.com/qunit-notifications/-/qunit-notifications-0.1.1.tgz#3001afc6a6a77dfbd962ccbcddde12dec5286c09"
44074413

44084414
qunitjs@^2.0.1:
4409-
version "2.4.0"
4410-
resolved "https://registry.yarnpkg.com/qunitjs/-/qunitjs-2.4.0.tgz#58f3a81e846687f2e7f637c5bedc9c267f887261"
4415+
version "2.4.1"
4416+
resolved "https://registry.yarnpkg.com/qunitjs/-/qunitjs-2.4.1.tgz#88aba055a9e2ec3dbebfaad02471b2cb002c530b"
44114417
dependencies:
44124418
chokidar "1.6.1"
44134419
commander "2.9.0"
@@ -4979,7 +4985,11 @@ stable@~0.1.3:
49794985
version "0.1.6"
49804986
resolved "https://registry.yarnpkg.com/stable/-/stable-0.1.6.tgz#910f5d2aed7b520c6e777499c1f32e139fdecb10"
49814987

4982-
"statuses@>= 1.3.1 < 2", statuses@~1.3.1:
4988+
"statuses@>= 1.3.1 < 2":
4989+
version "1.4.0"
4990+
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087"
4991+
4992+
statuses@~1.3.1:
49834993
version "1.3.1"
49844994
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
49854995

0 commit comments

Comments
 (0)