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

Class get ("getter") is not supported #148

Open
tianyingchun opened this issue Dec 19, 2019 · 1 comment
Open

Class get ("getter") is not supported #148

tianyingchun opened this issue Dec 19, 2019 · 1 comment

Comments

@tianyingchun
Copy link

tianyingchun commented Dec 19, 2019

const resolvedValue = initializer
            ? Reflect.apply(initializer, this, [])
            : Reflect.apply(get, this, []);
          const decoratedValue = decorate(resolvedValue).bind(this);

if we need to decorator one property or getter()

  // member field.
  @track({ fieldName: 'fieldName' })
  private fieldName = 'fieldName';

  // getter
  @track({ getName: 'getter() getMyName' })
  private get getMyName() {
    return this.parentMethod() + 'my name';
  }

  private handleTrack = () => {
    console.log('handleTrack: property decorator:', this.getMyName, this.fieldName);
    return {
      result: '({} as any).name.handleTrack',
    };
  }

for property decorate will lazy execute, it will result in

const resolvedValue = initializer
            ? Reflect.apply(initializer, this, [])
            : Reflect.apply(get, this, []);

//  resolvedValue value will be string, 
//  but if we execute
const decoratedValue = decorate(resolvedValue).bind(this); 
// will aways return us a function.
 

so maybe we need to do some check here like below code:

const decoratedValue = isFunction(resolvedValue)
            ? decorate(resolvedValue, name).bind(this)
           // for getter, member field we need to direct evaluate this express. and get the final value to consumer.
            : Reflect.apply(decorate(() => resolvedValue, name), this, []);
@tizmagik
Copy link
Collaborator

Yes, that's quite possibly a bug. I don't think we've handled the use case for a getter. Feel free to submit a PR with a test case! 🙏

@tizmagik tizmagik changed the title is there is a bug here? Class get ("getter") is not supported Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants