phodal / mooa

Mooa 是一个为 Angular 服务的微前端框架。A independent-deployment micro-frontend Framework for Angular from single-spa.
http://mooa.phodal.com/
Other
850 stars 109 forks source link

Passing data on application startup #16

Closed GeoffSeloana closed 5 years ago

GeoffSeloana commented 5 years ago

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));
})
phodal commented 5 years ago

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

  1. set data to window object
  2. save data to localStorage
GeoffSeloana commented 5 years ago

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.

GeoffSeloana commented 5 years ago

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

phodal commented 5 years ago

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?

GeoffSeloana commented 5 years ago

Okay thank you. Will try it.