beforeCreate() function on an Abstract type


We have an abstract type:

type A {
beforeCreate: function(objs: [Obj]): ObjList js server;

and an entity type:

entity type B mixes A schema name “S_B”

we have a js implementation for the beforeCreate() on type A. When I do a c3ShowType(B) and look at beforeCreate(), it still shows the declaration from Persistable, but the js implementation on type A seems to be working.

Can someone explain how this is working? We are trying to define beforeCreate() on a NON PERSISTABLE type because the types that share the logic don’t want to share a table


I would guess that this is what’s happening as type B is resolved:

  1. Apply Persistable mixin
    1.1 Apply Persistable.beforeCreate implementation
    1.2 Apply Persistable.beforeCreate documentation
  2. Apply A mixin
    2.1 Apply A.beforeCreate implementation (overrides Persistable.beforeCreate implementation)
    2.2 There is no A.beforeCreate documentation, so use whatever documentation has already been applied

However, I could see some potential issues here with the way you’ve defined A. Because Persistable is a parametric type with variable T, the declaration of Persistable.beforeCreate actually looks like this:

beforeCreate: function(objs: !?[T]): ObjList<T>

I’m not sure if the signature of beforeCreate is modified in step 2.1, but double-check type B after provisioning to make sure the return value type of beforeCreate is not an unbound ObjList.


c3ShowType(B) does show

beforeCreate: function(objs: !?[B]): ObjList<B>

So that’s good.