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

121 lines
2.4KB

  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. }
  14. // MARK: - Controller
  15. extension Mic {
  16. final class Controller: MPAK.Controller<Mic.Model> {
  17. init() {
  18. super.init(
  19. Mic.Model(),
  20. debugClassName: "MicCtrl",
  21. debugLog: { aelog($0) }
  22. )
  23. }
  24. }
  25. // MARK: - Model
  26. public struct Model: MicContext {
  27. public var activeIds: MPAK.Recent<[String]> = .init([])
  28. public var activityDates: MPAK.Recent<[String:Date]> = .init([:])
  29. }
  30. // MARK: - Service
  31. public final class Service {
  32. let ctrl = Controller()
  33. let world: World
  34. var subscriptions = [AnyCancellable]()
  35. static private(set) weak var singleton: Service?
  36. public init(_ world: World) {
  37. self.world = world
  38. Self.singleton = self
  39. SectionGenerated.setupPlatform(ctrl, self, world)
  40. }
  41. }
  42. // MARK: - World
  43. public struct World {
  44. public init(
  45. ) {
  46. }
  47. }
  48. enum SectionGenerated {
  49. // MARK: - SectionGenerated Service
  50. static func setupPlatform(
  51. _ ctrl: Controller,
  52. _ service: Service,
  53. _ world: World
  54. ) {
  55. // MARK: - SectionGenerated Service Actions
  56. ctrl.m
  57. .compactMap { shouldResetActivityDates($0) }
  58. .receive(on: DispatchQueue.main)
  59. .sink { v in Bus.send(K.activityDates, v) }
  60. .store(in: &service.subscriptions)
  61. // MARK: - SectionGenerated Service Pipes
  62. ctrl.pipeValue(
  63. dbg: "activeI",
  64. sub: nil,
  65. Bus.events.compactMap { Bus.convertKeyValue(K.activeIds, $0) }.map { (k: String, v: [String]) in v }.eraseToAnyPublisher(),
  66. {
  67. $0.activeIds.value = $1
  68. $0.activeIds.isRecent = true
  69. },
  70. { m, _ in m.activeIds.isRecent = false }
  71. )
  72. ctrl.pipeValue(
  73. dbg: "activityD",
  74. sub: nil,
  75. Bus.events.compactMap { Bus.convertKeyValue(K.activityDates, $0) }.map { (k: String, v: [String:Date]) in v }.eraseToAnyPublisher(),
  76. {
  77. $0.activityDates.value = $1
  78. $0.activityDates.isRecent = true
  79. },
  80. { m, _ in m.activityDates.isRecent = false }
  81. )
  82. }
  83. }
  84. }