Skip to content

微应用监听主应用发送的消息,调用off取消监听不成功 #6959

@yyyyffqqqq

Description

@yyyyffqqqq

Describe the bug

主应用通过这两种方式给微应用传递消息:
import { store as starkDataStore, event } from '@ice/stark-data';

event?.emit(MQTT_MESSAGE, { topic, message: JSON.parse(message.toString()) });
starkDataStore?.set(MQTT_MESSAGE, { topic, message: JSON.parse(message.toString()) });

在微应用中:

starkEvent.on(MQTT_MESSAGE, ({ topic, message }) => {
      console.log('航班动态 收到主应用推送过来的消息', topic, message);
      onReceivedMqttMessage({ topic, message });
   });

starkEvent.off(MQTT_MESSAGE, () => {
        console.log('航班动态 主应用推送过来的消息监听被移除');
      });

starkEvent.off没起作用,反复执行starkEvent.on,主应用发送一次消息,会多次进入starkEvent.on的回调方法

Expected behavior

starkEvent.off(MQTT_MESSAGE, () => {
console.log('航班动态 主应用推送过来的消息监听被移除');
});
能够正常取消监听

Actual behavior

No response

Version of ice.js

"@ice/app": "3.4.10"

Content of build.json or ice.config.mts

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions