LookinMsgAttribute.h 2.5 KB

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