Skip to content

Instantly share code, notes, and snippets.

@codler
Last active January 9, 2018 17:35
Show Gist options
  • Save codler/c91bc144a822c3fb0fc2 to your computer and use it in GitHub Desktop.
Save codler/c91bc144a822c3fb0fc2 to your computer and use it in GitHub Desktop.
Ractive.extend options as TypeScript Class - http://jsfiddle.net/qnjgsq1L/
function RactiveExtendTypeScriptClass(tsClass: any): RactiveStatic {
var instance = new tsClass();
var r = {};
for (var key in instance) {
r[key] = instance[key];
}
return Ractive.extend(r);
}
interface RactiveComponentPlugins {
Animal: RactiveStatic;
}
class Animal implements RactiveExtendOptions {
data = {
key: "value"
};
init(options: RactiveExtendOptions) {
var self: Ractive = <any>this;
self.add('a');
console.log('init');
console.log(options);
}
}
Ractive.components.Animal = RactiveExtendTypeScriptClass(Animal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment