Reputation: 2623
This is weird. What am I doing wrong?
class Store extends Riot.Observable {
trigger():void {
// shouldn't this be completely overwriting the trigger method on riot.observable?
console.log("my trigger....");
}
}
let store = new Store();
store.trigger();
Expected behaviour: "my trigger...." in the console. What I get is the original implementation of trigger on the Riot.Observable, which errors because of no parameters being passed.
If I poke the store
object I can see on store.__proto__
does have trigger on there, with my implementation. But store
iself has its own (original) copy of trigger()
Please see https://jsfiddle.net/sidouglas/5spbvpnn/
I referenced this with a very basic example, and I don't know what's going on.
Upvotes: 2
Views: 235
Reputation: 29926
Based on the source, riot observables do not take advantage of prototypical inheritance. They work as mixins instead. The typescript wrapper class just calls the original riot mixin. To overwrite a function, you have to assign it to the instance:
class Store extends Riot.Observable {
constructor() {
this.trigger = function() {
console.log("My trigger");
};
}
}
let store = new Store();
store.trigger();
Upvotes: 2