Inheriting Methods Across Types


#1

I would like to programmatically determine the type that invoked the method, from within the method.

I have a type:

type TypeA {
  function1: function(input1: string)
}

I want to mix in TypeA into TypeB:

entity type TypeB mixes TypeA {
  function1: ~ js server
}

I also intend to mix in TypeA to TypeC, TypeD, TypeE, etc.

However, function1.js ideally is defined on TypeA and looks like this:

function function1(input1){
  ...
  <<grab the Type that invoked the method>>>
  TypeB.create() //Where TypeB would be the Type that mixes in TypeA, so could be TypeB/C/D/E/etc. 
  // This method would never be called on TypeA, but it's logic will not change across the different types that mix TypeA, with the exception of which type gets created.
  ...
}

I could create another input to the function that is a string of the typeName, and then to a C3Type(‘typeName’), but this seems a bit sloppy, so I am wondering if there is a way to <>>.


#2

In the server-side JS action runtime, you can get the current type using this snippet:

var type = c3Type(c3CurrentAction().getTarget().getType());