enigma.js icon indicating copy to clipboard operation
enigma.js copied to clipboard

Allow mixins to seamlessly override existing methods

Open konne opened this issue 7 years ago • 4 comments

If I add a mixin I have no chance to make something like an "inserOrUpdate".

It would be great to have a section there I can add function and enigma gives me as a parameter if this function exists or not. So that I can decide in my mixin what to do.

For example. We develop an mixin like #272 and a later engine version delivers even on .app an getProperties. With the current enigma.js we have no chance to write a generic working mixin.

konne avatar Nov 08 '17 12:11 konne

Good point! One way to solve this would be to remove the mixin.extend and mixin.override properties and modify the signature of all mixin methods to take baseFn as its first argument.

For example:

const mixin = {
  types: ['Doc'],
  init(args) {},
  methods: {
    method1(baseFn, arg1, arg2) {
      if (baseFn) {
        // base function exists (overrides existing method)
      } else {
        // no base function (extends the generated api)
      }
    } 
  }

Is this something that would work for you?

marcusoffesson avatar Nov 10 '17 15:11 marcusoffesson

Hi @marcusoffesson, this should work, but this mixin.methods is at least at the moment not documented. If this is already in the product please extend https://github.com/qlik-oss/enigma.js/blob/2fe4538cdeeb6d2a174cd78cf96906de91bcfce5/docs/api.md#mixins

konne avatar Nov 10 '17 15:11 konne

Hi @konne! My previous comment should be read as a design proposal and not as something that already exists. Also, we have to consider other things, such as backwards compatibility, etc.

marcusoffesson avatar Nov 13 '17 09:11 marcusoffesson

Hi @marcusoffesson, okay, the design proposal sounds great, so this would perfectly work.

konne avatar Nov 13 '17 13:11 konne