What is special about actor wrapper and this? - Motoko

Send you guys invites to https://github.com/icdevsorg/class-plus

I’ve gotten the class plus boiler plate down to

  let initManager = ClassPlus.ClassPlusInitializationManager(_owner, Principal.fromActor(this));
   
  stable var aClass_state : State = AClassLib.initialState();

  let aClass = AClassLib.Init<system>({
    manager = initManager;
    initialState = aClass_state;
    args = ?({messageModifier = "Hello World"});
    pullEnvironment = ?(func() : Environment {
      {
        thisActor = actor(Principal.toText(Principal.fromActor(this)));
      };
    });
    onInitialize = ?(func (newClass: AClassLib.AClass) : async* () {
        //_aClass := ?newClass;
        D.print("Initializing AClass");
      });
    onStorageChange = func(new_state: State) {
        aClass_state := new_state;
      } 
  });

From Aclass:

public func Init<system>(config : {
      manager: ClassPlusLib.ClassPlusInitializationManager;
      initialState: State;
      args : ?InitArgs;
      pullEnvironment : ?(() -> Environment);
      onInitialize: ?(AClass -> async*());
      onStorageChange : ((State) ->())
    }) :()-> AClass{

      ClassPlusLib.ClassPlus<system,
        AClass, 
        State,
        InitArgs,
        Environment>({config with constructor = AClass}).get;
    };

  

  public class AClass(stored: ?State, caller: Principal, canister: Principal, args: ?InitArgs, _environment: ?Environment, onStateChange: (State) -> ()){

public let state = switch(stored){
      case(?val) val;
      case(null) initialState() : State;
    };

    onStateChange(state); //passes state tracker back to actor to update the var.

...rest of class
}

I’ve haven’t had a chance to review what @infu has done with the module stuff, but this is working nicely and I have the @ZhenyaUsenko migration pattern working nicely under the hood where I need it. I’m hoping this will survive the upgrade to OEP as long as I keep variant vars out of my object states(this makes the pattern much less powerful but it hasn’t seemed to be much of an issue in the libraries I’ve reviewed…my biggest concerns are places where I’m keeping track of some state and want track states with variants…if the pattern changes in the future I’ll be in trouble.)