Проверка шаблона шины для 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.

137 lines
2.7KB

  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 join: Bool { get }
  13. var textApp: MPAK.Recent<String> { 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 join: Bool = false
  30. public var textApp: MPAK.Recent<String> = .init("")
  31. public var textUI: MPAK.Recent<String> = .init("")
  32. }
  33. // MARK: - Service
  34. public final class Service {
  35. let ctrl = Controller()
  36. let world: World
  37. var subscriptions = [AnyCancellable]()
  38. static private(set) weak var singleton: Service?
  39. public init(_ world: World) {
  40. self.world = world
  41. Self.singleton = self
  42. SectionGenerated.setupPlatform(ctrl, self, world)
  43. }
  44. }
  45. // MARK: - World
  46. public struct World {
  47. let join = PassthroughSubject<Void, Never>()
  48. let textApp = PassthroughSubject<String, 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. // MARK: - SectionGenerated Service Pipes
  66. ctrl.pipe(
  67. dbg: "join",
  68. sub: nil,
  69. Bus.events.compactMap { Bus.convertKeyValue(K.join, $0) }.map { (k: String, v: Bool) in v }.map { _ in () }.eraseToAnyPublisher(),
  70. { $0.join = true },
  71. { $0.join = false }
  72. )
  73. ctrl.pipeValue(
  74. dbg: "textA",
  75. sub: nil,
  76. Bus.events.compactMap { Bus.convertKeyValue(K.textApp, $0) }.map { (k: String, v: String) in v }.eraseToAnyPublisher(),
  77. {
  78. $0.textApp.value = $1
  79. $0.textApp.isRecent = true
  80. },
  81. { m, _ in m.textApp.isRecent = false }
  82. )
  83. ctrl.pipeValue(
  84. dbg: "textUI",
  85. sub: nil,
  86. Bus.events.compactMap { Bus.convertKeyValue(K.textUI, $0) }.map { (k: String, v: String) in v }.eraseToAnyPublisher(),
  87. {
  88. $0.textUI.value = $1
  89. $0.textUI.isRecent = true
  90. },
  91. { m, _ in m.textUI.isRecent = false }
  92. )
  93. }
  94. }
  95. }