handler.dart 911 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import 'package:fis_common/event/event_type.dart';
  2. import 'package:flutter/foundation.dart';
  3. /// 消息处理器
  4. abstract class IHandler<T> {
  5. /// 类型Int值
  6. int get typeInt;
  7. /// 执行处理程序
  8. ///
  9. /// [message] 消息实例
  10. void execute(T message);
  11. }
  12. /// 可分发
  13. abstract class IDistributable<T> {
  14. /// 订阅
  15. ///
  16. /// [callback] 订阅消息回调函数
  17. void subscribe(ValueChanged<T> callback);
  18. /// 取消订阅
  19. ///
  20. /// [callback] 订阅消息回调函数
  21. void unsubscribe(ValueChanged<T> callback);
  22. }
  23. /// 处理器提供者
  24. abstract class IHandlerProvider {
  25. /// 获取处理器
  26. ///
  27. /// [type] 消息类型
  28. IHandler? getHandler(int type);
  29. }
  30. /// 可注册处理器
  31. abstract class IHandlerRegistrable {
  32. /// 注册处理器
  33. ///
  34. /// [handler] 处理器
  35. void register<T>(IHandler<T> handler);
  36. /// 撤销注册
  37. void deregister<T>(IHandler<T> handler);
  38. }