-
Notifications
You must be signed in to change notification settings - Fork 75
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
Tracked descriptors not accessible after property initialization #415
Comments
Would this work for your usecase? import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { on } from '@ember/modifier';
/**
* Note that when an app switches to accessor decorators,
* this won't work
*/
function log(target, propertyKey, descriptor) {
let {get, set} = descriptor;
Object.assign(descriptor, {
get() {
console.log('get', propertyKey);
return get.call(this);
},
set(newValue) {
console.log('set', propertyKey, newValue);
return set.call(this, newValue);
}
});
}
export default class extends Component {
@log
@tracked
foo = '';
change = () => this.foo += Math.random().toString().split('').at(-1);
<template>
foo: {{this.foo}}
<br>
<button {{on 'click' this.change}}>change foo</button>
</template>
} |
So technically yes this works, however, the TypeScript compiler is going to error with |
oh yes, the TS types for decorators are way wrong for what we do, so when you type a decorator you need all the lies. This isn't fixed until we move to supporting the spec-decorators coming out of the TC39 process |
Background
I'm attempting to create a custom decorator to apply to a
@tracked
property in order to execute a function whenever the property's value is set.Here's a simplified version of the component and the decorator:
Problem
When trying to access the tracked descriptor in a subsequent decorator, it will always be
undefined
. Thus preventing me from creating a custom decorator for a@tracked
property. Am I going about this incorrectly? Any help would be appreciated, thanks!Version
The text was updated successfully, but these errors were encountered: