import vue from 'vue';

export const createMutationObserve = ({ modules = [] }) => {
  return (store) => {
    store.subscribe((mutation, state) => {
      // 每次 mutation 之后调用
      // mutation 的格式为 { type, payload }
      console.log(mutation, 'mutation');
      if (
        modules?.length &&
        modules.find((i) => mutation?.type?.startsWith(i + '/')) &&
        mutation.payload.toPort
      ) {
        console.log(vue.prototype.$portalStore, 'vue.prototype.$portalStore');
        vue.prototype.$portalStore?.commit &&
          vue.prototype.$portalStore?.commit(mutation.type, mutation.payload);
      }
    });
  };
};
