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

155 lines
3.2KB

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