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

TypeScript mixin is not transformed as a complete Polymer module definition #97

Closed
tpluscode opened this issue Jul 16, 2017 · 1 comment
Assignees

Comments

@tpluscode
Copy link
Contributor

A mixin in TypeScript can be defined as a function returning class containing properties and methods

Expected behavior

Properties are transformed to the static get properties method.

Actual behavior

Only methods are copied to the output file.

Example

type Constructor<T> = new(...args: any[]) => T;

export function MyMixin<T extends Constructor<{}>>(Base: T) {
    return class extends Base {
        some: String;

        _abstract() {

        }

        static _static() {

        }
    }
}

produces

function MyMixin(Base) {
  return class extends Base {
    _abstract() {}
    static _static() {}
  };
}
@Buslowicz Buslowicz self-assigned this Jul 16, 2017
@Buslowicz
Copy link
Owner

Buslowicz commented Jul 31, 2017

Need a hand with the decision by which mixin should be transformed into Polymer Mixin. We can have something like that:

function Mixin<T extends Constructor>(Super: T) {
  @Mixin()
  class Mixin extends Super {
    test: number;
  }
  return Mixin;
}

This however requires that:

  • mixin is a function or arrow function with body
  • inside the body, class is not exported right away
  • class is decorated with an annotation
  • class is returned from the mixin function

This would not allow to to a shorthand syntax:

const Mixin = <T extends Constructor>(Super: T) => class Mixin extends Super {
  test: number;
};

We could also use a JSDoc to mark mixins for transformation, which would match exactly how Polymer Tools require it:

/**
 * @mixinFunction
 * @polymer
 */  
const Mixin = <T extends Constructor>(Super: T) =>
  /**
   * @mixinClass
   * @polymer
   */
  class Mixin extends Super {
    test: number;
  }

or with marking just the function:

/**
 * @mixinFunction
 * @polymer
 */  
const Mixin = <T extends Constructor>(Super: T) => class Mixin extends Super {
  test: number;
}

What looks properly? Or should we have all of the above working?

Buslowicz pushed a commit that referenced this issue Nov 8, 2017
Buslowicz pushed a commit that referenced this issue Nov 21, 2017
… definition - basic mixins (properties only)
Buslowicz pushed a commit that referenced this issue Nov 21, 2017
… definition - optimizing the code (just a little bit)
Buslowicz pushed a commit that referenced this issue Nov 21, 2017
… definition - added mixed content test, fixed typo
Buslowicz pushed a commit that referenced this issue Nov 26, 2017
Buslowicz pushed a commit that referenced this issue Nov 27, 2017
… definition - covering further observer cases
Buslowicz pushed a commit that referenced this issue Nov 27, 2017
… definition - added computed props recognition
Buslowicz pushed a commit that referenced this issue Dec 3, 2017
… definition - added `reflectToAttribute` and `notify` recognition
Buslowicz pushed a commit that referenced this issue Dec 3, 2017
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