Skip to content

Commit

Permalink
Renaming Ember.router to Ember._routerMicrolib to disambiguate
Browse files Browse the repository at this point in the history
references.
  • Loading branch information
scalvert committed Feb 14, 2017
1 parent cdcd385 commit ad82fa9
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 103 deletions.
4 changes: 2 additions & 2 deletions packages/ember-application/lib/system/application-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ const ApplicationInstance = EngineInstance.extend({
let handleTransitionReject = (error) => {
if (error.error) {
throw error.error;
} else if (error.name === 'TransitionAborted' && router.router.activeTransition) {
return router.router.activeTransition.then(handleTransitionResolve, handleTransitionReject);
} else if (error.name === 'TransitionAborted' && router._routerMicrolib.activeTransition) {
return router._routerMicrolib.activeTransition.then(handleTransitionResolve, handleTransitionReject);
} else if (error.name === 'TransitionAborted') {
throw new Error(error.message);
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/ember-metal/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {
debugSeal,
debugFreeze
} from './debug';
export { deprecateProperty } from './deprecate_property';
export {
instrument,
flaggedInstrument,
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-routing/lib/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default Service.extend({

generateURL(routeName, models, queryParams) {
let router = get(this, 'router');
if (!router.router) { return; }
if (!router._routerMicrolib) { return; }

let visibleQueryParams = {};
assign(visibleQueryParams, queryParams);
Expand All @@ -72,7 +72,7 @@ export default Service.extend({
isActiveForRoute(contexts, queryParams, routeName, routerState, isCurrentWhenSpecified) {
let router = get(this, 'router');

let handlers = router.router.recognizer.handlersFor(routeName);
let handlers = router._routerMicrolib.recognizer.handlersFor(routeName);
let leafName = handlers[handlers.length - 1].handler;
let maximumContexts = numberOfContextsAcceptedByHandler(routeName, handlers);

Expand Down
18 changes: 9 additions & 9 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
return {};
}

let transition = this.router.router.activeTransition;
let state = transition ? transition.state : this.router.router.state;
let transition = this.router._routerMicrolib.activeTransition;
let state = transition ? transition.state : this.router._routerMicrolib.state;

let fullName = route.fullRouteName;
let params = assign({}, state.params[fullName]);
Expand Down Expand Up @@ -1180,7 +1180,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
@public
*/
refresh() {
return this.router.router.refresh(this);
return this.router._routerMicrolib.refresh(this);
},

/**
Expand Down Expand Up @@ -1277,7 +1277,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
@public
*/
send(...args) {
if ((this.router && this.router.router) || !isTesting()) {
if ((this.router && this.router._routerMicrolib) || !isTesting()) {
this.router.send(...args);
} else {
let name = args[0];
Expand Down Expand Up @@ -1888,14 +1888,14 @@ let Route = EmberObject.extend(ActionHandler, Evented, {

// Only change the route name when there is an active transition.
// Otherwise, use the passed in route name.
if (owner.routable && this.router && this.router.router.activeTransition) {
if (owner.routable && this.router && this.router._routerMicrolib.activeTransition) {
name = getEngineRouteName(owner, _name);
} else {
name = _name;
}

let route = getOwner(this).lookup(`route:${name}`);
let transition = this.router ? this.router.router.activeTransition : null;
let transition = this.router ? this.router._routerMicrolib.activeTransition : null;

// If we are mid-transition, we want to try and look up
// resolved parent contexts on the current transitionEvent.
Expand Down Expand Up @@ -2165,12 +2165,12 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
parentView = parentView && parentView.replace(/\//g, '.');
outletName = outletName || 'main';
this._disconnectOutlet(outletName, parentView);
for (let i = 0; i < this.router.router.currentHandlerInfos.length; i++) {
for (let i = 0; i < this.router._routerMicrolib.currentHandlerInfos.length; i++) {
// This non-local state munging is sadly necessary to maintain
// backward compatibility with our existing semantics, which allow
// any route to disconnectOutlet things originally rendered by any
// other route. This should all get cut in 2.0.
this.router.router
this.router._routerMicrolib
.currentHandlerInfos[i]
.handler._disconnectOutlet(outletName, parentView);
}
Expand Down Expand Up @@ -2228,7 +2228,7 @@ Route.reopenClass({
});

function parentRoute(route) {
let handlerInfo = handlerInfoFor(route, route.router.router.state.handlerInfos, -1);
let handlerInfo = handlerInfoFor(route, route.router._routerMicrolib.state.handlerInfos, -1);
return handlerInfo && handlerInfo.handler;
}

Expand Down
86 changes: 46 additions & 40 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
computed,
run,
runInDebug,
deprecate
deprecate,
deprecateProperty
} from 'ember-metal';
import {
Object as EmberObject,
Expand Down Expand Up @@ -92,11 +93,11 @@ const EmberRouter = EmberObject.extend(Evented, {
rootURL: '/',

_initRouterJs() {
let router = this.router = new Router();
router.triggerEvent = triggerEvent;
let routerMicrolib = this._routerMicrolib = new Router();
routerMicrolib.triggerEvent = triggerEvent;

router._triggerWillChangeContext = K;
router._triggerWillLeave = K;
routerMicrolib._triggerWillChangeContext = K;
routerMicrolib._triggerWillLeave = K;

let dslCallbacks = this.constructor.dslCallbacks || [K];
let dsl = this._buildDSL();
Expand All @@ -109,11 +110,11 @@ const EmberRouter = EmberObject.extend(Evented, {

runInDebug(() => {
if (get(this, 'namespace.LOG_TRANSITIONS_INTERNAL')) {
router.log = Logger.debug;
routerMicrolib.log = Logger.debug;
}
});

router.map(dsl.generate());
routerMicrolib.map(dsl.generate());
},

_buildDSL() {
Expand Down Expand Up @@ -210,7 +211,6 @@ const EmberRouter = EmberObject.extend(Evented, {
this._initRouterJs();
this._setupLocation();

let router = this.router;
let location = get(this, 'location');

// Allow the Location class to cancel the router setup while it refreshes
Expand All @@ -219,7 +219,7 @@ const EmberRouter = EmberObject.extend(Evented, {
return false;
}

this._setupRouter(router, location);
this._setupRouter(location);

location.onUpdateURL(url => {
this.handleURL(url);
Expand Down Expand Up @@ -281,7 +281,7 @@ const EmberRouter = EmberObject.extend(Evented, {
// to create another this._toplevelView (and leak the renderer)
if (this.isDestroying || this.isDestroyed) { return; }

let handlerInfos = this.router.currentHandlerInfos;
let handlerInfos = this._routerMicrolib.currentHandlerInfos;
let route;
let defaultParentState;
let liveRoutes = null;
Expand Down Expand Up @@ -356,7 +356,7 @@ const EmberRouter = EmberObject.extend(Evented, {
},

_doURLTransition(routerJsMethod, url) {
let transition = this.router[routerJsMethod](url || '/');
let transition = this._routerMicrolib[routerJsMethod](url || '/');
didBeginTransition(transition, this);
return transition;
},
Expand Down Expand Up @@ -395,12 +395,12 @@ const EmberRouter = EmberObject.extend(Evented, {
},

intermediateTransitionTo() {
this.router.intermediateTransitionTo(...arguments);
this._routerMicrolib.intermediateTransitionTo(...arguments);

updatePaths(this);

runInDebug(() => {
let infos = this.router.currentHandlerInfos;
let infos = this._routerMicrolib.currentHandlerInfos;
if (get(this, 'namespace').LOG_TRANSITIONS) {
Logger.log(`Intermediate-transitioned into '${EmberRouter._routePath(infos)}'`);
}
Expand All @@ -412,7 +412,7 @@ const EmberRouter = EmberObject.extend(Evented, {
},

generate() {
let url = this.router.generate(...arguments);
let url = this._routerMicrolib.generate(...arguments);
return this.location.formatURL(url);
},

Expand All @@ -425,8 +425,7 @@ const EmberRouter = EmberObject.extend(Evented, {
@private
*/
isActive(routeName) {
let router = this.router;
return router.isActive(...arguments);
return this._routerMicrolib.isActive(...arguments);
},

/**
Expand All @@ -447,7 +446,7 @@ const EmberRouter = EmberObject.extend(Evented, {
},

send(name, context) {
this.router.trigger(...arguments);
this._routerMicrolib.trigger(...arguments);
},

/**
Expand All @@ -458,7 +457,7 @@ const EmberRouter = EmberObject.extend(Evented, {
@private
*/
hasRoute(route) {
return this.router.hasRoute(route);
return this._routerMicrolib.hasRoute(route);
},

/**
Expand All @@ -469,8 +468,8 @@ const EmberRouter = EmberObject.extend(Evented, {
@method reset
*/
reset() {
if (this.router) {
this.router.reset();
if (this._routerMicrolib) {
this._routerMicrolib.reset();
}
},

Expand Down Expand Up @@ -633,19 +632,20 @@ const EmberRouter = EmberObject.extend(Evented, {
};
},

_setupRouter(router, location) {
_setupRouter(location) {
let lastURL;
let emberRouter = this;
let routerMicrolib = this._routerMicrolib;

router.getHandler = this._getHandlerFunction();
router.getSerializer = this._getSerializerFunction();
routerMicrolib.getHandler = this._getHandlerFunction();
routerMicrolib.getSerializer = this._getSerializerFunction();

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

router.updateURL = path => {
routerMicrolib.updateURL = path => {
lastURL = path;
run.once(doUpdateURL);
};
Expand All @@ -656,17 +656,17 @@ const EmberRouter = EmberObject.extend(Evented, {
set(emberRouter, 'currentURL', lastURL);
};

router.replaceURL = path => {
routerMicrolib.replaceURL = path => {
lastURL = path;
run.once(doReplaceURL);
};
}

router.didTransition = infos => {
routerMicrolib.didTransition = infos => {
emberRouter.didTransition(infos);
};

router.willTransition = (oldInfos, newInfos, transition) => {
routerMicrolib.willTransition = (oldInfos, newInfos, transition) => {
emberRouter.willTransition(oldInfos, newInfos, transition);
};
},
Expand Down Expand Up @@ -770,8 +770,8 @@ const EmberRouter = EmberObject.extend(Evented, {
},

_doTransition(_targetRouteName, models, _queryParams) {
let targetRouteName = _targetRouteName || getActiveTargetName(this.router);
assert(`The route ${targetRouteName} was not found`, targetRouteName && this.router.hasRoute(targetRouteName));
let targetRouteName = _targetRouteName || getActiveTargetName(this._routerMicrolib);
assert(`The route ${targetRouteName} was not found`, targetRouteName && this._routerMicrolib.hasRoute(targetRouteName));

let queryParams = {};

Expand All @@ -781,7 +781,7 @@ const EmberRouter = EmberObject.extend(Evented, {
this._prepareQueryParams(targetRouteName, models, queryParams);

let transitionArgs = routeArgs(targetRouteName, models, queryParams);
let transition = this.router.transitionTo(...transitionArgs);
let transition = this._routerMicrolib.transitionTo(...transitionArgs);

didBeginTransition(transition, this);

Expand All @@ -791,13 +791,13 @@ const EmberRouter = EmberObject.extend(Evented, {
_processActiveTransitionQueryParams(targetRouteName, models, queryParams, _queryParams) {
// merge in any queryParams from the active transition which could include
// queryParams from the url on initial load.
if (!this.router.activeTransition) { return; }
if (!this._routerMicrolib.activeTransition) { return; }

var unchangedQPs = {};
var qpUpdates = this._qpUpdates || {};
for (var key in this.router.activeTransition.queryParams) {
for (var key in this._routerMicrolib.activeTransition.queryParams) {
if (!qpUpdates[key]) {
unchangedQPs[key] = this.router.activeTransition.queryParams[key];
unchangedQPs[key] = this._routerMicrolib.activeTransition.queryParams[key];
}
}

Expand Down Expand Up @@ -985,16 +985,16 @@ const EmberRouter = EmberObject.extend(Evented, {
targetState: null,

_handleSlowTransition(transition, originRoute) {
if (!this.router.activeTransition) {
if (!this._routerMicrolib.activeTransition) {
// Don't fire an event if we've since moved on from
// the transition that put us in a loading state.
return;
}

this.set('targetState', RouterState.create({
emberRouter: this,
routerJs: this.router,
routerJsState: this.router.activeTransition.state
routerJs: this._routerMicrolib,
routerJsState: this._routerMicrolib.activeTransition.state
}));

transition.trigger(true, 'loading', transition, originRoute);
Expand Down Expand Up @@ -1283,8 +1283,8 @@ export function triggerEvent(handlerInfos, ignoreFailure, args) {
}

function calculatePostTransitionState(emberRouter, leafRouteName, contexts) {
let routerjs = emberRouter.router;
let state = routerjs.applyIntent(leafRouteName, contexts);
let routerMicrolib = emberRouter._routerMicrolib;
let state = routerMicrolib.applyIntent(leafRouteName, contexts);
let handlerInfos = state.handlerInfos;
let params = state.params;

Expand All @@ -1302,7 +1302,7 @@ function calculatePostTransitionState(emberRouter, leafRouteName, contexts) {
}

function updatePaths(router) {
let infos = router.router.currentHandlerInfos;
let infos = router._routerMicrolib.currentHandlerInfos;
if (infos.length === 0) { return; }

let path = EmberRouter._routePath(infos);
Expand Down Expand Up @@ -1429,7 +1429,7 @@ EmberRouter.reopenClass({
function didBeginTransition(transition, router) {
let routerState = RouterState.create({
emberRouter: router,
routerJs: router.router,
routerJs: router._routerMicrolib,
routerJsState: transition.state
});

Expand Down Expand Up @@ -1563,4 +1563,10 @@ function representEmptyRoute(liveRoutes, defaultParentState, route) {
}
}

deprecateProperty(EmberRouter.prototype, 'router', '_routerMicrolib', {
id: 'ember-router.router',
until: '2.16',
url: 'http://emberjs.com/deprecations/v2.x/#toc_ember-router-router-renamed-to-ember-router-_routerMicrolib'
});

export default EmberRouter;
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function stashParamNames(router, handlerInfos) {
// on whether a URL transition or named transition is happening.
// Hopefully we can remove this in the future.
let targetRouteName = handlerInfos[handlerInfos.length - 1].name;
let recogHandlers = router.router.recognizer.handlersFor(targetRouteName);
let recogHandlers = router._routerMicrolib.recognizer.handlersFor(targetRouteName);
let dynamicParent = null;

for (let i = 0; i < handlerInfos.length; ++i) {
Expand Down
Loading

0 comments on commit ad82fa9

Please sign in to comment.