Skip to content
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

[BUGFIX] Ensure tagForProperty works on class constructors #17691

Merged
merged 2 commits into from Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@ember/-internals/metal/lib/decorator.ts
Expand Up @@ -22,8 +22,9 @@ export function isElementDescriptor(
return (
// Ensure we have the right number of args
args.length === 3 &&
// Make sure the target is an object
(typeof maybeTarget === 'object' && maybeTarget !== null) &&
// Make sure the target is a class or object (prototype)
(typeof maybeTarget === 'function' ||
(typeof maybeTarget === 'object' && maybeTarget !== null)) &&
// Make sure the key is a string
typeof maybeKey === 'string' &&
// Make sure the descriptor is the right shape
Expand Down
3 changes: 2 additions & 1 deletion packages/@ember/-internals/metal/lib/tags.ts
Expand Up @@ -22,7 +22,8 @@ function makeTag(): TagWrapper<DirtyableTag> {
}

export function tagForProperty(object: any, propertyKey: string | symbol, _meta?: Meta): Tag {
if (typeof object !== 'object' || object === null) {
let objectType = typeof object;
if (objectType !== 'function' && (objectType !== 'object' || object === null)) {
return CONSTANT_TAG;
}
let meta = _meta === undefined ? metaFor(object) : _meta;
Expand Down
19 changes: 19 additions & 0 deletions packages/@ember/-internals/metal/tests/computed_decorator_test.js
Expand Up @@ -70,6 +70,25 @@ if (EMBER_NATIVE_DECORATOR_SUPPORT) {
get(obj, 'fullName');
}

['@test computed property can be defined and accessed on a class constructor'](assert) {
let count = 0;

class Obj {
static bar = 123;

@computed
static get foo() {
count++;
return this.bar;
}
}

assert.equal(Obj.foo, 123, 'should return value');
Obj.foo;

assert.equal(count, 1, 'should only call getter once');
}

['@test it works with computed desc'](assert) {
assert.expect(4);

Expand Down
19 changes: 19 additions & 0 deletions packages/@ember/-internals/metal/tests/computed_test.js
Expand Up @@ -82,6 +82,25 @@ moduleFor(
assert.equal(count, 1, 'should have invoked computed property');
}

['@test computed property can be defined and accessed on a class constructor'](assert) {
pzuraq marked this conversation as resolved.
Show resolved Hide resolved
let count = 0;

let Obj = EmberObject.extend();
Obj.reopenClass({
bar: 123,

foo: computed(function() {
count++;
return this.bar;
}),
});

assert.equal(Obj.foo, 123, 'should return value');
Obj.foo;

assert.equal(count, 1, 'should only call getter once');
}

['@test can override volatile computed property'](assert) {
let obj = {};

Expand Down