Skip to content

Commit

Permalink
[FEATURE ember-routing-router-service] - Implementing phase 1 of public
Browse files Browse the repository at this point in the history
Router Service RFC
  • Loading branch information
scalvert committed Jan 19, 2017
1 parent 5df51f8 commit 7daa911
Show file tree
Hide file tree
Showing 7 changed files with 590 additions and 1 deletion.
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ember-glimmer-allow-backtracking-rerender": null,
"ember-testing-resume-test": null,
"ember-factory-for": true,
"ember-no-double-extend": null
"ember-no-double-extend": null,
"ember-routing-router-service": null
}
}
7 changes: 7 additions & 0 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import ApplicationInstance from './application-instance';
import { privatize as P } from 'container';
import Engine from './engine';
import { setupApplicationRegistry } from 'ember-glimmer';
import { RouterService } from 'ember-routing';
import { isFeatureEnabled } from 'ember-metal';

let librariesRegistered = false;

Expand Down Expand Up @@ -1037,6 +1039,11 @@ function commonSetupRegistry(registry) {
registry.register('location:none', NoneLocation);

registry.register(P`-bucket-cache:main`, BucketCache);

if (isFeatureEnabled('ember-routing-router-service')) {
registry.register('service:router', RouterService);
registry.injection('service:router', 'router', 'router:main');
}
}

function registerLibraries() {
Expand Down
1 change: 1 addition & 0 deletions packages/ember-routing/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export { default as Router } from './system/router';
export { default as Route } from './system/route';
export { default as QueryParams } from './system/query_params';
export { default as RoutingService } from './services/routing';
export { default as RouterService } from './services/router';
export { default as BucketCache } from './system/cache';
49 changes: 49 additions & 0 deletions packages/ember-routing/lib/services/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
@module ember
@submodule ember-routing
*/

import {
Service,
readOnly
} from 'ember-runtime';
import { get } from 'ember-metal';
import RouterDSL from '../system/dsl';

/**
The Router service is the public API that provides component/view layer
access to the router.
@public
@class RouterService
@category ember-routing-router-service
*/
const RouterService = Service.extend({
currentRouteName: readOnly('router.currentRouteName'),
currentURL: readOnly('router.currentURL'),
location: readOnly('router.location'),
rootURL: readOnly('router.rootURL'),

/**
Transition the application into another route. The route may
be either a single route or route path:
See [Route.transitionTo](http://emberjs.com/api/classes/Ember.Route.html#method_transitionTo) for more info.
@method transitionTo
@category ember-routing-router-service
@param {String} name the name of the route or a URL
@param {...Object} models the model(s) or identifier(s) to be used while
transitioning to the route.
@param {Object} [options] optional hash with a queryParams property
containing a mapping of query parameters
@return {Transition} the transition object associated with this
attempted transition
@public
*/
transitionTo() {
this.router.transitionTo(...arguments);
}
});

export default RouterService;
8 changes: 8 additions & 0 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ const EmberRouter = EmberObject.extend(Evented, {
init() {
this._super(...arguments);

this.currentURL = null;
this.currentRouteName = null;
this.currentPath = null;

this._qpCache = new EmptyObject();
this._resetQueuedQueryParameterChanges();
this._handledErrors = dictionary(null);
Expand Down Expand Up @@ -629,6 +633,7 @@ const EmberRouter = EmberObject.extend(Evented, {

let doUpdateURL = function() {
location.setURL(lastURL);
set(emberRouter, 'currentURL', lastURL);
};

router.updateURL = function(path) {
Expand All @@ -639,6 +644,7 @@ const EmberRouter = EmberObject.extend(Evented, {
if (location.replaceURL) {
let doReplaceURL = function() {
location.replaceURL(lastURL);
set(emberRouter, 'currentURL', lastURL);
};

router.replaceURL = function(path) {
Expand Down Expand Up @@ -1291,9 +1297,11 @@ function updatePaths(router) {

let path = EmberRouter._routePath(infos);
let currentRouteName = infos[infos.length - 1].name;
let currentURL = router.get('location').getURL();

set(router, 'currentPath', path);
set(router, 'currentRouteName', currentRouteName);
set(router, 'currentURL', currentURL);

let appController = getOwner(router).lookup('controller:application');

Expand Down
Loading

0 comments on commit 7daa911

Please sign in to comment.