ember-decorators / ember-decorators/ember-decorators
wrapComputed and computedDecoratorWithParams do not work with a getter/setter computed
- Dominant language
- JavaScript
- Stars
- 357
- Forks
- 93
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
This works:
```js
@computed('startDate')
get startDateLuxon(): DateTime {
return DateTime.fromJSDate(this.startDate, { zone: 'UTC' });
}
set startDateLuxon(luxonDate: DateTime) {
this.set('startDate', luxonDate.toJSDate());
}
```
But I would like to make this code reusable like this:
```js
@dateToLuxon('startDate')
startDateLuxon!: DateTime;
```
I'm trying to achieve it with this:
```js
import computed from 'ember-macro-helpers/computed';
// @ts-ignore
import { computedDecoratorWithParams } from '@ember-decorators/utils/computed';
export function dateToLuxonCP(key: any): ComputedProperty {
return computed(key, {
get(date: Date) {
return Date2Luxon(date);
},
set(luxonDate: DateTime) {
this.set(key, luxonDate.toJSDate());
},
});
}
// @ts-ignore
export const dateToLuxon = computedDecoratorWithParams((_desc: any, params: any[]) => dateToLuxonCP.apply(this, params));
```
It doesn't work! `this.startDateLuxon` returns `undefined`. I've tried putting a `debugger` into the getter, and it is never called.
I also tried this and it doesn't work either:
```js
@wrapComputed(dateToLuxonCP('startDate'))
startDateLuxon!: DateTime;
```
CC @simonihmig.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.