@gmsoft/event-bus
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

子应用和容器通信使用

/**
 * 创建或者从顶层窗口查找 eventBus
 * @param forceCreateNew 强制使用新的 eventBus, 否则尝试查找 top.eventBus
 * @param registerDefaultEvents 注册默认事件
 */
const createOrFindInTop = (
  forceCreateNew: boolean = false,
  registerDefaultEvents: boolean = true
) => eventBus
默认注册的事件
  /**
   * @param {string} data - 被注入的样式数据(css代码 | css文件链接)
   * @param {string} type - 注入的方式 style | link
   * injectCss: fn(data, type)
   */
  eventBus.on('inject.css', injectCss);

  /**
   * @param {string} src - 被注入的js文件链接
   * injectjs: fn(src) => Promise
   */
  eventBus.on('inject.js', injectJs);

  /**
   * store.set: fn(key, value)
   */
  eventBus.on('store.set', store.set.bind(store));

  /**
   * store.get: fn(key, defaultValue)
   */
  eventBus.on('store.get', store.get.bind(store));

  /**
   * store.remove: fn(key)
   */
  eventBus.on('store.remove', store.remove.bind(store));

  /**
   * store.clear: fn()
   */
  eventBus.on('store.clear', store.clear.bind(store));

  /**
   * 回到页面顶部(可以指定位置)
   * gotop: fn(position=0, isSmooth=true)
   */
  eventBus.on('page.gotop', gotop);

  /**
   * 页面打印, ie尝试使用打印插件
   */
  eventBus.on('page.print', print);

  /**
   * antd 的 Modal, 如何使用参见:
   * https://ant.design/components/modal-cn/#Modal.method()
   */
  eventBus.on('antd.Modal.info', Modal.info);
  eventBus.on('antd.Modal.success', Modal.success);
  eventBus.on('antd.Modal.error', Modal.error);
  eventBus.on('antd.Modal.warning', Modal.warning);
  eventBus.on('antd.Modal.confirm', Modal.confirm);
  eventBus.on('antd.Modal.destroyAll', Modal.destroyAll);

  /**
   * antd 的 message, 如何使用参见:
   * https://ant.design/components/message-cn/#API
   */
  eventBus.on('antd.message.info', message.info);
  eventBus.on('antd.message.success', message.success);
  eventBus.on('antd.message.error', message.error);
  eventBus.on('antd.message.warning', message.warning);
  eventBus.on('antd.message.loading', message.loading);
  eventBus.on('antd.message.destroy', message.destroy);

  /**
   * antd 的 message, 如何使用参见:
   * https://ant.design/components/notification-cn/#API
   */
  eventBus.on('antd.notification.info', notification.info);
  eventBus.on('antd.notification.success', notification.success);
  eventBus.on('antd.notification.error', notification.error);
  eventBus.on('antd.notification.warning', notification.warning);
  eventBus.on('antd.notification.open', notification.open);
  eventBus.on('antd.notification.close', notification.close);
  eventBus.on('antd.notification.destroy', notification.destroy);

Readme

Keywords

none

Package Sidebar

Install

npm i @gmsoft/event-bus

Weekly Downloads

0

Version

1.4.0

License

none

Unpacked Size

207 kB

Total Files

35

Last publish

Collaborators

  • xt_journey
  • angular-moon
  • bddandelion
  • julysunshine