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] observed properties not being marked as enum #16735

Merged
merged 1 commit into from Jan 4, 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
11 changes: 8 additions & 3 deletions packages/@ember/-internals/metal/lib/property_set.ts
@@ -1,5 +1,5 @@
import { descriptorFor, Meta, peekMeta } from '@ember/-internals/meta';
import { HAS_NATIVE_PROXY, toString } from '@ember/-internals/utils';
import { HAS_NATIVE_PROXY, lookupDescriptor, toString } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import EmberError from '@ember/error';
import { DEBUG } from '@glimmer/env';
Expand All @@ -19,6 +19,7 @@ let setWithMandatorySetter: <T extends object, K extends Extract<keyof T, string
keyName: K,
value: T[K]
) => void;

let makeEnumerable: (obj: object, keyName: string) => void;

/**
Expand Down Expand Up @@ -125,9 +126,13 @@ if (DEBUG) {
};

makeEnumerable = (obj: object, key: string) => {
let desc = Object.getOwnPropertyDescriptor(obj, key);
let desc = lookupDescriptor(obj, key);

if (desc && desc.set && (desc.set as MandatorySetterFunction).isMandatorySetter) {
if (
desc !== null &&
desc.set !== undefined &&
(desc.set as MandatorySetterFunction).isMandatorySetter
) {
desc.enumerable = true;
Object.defineProperty(obj, key, desc);
}
Expand Down
@@ -1,5 +1,5 @@
import { getOwner, setOwner } from '@ember/-internals/owner';
import { get } from '@ember/-internals/metal';
import { get, set, observer } from '@ember/-internals/metal';
import CoreObject from '../../lib/system/core_object';
import { moduleFor, AbstractTestCase, buildOwner } from 'internal-test-helpers';

Expand Down Expand Up @@ -106,5 +106,28 @@ moduleFor(
},
}).create(options);
}

['@test observed properties are enumerable when set GH#14594'](assert) {
let callCount = 0;
let Test = CoreObject.extend({
myProp: null,
anotherProp: undefined,
didChangeMyProp: observer('myProp', function() {
callCount++;
}),
});

let test = Test.create();
set(test, 'id', '3');
set(test, 'myProp', { id: 1 });

assert.deepEqual(Object.keys(test).sort(), ['id', 'myProp']);

set(test, 'anotherProp', 'nice');

assert.deepEqual(Object.keys(test).sort(), ['anotherProp', 'id', 'myProp']);

assert.equal(callCount, 1);
}
}
);