PolymerTS
PolymerTS copied to clipboard
Behavior properties - eg animationConfig and keyBindings
Is there any trick to using Behavior properties such as animationConfig
and keyBindings
?
By the way, I've created a Babel plugin which converts standard JavaScript Polymer 1.x projects into PolymerTS format - https://github.com/nalbion/babel-plugin-polymer-to-typescript
This should work, right?
/// <reference path="../../../bower_components/polymer-ts/polymer-ts.d.ts"/>
/// <reference path="../../../typings/polymer/paper/PaperRippleBehavior.d.ts"/>
@component('ts-element')
@behavior('Polymer.PaperRippleBehavior')
class TsElement extends polymer.Base implements Polymer.PaperRippleBehavior
{
//...
}
I get the following error:
error TS2420: Class 'TsElement' incorrectly implements interface 'PaperRippleBehavior'.
Property 'ensureRipple' is missing in type 'TsElement'.
I've figured it out - please add an example in the README
/// <reference path="../../../bower_components/polymer-ts/polymer-ts.d.ts"/>
/// <reference path="../../../typings/polymer/paper/PaperRippleBehavior.d.ts"/>
@component('ts-element')
@behavior(Polymer['PaperRippleBehavior'])
class TsElement extends polymer.Base implements Polymer.PaperRippleBehavior
{
// ...
handleClick(e:Event)
{
this.greet = "Holà";
this.fire("greet-event");
this.ensureRipple(e);
}
// stand-in properties for behavior mixins
noink: boolean = false;
ensureRipple: (optTriggeringEvent?: Event) => void;
getRipple: () => paper.PaperRipple;
hasRipple: () => boolean;
}
added in readme.md
Another note that would be worth adding to the README - this doesn't seem to work in polymer-ts:
keyBindings: {
'left': '_leftKey',
'right': '_rightKey',
'esc': '_escKey'
};
As per https://www.polymer-project.org/1.0/articles/es6.html, converting to a get
method seems to fix it:
get keyBindings() {
return {
'left': '_leftKey',
'right': '_rightKey',
'esc': '_escKey'
};
}
Is there any way to implement a behavior without having to provide "stand-in properties for behavior mixins". Clearly it works at runtime, but the TS compiler doesn't work without adding the stand-in properties...
@nalbion I was going add this to the README since I'm creating a new release, but I don't quite follow what you're asking. Is keyBindings a property in a behavior or just a new property in your class?