Проверка шаблона шины для iOS

141 lines
3.0KB

  1. // ВНИМАНИЕ Сгенерировано автоматом из файла Mic.yml
  2. // ВНИМАНИЕ Не менять руками!
  3. import AELog
  4. import BusX
  5. import Combine
  6. import Foundation
  7. import MPAKX
  8. import UIKit
  9. // MARK: - Context
  10. public protocol MicContext {
  11. var activeIds: MPAK.Recent<[String]> { get }
  12. var activityDates: MPAK.Recent<[String:Date]> { get }
  13. var requestActivityDate: String? { get }
  14. }
  15. // MARK: - Controller
  16. extension Mic {
  17. final class Controller: MPAK.Controller<Mic.Model> {
  18. init() {
  19. super.init(
  20. Mic.Model(),
  21. debugClassName: "MicCtrl",
  22. debugLog: { aelog($0) }
  23. )
  24. }
  25. }
  26. // MARK: - Model
  27. public struct Model: MicContext {
  28. public var activeIds: MPAK.Recent<[String]> = .init([])
  29. public var activityDates: MPAK.Recent<[String:Date]> = .init([:])
  30. public var requestActivityDate: String? = nil
  31. }
  32. // MARK: - Service
  33. public final class Service {
  34. let ctrl = Controller()
  35. let world: World
  36. var subscriptions = [AnyCancellable]()
  37. static private(set) weak var singleton: Service?
  38. public init(_ world: World) {
  39. self.world = world
  40. Self.singleton = self
  41. SectionGenerated.setupPlatform(ctrl, self, world)
  42. }
  43. }
  44. // MARK: - World
  45. public struct World {
  46. public init(
  47. ) {
  48. }
  49. }
  50. enum SectionGenerated {
  51. // MARK: - SectionGenerated Service
  52. static func setupPlatform(
  53. _ ctrl: Controller,
  54. _ service: Service,
  55. _ world: World
  56. ) {
  57. // MARK: - SectionGenerated Service Actions
  58. ctrl.m
  59. .compactMap { shouldDeliverActivityDates($0) }
  60. .receive(on: DispatchQueue.main)
  61. .sink { v in Bus.deliver(K.activityDate, v) }
  62. .store(in: &service.subscriptions)
  63. ctrl.m
  64. .compactMap { shouldResetActivityDates($0) }
  65. .receive(on: DispatchQueue.main)
  66. .sink { v in Bus.send(K.activityDates, v) }
  67. .store(in: &service.subscriptions)
  68. // MARK: - SectionGenerated Service Pipes
  69. ctrl.pipeValue(
  70. dbg: "activeI",
  71. sub: nil,
  72. Bus.events.compactMap { Bus.convertKeyValue(K.activeIds, $0) }.map { (k: String, v: [String]) in v }.eraseToAnyPublisher(),
  73. {
  74. $0.activeIds.value = $1
  75. $0.activeIds.isRecent = true
  76. },
  77. { m, _ in m.activeIds.isRecent = false }
  78. )
  79. ctrl.pipeValue(
  80. dbg: "activityD",
  81. sub: nil,
  82. Bus.events.compactMap { Bus.convertKeyValue(K.activityDates, $0) }.map { (k: String, v: [String:Date]) in v }.eraseToAnyPublisher(),
  83. {
  84. $0.activityDates.value = $1
  85. $0.activityDates.isRecent = true
  86. },
  87. { m, _ in m.activityDates.isRecent = false }
  88. )
  89. ctrl.pipeValue(
  90. dbg: "requestAD",
  91. sub: nil,
  92. Bus.events.compactMap { Bus.convertKeyValue(K.requestActivityDate, $0) }.map { (k: String, v: String?) in v }.eraseToAnyPublisher(),
  93. { $0.requestActivityDate = $1 },
  94. { m, _ in m.requestActivityDate = nil }
  95. )
  96. }
  97. }
  98. }