A Polymer behavior, implementing the co generator in Polymer. co is implemented as a behavior. A simple way to use it is as part of a a polymer function as below:
<link rel="import" href="co-behavior.html">
....
class SomeClass extends Polymer.mixinBehaviors(
[
Polymer.CoBehavior
], Polymer.Element) {
__fetchStuff() {
var self = this;
return new Promise(function(resolve, reject) {
.....
resolve(stuff);
});
}
__fetchSomething() {
let something = function*() {
let stuff = yield this.__fetchStuff.call(this);
this.someProperty = stuff;
};
return this.co(something.call(this));
}
Install with:
bower install co-behavior --save-dev