Allow modifying class methods/properties in plugin-api?

(Shoshana Berleant) #1

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 (discourse/user.js.es6 at 9df7fd4f308e007e4aa2cd17e40cee92b68fad07 · discourse/discourse · GitHub).

I got around it with this, drawing heavily on plugin-api.modifyClass

const klass = api.container.factoryFor('model:user');

  createAccount(attrs) {
    console.log('overwrites createAccount')

… which seems to work, but it’s a little kludgy.

(Sam Saffron) #2

@eviltrout thoughts? I think adding reopenClass or something like that in plugin api makes sense, not sure what the right naming here is though.

(Robin Ward) #3

Sure reopenClass would be a good addition to the plugin api if you want to submit a PR @shoshber

(Shoshana Berleant) #4

Ok, I will do that! :grinning: