Search code examples
ecmascript-6babeljsflowtypemixins

Does FlowType support mixins or composition?


Does flow support mixins like the following?

// spark.js
import {includeEmitterIn} from 'emitter';
export default class Spark {
  constructor() {
    includeEmitterIn(this);
  }
  doSomething() {
    this.emit();
  }
}

// emitter.js
export function includeEmitterIn(obj) {
  obj.emit = function(callback) {
    //...
  }
}

Solution

  • With newer versions of Flowtype, you can now do mixins like so:

    class A {}
    class B {}
    
    class C mixins A, B {}
    

    Don't know what version this was introduced in though, sorry. The docs aren't the greatest, but I'm using this feature now.

    edit: Looks like they were added in 0.16.0