-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE Router Service] Deprecate touching transition state #17038
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,14 @@ import { once } from '@ember/runloop'; | |
import { classify } from '@ember/string'; | ||
import { DEBUG } from '@glimmer/env'; | ||
import { TemplateFactory } from '@glimmer/opcode-compiler'; | ||
import { InternalRouteInfo, Route as IRoute, Transition, TransitionState } from 'router_js'; | ||
import { | ||
InternalRouteInfo, | ||
PARAMS_SYMBOL, | ||
Route as IRoute, | ||
STATE_SYMBOL, | ||
Transition, | ||
TransitionState, | ||
} from 'router_js'; | ||
import { | ||
calculateCacheKey, | ||
normalizeControllerQueryParams, | ||
|
@@ -219,7 +226,7 @@ class Route extends EmberObject implements IRoute { | |
} | ||
|
||
let transition = this._router._routerMicrolib.activeTransition; | ||
let state = transition ? transition.state : this._router._routerMicrolib.state; | ||
let state = transition ? transition[STATE_SYMBOL] : this._router._routerMicrolib.state; | ||
|
||
let fullName = route.fullRouteName; | ||
let params = assign({}, state!.params[fullName]); | ||
|
@@ -899,10 +906,10 @@ class Route extends EmberObject implements IRoute { | |
|
||
if (transition) { | ||
// Update the model dep values used to calculate cache keys. | ||
stashParamNames(this._router, transition.state!.routeInfos); | ||
stashParamNames(this._router, transition[STATE_SYMBOL]!.routeInfos); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. svelting? |
||
|
||
let cache = this._bucketCache; | ||
let params = transition.params; | ||
let params = transition[PARAMS_SYMBOL]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Svelting? |
||
let allParams = queryParams.propertyNames; | ||
|
||
allParams.forEach((prop: string) => { | ||
|
@@ -914,7 +921,7 @@ class Route extends EmberObject implements IRoute { | |
set(controller, prop, value); | ||
}); | ||
|
||
let qpValues = getQueryParamsFor(this, transition.state!); | ||
let qpValues = getQueryParamsFor(this, transition[STATE_SYMBOL]!); | ||
setProperties(controller, qpValues); | ||
} | ||
|
||
|
@@ -1152,7 +1159,7 @@ class Route extends EmberObject implements IRoute { | |
if (transition.resolveIndex < 1) { | ||
return; | ||
} | ||
return transition.state!.routeInfos[transition.resolveIndex - 1].context; | ||
return transition[STATE_SYMBOL]!.routeInfos[transition.resolveIndex - 1].context; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Svelting? What do we return after the deprecation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No where this is returning the |
||
} | ||
} | ||
|
||
|
@@ -2432,7 +2439,7 @@ Route.reopen(ActionHandler, Evented, { | |
return; | ||
} | ||
|
||
let routeInfos = transition.state!.routeInfos; | ||
let routeInfos = transition[STATE_SYMBOL]!.routeInfos; | ||
let router = this._router; | ||
let qpMeta = router._queryParamsFor(routeInfos); | ||
let changes = router._qpUpdates; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { getOwner, Owner } from '@ember/-internals/owner'; | |
import { A as emberA, Evented, Object as EmberObject, typeOf } from '@ember/-internals/runtime'; | ||
import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; | ||
import { assert, deprecate, info } from '@ember/debug'; | ||
import { HANDLER_INFOS, ROUTER_EVENTS } from '@ember/deprecated-features'; | ||
import { HANDLER_INFOS, ROUTER_EVENTS, TRANSITION_STATE } from '@ember/deprecated-features'; | ||
import EmberError from '@ember/error'; | ||
import { assign } from '@ember/polyfills'; | ||
import { cancel, once, run, scheduleOnce } from '@ember/runloop'; | ||
|
@@ -27,6 +27,9 @@ import Router, { | |
InternalRouteInfo, | ||
InternalTransition, | ||
logAbort, | ||
PARAMS_SYMBOL, | ||
QUERY_PARAMS_SYMBOL, | ||
STATE_SYMBOL, | ||
Transition, | ||
TransitionError, | ||
TransitionState, | ||
|
@@ -73,6 +76,56 @@ function defaultWillTransition( | |
} | ||
} | ||
|
||
if (TRANSITION_STATE) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. svelte There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a svelte import. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DOH! |
||
Object.defineProperty(InternalTransition.prototype, 'state', { | ||
get() { | ||
if (EMBER_ROUTING_ROUTER_SERVICE) { | ||
deprecate( | ||
'You attempted to read "transition.state" which is a private API. You should read the `RouteInfo` object on "transition.to" or "transition.from" which has the public state on it.', | ||
false, | ||
{ | ||
id: 'transition-state', | ||
until: '3.9.0', | ||
} | ||
); | ||
} | ||
return this[STATE_SYMBOL]; | ||
}, | ||
}); | ||
|
||
Object.defineProperty(InternalTransition.prototype, 'queryParams', { | ||
get() { | ||
if (EMBER_ROUTING_ROUTER_SERVICE) { | ||
deprecate( | ||
'You attempted to read "transition.queryParams" which is a private API. You should read the `RouteInfo` object on "transition.to" or "transition.from" which has the queryParams on it.', | ||
false, | ||
{ | ||
id: 'transition-state', | ||
until: '3.9.0', | ||
} | ||
); | ||
} | ||
return this[QUERY_PARAMS_SYMBOL]; | ||
}, | ||
}); | ||
|
||
Object.defineProperty(InternalTransition.prototype, 'params', { | ||
get() { | ||
if (EMBER_ROUTING_ROUTER_SERVICE) { | ||
deprecate( | ||
'You attempted to read "transition.params" which is a private API. You should read the `RouteInfo` object on "transition.to" or "transition.from" which has the params on it.', | ||
false, | ||
{ | ||
id: 'transition-state', | ||
until: '3.9.0', | ||
} | ||
); | ||
} | ||
return this[PARAMS_SYMBOL]; | ||
}, | ||
}); | ||
} | ||
|
||
if (HANDLER_INFOS) { | ||
Object.defineProperty(InternalRouteInfo.prototype, 'handler', { | ||
get() { | ||
|
@@ -944,7 +997,7 @@ class EmberRouter extends EmberObject { | |
|
||
let unchangedQPs = {}; | ||
let qpUpdates = this._qpUpdates; | ||
let params = this._routerMicrolib.activeTransition.queryParams; | ||
let params = this._routerMicrolib.activeTransition[QUERY_PARAMS_SYMBOL]; | ||
for (let key in params) { | ||
if (!qpUpdates.has(key)) { | ||
unchangedQPs[key] = params[key]; | ||
|
@@ -1203,7 +1256,7 @@ class EmberRouter extends EmberObject { | |
let targetState = new RouterState( | ||
this, | ||
this._routerMicrolib, | ||
this._routerMicrolib.activeTransition.state! | ||
this._routerMicrolib.activeTransition[STATE_SYMBOL]! | ||
); | ||
this.set('targetState', targetState); | ||
|
||
|
@@ -1668,7 +1721,7 @@ EmberRouter.reopenClass({ | |
}); | ||
|
||
function didBeginTransition(transition: Transition, router: EmberRouter) { | ||
let routerState = new RouterState(router, router._routerMicrolib, transition.state!); | ||
let routerState = new RouterState(router, router._routerMicrolib, transition[STATE_SYMBOL]!); | ||
|
||
if (!router.currentState) { | ||
router.set('currentState', routerState); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { RouterTestCase, moduleFor } from 'internal-test-helpers'; | ||
import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; | ||
|
||
if (EMBER_ROUTING_ROUTER_SERVICE) { | ||
moduleFor( | ||
'Deprecated Transition State', | ||
class extends RouterTestCase { | ||
'@test touching transition.state is deprecated'(assert) { | ||
assert.expect(1); | ||
return this.visit('/').then(() => { | ||
this.routerService.on('routeWillChange', transition => { | ||
expectDeprecation(() => { | ||
transition.state; | ||
}, 'You attempted to read "transition.state" which is a private API. You should read the `RouteInfo` object on "transition.to" or "transition.from" which has the public state on it.'); | ||
}); | ||
return this.routerService.transitionTo('/child'); | ||
}); | ||
} | ||
|
||
'@test touching transition.queryParams is deprecated'(assert) { | ||
assert.expect(1); | ||
return this.visit('/').then(() => { | ||
this.routerService.on('routeWillChange', transition => { | ||
expectDeprecation(() => { | ||
transition.queryParams; | ||
}, 'You attempted to read "transition.queryParams" which is a private API. You should read the `RouteInfo` object on "transition.to" or "transition.from" which has the queryParams on it.'); | ||
}); | ||
return this.routerService.transitionTo('/child'); | ||
}); | ||
} | ||
|
||
'@test touching transition.params is deprecated'(assert) { | ||
assert.expect(1); | ||
return this.visit('/').then(() => { | ||
this.routerService.on('routeWillChange', transition => { | ||
expectDeprecation(() => { | ||
transition.params; | ||
}, 'You attempted to read "transition.params" which is a private API. You should read the `RouteInfo` object on "transition.to" or "transition.from" which has the params on it.'); | ||
}); | ||
return this.routerService.transitionTo('/child'); | ||
}); | ||
} | ||
} | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need svelting here I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might be confused.
transition.state
is still needed internally but access to it from application code should be deprecated and we just tell people to use theRouteInfo
. All of these symbols are just allowing the integration of ember-router and router.js to work. I could have simply renamed the method but I felt that using a faux-symbol may deter people further. In the future we should just make these real symbols.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thank you!
some of the comments though are specifically about deprecations, and should still apply