plugin-api.modifyClass
allows us to overwrite instance methods of existing classes, but there is no analogous way to overwrite class methods. It would be cool if there were.
In my case, I want to overwrite the user
model’s createAccount
method (https://github.com/discourse/discourse/blob/9df7fd4f308e007e4aa2cd17e40cee92b68fad07/app/assets/javascripts/discourse/models/user.js.es6#L624).
I got around it with this, drawing heavily on plugin-api.modifyClass
…
const klass = api.container.factoryFor('model:user');
klass.class.reopenClass({
createAccount(attrs) {
console.log('overwrites createAccount')
}
})
… which seems to work, but it’s a little kludgy.