Skip to content

Commit

Permalink
Remove computed property overrides
Browse files Browse the repository at this point in the history
This fixes the deprecation warnings described here:
https://deprecations.emberjs.com/v3.x/#toc_computed-property-override

As mentioned by @richard-viney here:
mainmatter#1799 (comment)
  • Loading branch information
backspace authored and marcoow committed Jul 12, 2019
1 parent 6537fcf commit 4addb2c
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 26 deletions.
15 changes: 13 additions & 2 deletions addon/mixins/application-route-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,19 @@ export default Mixin.create({
@default 'index'
@public
*/
routeAfterAuthentication: computed(function() {
return Configuration.routeAfterAuthentication;
routeAfterAuthentication: computed({
get() {
if (this.hasOwnProperty('routeAfterAuthenticationOverride')) {
return this.routeAfterAuthenticationOverride;
} else {
return Configuration.routeAfterAuthentication;
}
},

set(key, value) {
this.routeAfterAuthenticationOverride = value;
return value;
}
}),

init() {
Expand Down
32 changes: 27 additions & 5 deletions addon/mixins/authenticated-route-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,20 @@ export default Mixin.create({
*/
session: service('session'),

_router: computed(function() {
let owner = getOwner(this);
return owner.lookup('service:router') || owner.lookup('router:main');
_router: computed({
get() {
if (this.hasOwnProperty('_routerOverride')) {
return this._routerOverride;
} else {
let owner = getOwner(this);
return owner.lookup('service:router') || owner.lookup('router:main');
}
},

set(key, value) {
this._routerOverride = value;
return value;
}
}),

_isFastBoot: isFastBootCPM(),
Expand All @@ -80,8 +91,19 @@ export default Mixin.create({
@default 'login'
@public
*/
authenticationRoute: computed(function() {
return Configuration.authenticationRoute;
authenticationRoute: computed({
get() {
if (this.hasOwnProperty('authenticationRouteOverride')) {
return this.authenticationRouteOverride;
} else {
return Configuration.authenticationRoute;
}
},

set(key, value) {
this.authenticationRouteOverride = value;
return value;
}
}),

/**
Expand Down
15 changes: 13 additions & 2 deletions addon/mixins/unauthenticated-route-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,19 @@ export default Mixin.create({
@default 'index'
@public
*/
routeIfAlreadyAuthenticated: computed(function() {
return Configuration.routeIfAlreadyAuthenticated;
routeIfAlreadyAuthenticated: computed({
get() {
if (this.hasOwnProperty('routeIfAlreadyAuthenticatedOverride')) {
return this.routeIfAlreadyAuthenticatedOverride;
} else {
return Configuration.routeIfAlreadyAuthenticated;
}
},

set(key, value) {
this.routeIfAlreadyAuthenticatedOverride = value;
return value;
}
}),

/**
Expand Down
42 changes: 32 additions & 10 deletions addon/session-stores/adaptive.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,41 @@ export default Base.extend({

_cookies: service('cookies'),

_fastboot: computed(function() {
let owner = getOwner(this);
_fastboot: computed({
get() {
if (this.hasOwnProperty('_fastbootOverride')) {
return this._fastbootOverride;
} else {
let owner = getOwner(this);

return owner && owner.lookup('service:fastboot');
}
},

return owner && owner.lookup('service:fastboot');
set(key, value) {
this._fastbootOverride = value;
return value;
}
}),

_isLocalStorageAvailable: computed(function() {
try {
localStorage.setItem(LOCAL_STORAGE_TEST_KEY, true);
localStorage.removeItem(LOCAL_STORAGE_TEST_KEY);
return true;
} catch (e) {
return false;
_isLocalStorageAvailable: computed({
get() {
if (this.hasOwnProperty('_isLocalStorageAvailableOverride')) {
return this._isLocalStorageAvailableOverride;
} else {
try {
localStorage.setItem(LOCAL_STORAGE_TEST_KEY, true);
localStorage.removeItem(LOCAL_STORAGE_TEST_KEY);
return true;
} catch (e) {
return false;
}
}
},

set(key, value) {
this._isLocalStorageAvailableOverride = value;
return value;
}
}),

Expand Down
17 changes: 14 additions & 3 deletions addon/session-stores/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,21 @@ export default BaseStore.extend({

_cookies: service('cookies'),

_fastboot: computed(function() {
let owner = getOwner(this);
_fastboot: computed({
get() {
if (this.hasOwnProperty('_fastbootOverride')) {
return this._fastbootOverride;
} else {
let owner = getOwner(this);

return owner && owner.lookup('service:fastboot');
}
},

return owner && owner.lookup('service:fastboot');
set(key, value) {
this._fastbootOverride = value;
return value;
}
}),

_secureCookies() {
Expand Down
15 changes: 13 additions & 2 deletions addon/utils/is-fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import ApplicationInstance from '@ember/application/instance';
* @return {ComputedProperty<boolean>}
*/
export default function isFastBootCPM() {
return computed(function() {
return isFastBoot(getOwner(this));
return computed({
get() {
if (this.hasOwnProperty('isFastBootOverride')) {
return this.isFastBootOverride;
} else {
return isFastBoot(getOwner(this));
}
},

set(key, value) {
this.isFastBootOverride = value;
return value;
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/mixins/authenticated-route-mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('AuthenticatedRouteMixin', () => {
it('does not transition to the authentication route', function() {
route.beforeModel(transition);

expect(route._router.transitionTo).to.not.have.been.calledWith(Configuration.authenticationRoute);
expect(route.get('_router').transitionTo).to.not.have.been.calledWith(Configuration.authenticationRoute);
});
});

Expand All @@ -96,7 +96,7 @@ describe('AuthenticatedRouteMixin', () => {
route.set('authenticationRoute', authenticationRoute);

route.beforeModel(transition);
expect(route._router.transitionTo).to.have.been.calledWith(authenticationRoute);
expect(route.get('_router').transitionTo).to.have.been.calledWith(authenticationRoute);
});

it('sets the redirectTarget cookie in fastboot', function() {
Expand Down

0 comments on commit 4addb2c

Please sign in to comment.