Let’s say I want to write an actor that has some base functionality, and then I want others to use this actor and build on top of it without breaking any of the abstractions and base logic I have laid underneath.
Currently, Motoko provides no functionality for the following:
import Y "mo:baseActor/Y";
actor X extends Y` {}
This means if I want to create an actor framework, the best I can do is to write modules, and then tell the developer to copy/paste each of the public/shared function code and import the one liner modules. Something like this
import Y "mo:some-module/Y";
shared ({ caller = caller )} actor class X {
public func f1(t: Text): async() {
await Y.f1(t);
};
// can't define shared functions in modules so need to pass the caller as an argument
public shared({caller = caller}) func f2(): async() {
await Y.f2(caller);
}
// If I tried making Y.f2() a shared function and importing that directly, I would get the following error:
//
// "type error [M0077], a shared function is only allowed as a public field of an actor
// (This is a limitation of the current version.)"
}
This works, but if the developer forgets to import an actor API endpoint, it could break their application in unexpected ways.
A few questions:
- Are there any “cleaner” ways than what I’ve laid out to extend or import public facing APIs into actors?
- If not, would an “extends” or imports/uses functionality similar to what I laid out at the top of this post be feasible? What type of effort/changes would this involve? (This feature would be amazing for abstracting away the complexities of infrastructure frameworks).