SObjectObserver.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. export class SObjectObserver {
  2. /** 回调函数 */
  3. private readonly callback: Function;
  4. /** 信号接收者 */
  5. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  6. private readonly receiver: any = null;
  7. /**
  8. * 构造函数
  9. *
  10. * @param receiver 信号接收者
  11. * @param callback 回调函数
  12. */
  13. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  14. constructor(receiver: any, callback: Function) {
  15. this.receiver = receiver;
  16. this.callback = callback;
  17. } // Constructor
  18. /**
  19. * 发送通知
  20. *
  21. * @param args 参数
  22. */
  23. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  24. notify(...args: any): void {
  25. this.callback.call(this.receiver, ...args);
  26. } // Function notify()
  27. /**
  28. * 上信号接收者比较
  29. *
  30. * @param receiver 信号接收者
  31. */
  32. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  33. compar(receiver: any): boolean {
  34. return receiver == this.receiver;
  35. } // Function compar()
  36. } // Class EventObserver