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

Do behaviors require stand-in properties? #886

Closed
kito99 opened this issue Jan 22, 2018 · 3 comments
Closed

Do behaviors require stand-in properties? #886

kito99 opened this issue Jan 22, 2018 · 3 comments

Comments

@kito99
Copy link
Contributor

kito99 commented Jan 22, 2018

So, unless I'm mistaken, since behaviors are declared as interfaces, we need to add stand-in declarations just as we did with PolymerTS:

class MyappView1 extends Polymer.mixinBehaviors([Polymer['AppLocalizeBehavior']], Polymer.Element) implements AppLocalizeBehavior {

// actual code

		// Stand-in declarations from AppLocalizeBehavior
		language: string|null|undefined;
		resources: object|null|undefined;
		formats: object|null|undefined;
		useKeyIfMissing: boolean|null|undefined;
		readonly localize: Function|null|undefined;
		bubbleEvent: boolean|null|undefined;
		loadResources: (path: string, language?: string, merge?: boolean) =>  any;

}

Is this the correct way to use a behavior?

@aomarks
Copy link
Member

aomarks commented Jan 25, 2018

I would cast the result of mixinBehaviors to a constructor that includes the generated interface. That way you don't need to redeclare anything. Getting mixinBehaviors to do this automatically seems potentially impossible.

const myElementBase =
    Polymer.mixinBehaviors([ Polymer.AppLocalizeBehavior ], Polymer.Element) as
    new () => Polymer.Element & Polymer.AppLocalizeBehavior;

class MyElement extends myElementBase {
   ...
}

I just filed #70 to address the fact that we don't declare the actual object representing the behavior (which is why you had to do Polymer['AppLocalizeBehavior']). In the short term you could do this, and then just remove it once the declarations include it:

declare namespace Polymer { const AppLocalizeBehavior: object; }

@kito99
Copy link
Contributor Author

kito99 commented Jan 25, 2018

Thanks! I'll give this a shot and close it once I get things working.

@kito99
Copy link
Contributor Author

kito99 commented Feb 1, 2018

That worked. Thanks!

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