Проверка шаблона шины для iOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.2KB

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