phodal / mooa

Mooa 是一个为 Angular 服务的微前端框架。A independent-deployment micro-frontend Framework for Angular from single-spa.

Home Page:http://mooa.phodal.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing data on application startup

GeoffSeloana opened this issue · comments

Hi,

Please advice how to pass data from parent application start-up with mooa.

Trying to do the following.

Parent applicatoin

const customProps: Test = new Test();
customProps.apikey = 'fasdfewafdsafdsfadsfasdf';
customProps.name = 'testing 123';
customProps.val1 = 'val1';
customProps.val2 = 'val2';

 that.mooa.registerApplicationByLink(config.name, config.link, mooaRouter.matchRoute(config.name), customProps);

customProps is the object i would like to pass to the other applications on start-up.

Child application

how can i get this object from the child application

e.g on the following code

mooaPlatform.mount('ficaVerificationFrontend').then((opts) => {

  console.log('--------- props start---------');
  console.log(opts);  // would like to access customProps obj at this point
  console.log('--------- props end---------');

  platformBrowserDynamic().bootstrapModule(AppModule)
    .then((module) => {
      opts['attachUnmount'](module);
      console.log('--------- attachUnmount start---------');
      console.log(module); // would like to access customProps obj at this point
      console.log('--------- attachUnmount end---------');
      // Do something with props if you want
      // Ex : module.instance.setSomething(...)
    })
    .catch(err => console.log(err));
})

it's not need to set customProps in mooa, you can try:

  1. set data to window object
  2. save data to localStorage

Okay, will try that... the problem is, i would like the child applications to listen on an object and react to any change that happens to that object. something like Angular observables or Angular BehaviorSubject. Something that can keep all the applications informed about the state of an object and its value.

Any idea how I can handle events with mooa framework? not only passing data but reacting to events

I think maybe you can implements a simple pub-sub function with Promise. And bind it to window object, then everywhere can use it. Or just customEvent?

Okay thank you. Will try it.