@elgordino wrote:
I have recently upgraded my Ember app from 2.18 to 3.4 and now get this deprecation:
[DEPRECATED] computed property 'xxx' was not set on object 'yyy' via 'defineProperty'
I am defining computed properties onto the prototype of a class at runtime. Currently like this:
prototype[attribute] = computed(...observableProperties, { get(key) { ... }, set(key, value) { ... }, }));
The deprecation advises to use
defineProperty
as a replacement, but if I do thisdefineProperty(prototype, attribute, computed(...observableProperties, { get(key) { ... }, set(key, value) { ... }, }));
Then the getter works fine but the setter is not added to the property and I get this error
Cannot set property xxx of [object Object] which has only a getter
I took at look into how
defineProperty
is defined and it only seems to set the getter. (from ember-metal/lib/properties.ts:192)Object.defineProperty(obj, keyName, { configurable: true, enumerable, get: DESCRIPTOR_GETTER_FUNCTION(keyName, value), });
I tried using Mixin instead of defineProperty but that ultimately executed the same
Object.defineProperty
.How can I add a computed property with a setter in Ember 3.x? I can live with the deprecation in Ember 3.4 but in 3.5 the deprecated functionality is removed. Thanks for any advice!
Posts: 1
Participants: 1