LookinMsgAttribute.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // LookinMsgAttribute.h
  3. // Lookin
  4. //
  5. // Created by Li Kai on 2019/8/19.
  6. // https://lookin.work
  7. //
  8. #import "LookinDefines.h"
  9. @interface LookinMsgActionParams : NSObject
  10. @property(nonatomic, strong) id value;
  11. @property(nonatomic, assign) double doubleValue;
  12. @property(nonatomic, assign) NSInteger integerValue;
  13. @property(nonatomic, assign) BOOL boolValue;
  14. @property(nonatomic, weak) id relatedObject;
  15. @property(nonatomic, strong) id userInfo;
  16. @end
  17. @interface LookinMsgAttribute : NSObject
  18. /// 创建一个示例并给予一个初始值
  19. + (instancetype)attributeWithValue:(id)value;
  20. /// 当前的值
  21. @property(nonatomic, strong, readonly) id currentValue;
  22. /**
  23. 使用 value 作为 currentValue 属性的值
  24. 调用该方法后,所有此前通过 subscribe:action: 相关方法注册的 subscriber 的 action 都会被调用,参数是一个 LookinMsgActionParams 对象
  25. 如果传入了 ignoreSubscriber,则 ignoreSubscriber 这个对象不会收到这次通知
  26. 如果传入的 value 和之前已有的 value 是 equal 的,则该方法不会产生任何效果
  27. 传入的 userInfo 对象可在 LookinMsgActionParams 中被读取
  28. */
  29. - (void)setValue:(id)value ignoreSubscriber:(id)ignoreSubscriber userInfo:(id)userInfo;
  30. /// target, relatedObject 均不会被强引用,action 方法的参数是一个 LookinMsgActionParams
  31. /// 即使多次调用该方法添加同一个 target,target 也只会收到一次通知
  32. - (void)subscribe:(id)target action:(SEL)action relatedObject:(id)relatedObject;
  33. /// 如果 sendAtOnce 为 YES,则在该方法调用后,会立即收到一条消息
  34. - (void)subscribe:(id)target action:(SEL)action relatedObject:(id)relatedObject sendAtOnce:(BOOL)sendAtOnce;
  35. @end
  36. @interface LookinDoubleMsgAttribute : LookinMsgAttribute
  37. @property(nonatomic, assign, readonly) double currentDoubleValue;
  38. + (instancetype)attributeWithDouble:(double)value;
  39. - (void)setDoubleValue:(double)doubleValue ignoreSubscriber:(id)ignoreSubscriber;
  40. @end
  41. @interface LookinIntegerMsgAttribute : LookinMsgAttribute
  42. @property(nonatomic, assign, readonly) NSInteger currentIntegerValue;
  43. + (instancetype)attributeWithInteger:(NSInteger)value;
  44. - (void)setIntegerValue:(NSInteger)integerValue ignoreSubscriber:(id)ignoreSubscriber;
  45. @end
  46. @interface LookinBOOLMsgAttribute : LookinMsgAttribute
  47. @property(nonatomic, assign, readonly) BOOL currentBOOLValue;
  48. + (instancetype)attributeWithBOOL:(BOOL)value;
  49. - (void)setBOOLValue:(BOOL)BOOLValue ignoreSubscriber:(id)ignoreSubscriber;
  50. @end