Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/@ember/-internals/deprecations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ export const DEPRECATIONS = {
until: '8.0.0',
url: 'https://deprecations.emberjs.com/id/deprecate-ember-utils',
}),
DEPRECATE_COMPUTED_MACROS: deprecation({
id: 'deprecate-computed-macros',
for: 'ember-source',
since: { available: '7.5.0' },
until: '9.0.0',
url: 'https://deprecations.emberjs.com/id/deprecate-computed-macros',
}),
};

export function deprecateUntil(message: string, deprecation: DeprecationObject) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class _LinkTo extends InternalComponent {

// consume the current router state so we invalidate when QP changes
// TODO: can we narrow this down to QP changes only?
consumeTag(tagFor(routing, 'currentState'));
consumeTag(tagFor(routing.router, 'currentState'));

if (DEBUG) {
try {
Expand Down Expand Up @@ -417,7 +417,7 @@ class _LinkTo extends InternalComponent {

// GH #17963
private currentRouteCache = createCache<Maybe<string>>(() => {
consumeTag(tagFor(this.routing, 'currentState'));
consumeTag(tagFor(this.routing.router, 'currentState'));
return untrack(() => this.routing.currentRouteName);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
equalsElement,
runTask,
defineSimpleModifier,
expectDeprecation,
testUnless,
} from 'internal-test-helpers';
import { DEPRECATIONS } from '@ember/-internals/deprecations';

import { tracked } from '@ember/-internals/metal';
import { alias } from '@ember/object/computed';
Expand Down Expand Up @@ -1571,7 +1574,12 @@ moduleFor(
this.assertText('3');
}

['@test ensure aliases are watched properly [GH#17243]']() {
[`${testUnless(DEPRECATIONS.DEPRECATE_COMPUTED_MACROS.isRemoved)} @test ensure aliases are watched properly [GH#17243]`]() {
expectDeprecation(
/from `@ember\/object\/computed` is deprecated/,
DEPRECATIONS.DEPRECATE_COMPUTED_MACROS.isEnabled
);

let fooInstance, barInstance;

let FooComponent = class extends GlimmerComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,12 @@ class DynamicContentTest extends RenderingTestCase {
this.assertInvariants();
}

['@test it can render a readOnly property of a path']() {
[`${testUnless(DEPRECATIONS.DEPRECATE_COMPUTED_MACROS.isRemoved)} @test it can render a readOnly property of a path`]() {
expectDeprecation(
/from `@ember\/object\/computed` is deprecated/,
DEPRECATIONS.DEPRECATE_COMPUTED_MACROS.isEnabled
);

let Messenger = class extends EmberObject {
@readOnly('a.b.c')
message;
Expand Down

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole file gets to be deleted when we get rid of array proxy, so I don't super care to move computed and observer out of here

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ArrayProxy from '@ember/array/proxy';
import EmberObject, { observer } from '@ember/object';
import { oneWay as reads, not } from '@ember/object/computed';
import EmberObject, { computed, observer } from '@ember/object';
import { oneWay as reads } from '@ember/object/computed';
import { A as a } from '@ember/array';
import {
moduleFor,
Expand Down Expand Up @@ -39,8 +39,10 @@ moduleFor(
assert
) {
let proxy = class extends ArrayProxy {
@not('length')
isEmpty;
@computed('length')
get isEmpty() {
return !this.length;
}
}.create({
content: a([1, 2, 3]),
});
Expand Down Expand Up @@ -186,6 +188,11 @@ moduleFor(
async [`${testUnless(DEPRECATIONS.DEPRECATE_ARRAY_PROXY.isRemoved)} @test array proxy + aliasedProperty complex test`](
assert
) {
expectDeprecation(
/from `@ember\/object\/computed` is deprecated/,
DEPRECATIONS.DEPRECATE_COMPUTED_MACROS.isEnabled
);

let aCalled, bCalled, cCalled, dCalled, eCalled;

aCalled = bCalled = cCalled = dCalled = eCalled = 0;
Expand Down
17 changes: 16 additions & 1 deletion packages/@ember/object/computed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
export { ComputedProperty as default } from '@ember/-internals/metal/lib/computed';
export { default as expandProperties } from '@ember/-internals/metal/lib/expand_properties';
export { default as alias } from '@ember/-internals/metal/lib/alias';

import { assert } from '@ember/debug';
import internalAlias, { type AliasDecorator } from '@ember/-internals/metal/lib/alias';
import { isDecoratorCall } from '@ember/-internals/metal/lib/decorator';
import { deprecateComputedMacro } from './lib/computed/computed_macros';

export function alias(altKey: string): AliasDecorator {
assert(
'You attempted to use @alias as a decorator directly, but it requires a `altKey` parameter',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('alias');

return internalAlias(altKey);
}

export {
empty,
Expand Down
45 changes: 45 additions & 0 deletions packages/@ember/object/lib/computed/computed_macros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import { DEPRECATIONS, deprecateUntil } from '@ember/-internals/deprecations';
@module @ember/object
*/

export function deprecateComputedMacro(name: string) {
deprecateUntil(
`\`${name}\` from \`@ember/object/computed\` is deprecated. Use a getter instead.`,
DEPRECATIONS.DEPRECATE_COMPUTED_MACROS
);
}

function expandPropertiesToArray(predicateName: string, properties: string[]) {
let expandedProperties: string[] = [];

Expand Down Expand Up @@ -43,6 +50,8 @@ function generateComputedWithPredicate(name: string, predicate: (value: unknown)
!isDecoratorCall(properties)
);

deprecateComputedMacro(name);

let dependentKeys = expandPropertiesToArray(name, properties);

let computedFunc = computed(...dependentKeys, function () {
Expand Down Expand Up @@ -250,13 +259,16 @@ export function none(dependentKey: string) {
@return {ComputedProperty} computed property which returns inverse of the
original value for property
@public
@deprecated Use a getter instead.
*/
export function not(dependentKey: string) {
assert(
'You attempted to use @not as a decorator directly, but it requires a `dependentKey` parameter',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('not');

return computed(dependentKey, function () {
return !get(this, dependentKey);
});
Expand Down Expand Up @@ -298,13 +310,16 @@ export function not(dependentKey: string) {
@return {ComputedProperty} computed property which converts to boolean the
original value for property
@public
@deprecated Use a getter instead.
*/
export function bool(dependentKey: string) {
assert(
'You attempted to use @bool as a decorator directly, but it requires a `dependentKey` parameter',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('bool');

return computed(dependentKey, function () {
return Boolean(get(this, dependentKey));
});
Expand Down Expand Up @@ -344,13 +359,16 @@ export function bool(dependentKey: string) {
@return {ComputedProperty} computed property which match the original value
for property against a given RegExp
@public
@deprecated Use a getter instead.
*/
export function match(dependentKey: string, regexp: RegExp) {
assert(
'You attempted to use @match as a decorator directly, but it requires `dependentKey` and `regexp` parameters',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('match');

return computed(dependentKey, function () {
let value = get(this, dependentKey);
return regexp.test(value);
Expand Down Expand Up @@ -390,13 +408,16 @@ export function match(dependentKey: string, regexp: RegExp) {
@return {ComputedProperty} computed property which returns true if the
original value for property is equal to the given value.
@public
@deprecated Use a getter instead.
*/
export function equal(dependentKey: string, value: unknown) {
assert(
'You attempted to use @equal as a decorator directly, but it requires `dependentKey` and `value` parameter',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('equal');

return computed(dependentKey, function () {
return get(this, dependentKey) === value;
});
Expand Down Expand Up @@ -435,13 +456,16 @@ export function equal(dependentKey: string, value: unknown) {
@return {ComputedProperty} computed property which returns true if the
original value for property is greater than given value.
@public
@deprecated Use a getter instead.
*/
export function gt(dependentKey: string, value: number) {
assert(
'You attempted to use @gt as a decorator directly, but it requires `dependentKey` and `value` parameters',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('gt');

return computed(dependentKey, function () {
return get(this, dependentKey) > value;
});
Expand Down Expand Up @@ -480,13 +504,16 @@ export function gt(dependentKey: string, value: number) {
@return {ComputedProperty} computed property which returns true if the
original value for property is greater or equal then given value.
@public
@deprecated Use a getter instead.
*/
export function gte(dependentKey: string, value: number) {
assert(
'You attempted to use @gte as a decorator directly, but it requires `dependentKey` and `value` parameters',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('gte');

return computed(dependentKey, function () {
return get(this, dependentKey) >= value;
});
Expand Down Expand Up @@ -525,13 +552,16 @@ export function gte(dependentKey: string, value: number) {
@return {ComputedProperty} computed property which returns true if the
original value for property is less then given value.
@public
@deprecated Use a getter instead.
*/
export function lt(dependentKey: string, value: number) {
assert(
'You attempted to use @lt as a decorator directly, but it requires `dependentKey` and `value` parameters',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('lt');

return computed(dependentKey, function () {
return get(this, dependentKey) < value;
});
Expand Down Expand Up @@ -570,13 +600,16 @@ export function lt(dependentKey: string, value: number) {
@return {ComputedProperty} computed property which returns true if the
original value for property is less or equal than given value.
@public
@deprecated Use a getter instead.
*/
export function lte(dependentKey: string, value: number) {
assert(
'You attempted to use @lte as a decorator directly, but it requires `dependentKey` and `value` parameters',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('lte');

return computed(dependentKey, function () {
return get(this, dependentKey) <= value;
});
Expand Down Expand Up @@ -625,6 +658,7 @@ export function lte(dependentKey: string, value: number) {
@return {ComputedProperty} computed property which performs a logical `and` on
the values of all the original values for properties.
@public
@deprecated Use a getter instead.
*/
export const and = generateComputedWithPredicate('and', (value) => value);

Expand Down Expand Up @@ -668,6 +702,7 @@ export const and = generateComputedWithPredicate('and', (value) => value);
@return {ComputedProperty} computed property which performs a logical `or` on
the values of all the original values for properties.
@public
@deprecated Use a getter instead.
*/
export const or = generateComputedWithPredicate('or', (value) => !value);

Expand Down Expand Up @@ -704,6 +739,7 @@ export const or = generateComputedWithPredicate('or', (value) => !value);
@return {ComputedProperty} computed property which creates an alias to the
original value for property.
@public
@deprecated Use a getter instead.
*/

/**
Expand Down Expand Up @@ -744,13 +780,16 @@ export const or = generateComputedWithPredicate('or', (value) => !value);
@return {ComputedProperty} computed property which creates a one way computed
property to the original value for property.
@public
@deprecated Use a getter instead.
*/
export function oneWay(dependentKey: string) {
assert(
'You attempted to use @oneWay as a decorator directly, but it requires a `dependentKey` parameter',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('oneWay');

return alias(dependentKey).oneWay() as FieldDecorator;
}

Expand Down Expand Up @@ -808,13 +847,16 @@ export function oneWay(dependentKey: string) {
property to the original value for property.
@since 1.5.0
@public
@deprecated Use a getter instead.
*/
export function readOnly(dependentKey: string) {
assert(
'You attempted to use @readOnly as a decorator directly, but it requires a `dependentKey` parameter',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('readOnly');

return alias(dependentKey).readOnly() as FieldDecorator;
}

Expand Down Expand Up @@ -852,13 +894,16 @@ export function readOnly(dependentKey: string) {
deprecation to the original value for property.
@since 1.7.0
@public
@deprecated Use a getter instead.
*/
export function deprecatingAlias(dependentKey: string, options: DeprecationOptions) {
assert(
'You attempted to use @deprecatingAlias as a decorator directly, but it requires `dependentKey` and `options` parameters',
!isDecoratorCall(Array.prototype.slice.call(arguments))
);

deprecateComputedMacro('deprecatingAlias');

return computed(dependentKey, {
get(key) {
deprecate(
Expand Down
Loading
Loading