This commit is contained in:
Михаил Капелько
2024-02-09 08:17:13 +03:00
parent 556b3c5879
commit 8bb677258f
3 changed files with 132 additions and 58 deletions

View File

@@ -0,0 +1,130 @@
// ВНИМАНИЕ Сгенерировано автоматом из файла MicItem.yml
// ВНИМАНИЕ Не менять руками!
import AELog
import BusX
import Combine
import Foundation
import MPAKX
import UIKit
// MARK: - Context
public protocol MicItemContext {
var activityDates: MPAK.Recent<Date?> { get }
var exReallyTest1: Bool? { get }
var reallyTest1: Bool { get }
var test2: Bool { get }
var test3: Bool { get }
var test4: Bool { get }
var test5: MPAK.Recent<Bool> { get }
var test6: MPAK.Recent<Bool> { get }
var test7: MPAK.Recent<Bool> { get }
var timeout: Bool { get }
}
extension MicItem {
// MARK: - Model
public struct Model: MicItemContext {
public var activityDates: MPAK.Recent<Date?> = .init(nil)
public var exReallyTest1: Bool? = nil
public var reallyTest1: Bool = false
public var test2: Bool = false
public var test3: Bool = false
public var test4: Bool = false
public var test5: MPAK.Recent<Bool> = .init(false)
public var test6: MPAK.Recent<Bool> = .init(false)
public var test7: MPAK.Recent<Bool> = .init(false)
public var timeout: Bool = false
}
// MARK: - Controller
final class Controller: MPAK.Controller<MicItem.Model> {
init(_ id: String? = nil) {
var sid = ""
if let id {
sid = " : \(id)"
}
super.init(
MicItem.Model(),
debugClassName: "MicItemCtrl",
debugLog: { aelog("\($0)\(sid)") }
)
// Отправляем модель в Шину.
m
.sink { v in Bus.send(Bus.keyId("MicItem", id), v) }
.store(in: &subscriptions)
pipeValue(
dbg: "activityD",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.activityDates, id), $0) }.map { (k: String, v: Date?) in v }.eraseToAnyPublisher(),
{
$0.activityDates.value = $1
$0.activityDates.isRecent = true
},
{ m, _ in m.activityDates.isRecent = false }
)
pipeValue(
dbg: "reallyT",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.reallyTest1, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{
$0.reallyTest1.value = $1
$0.reallyTest1.isRecent = true
},
{
$0.reallyTest1.isRecent = false
$0.exReallyTest1 = $1
}
)
pipeValue(
dbg: "test2",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.test2, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{ $0.test2 = $1 }
)
pipeValue(
dbg: "test3",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.test3, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{ $0.test3 = $1 },
{ m, _ in m.test3 = nil }
)
pipeValue(
dbg: "test5",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(D.test5, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{
$0.test5.value = $1
$0.test5.isRecent = true
},
{ m, _ in m.test5.isRecent = false }
)
pipeValue(
dbg: "test6",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.abc, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{
$0.test6.value = $1
$0.test6.isRecent = true
},
{ m, _ in m.test6.isRecent = false }
)
pipeValue(
dbg: "test7",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(D.def, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{
$0.test7.value = $1
$0.test7.isRecent = true
},
{ m, _ in m.test7.isRecent = false }
)
pipe(
dbg: "timeout",
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.timeout, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{ $0.timeout = true },
{ $0.timeout = false }
)
}
}
}

View File

@@ -1,56 +0,0 @@
import BusX
import MPAKX
public protocol MicItemContext {
var activityDate: MPAK.Recent<Date?> { get }
var timeout: Bool { get }
}
extension MicItem {
public struct Model: MicItemContext {
public var activityDate: MPAK.Recent<Date?> = .init(nil)
public var timeout: Bool = false
}
}
extension MicItem {
final class Controller: MPAK.Controller<MicItem.Model> {
init(_ id: String? = nil) {
var sid = ""
if let id {
sid = " : \(id)"
}
super.init(
MicItem.Model(),
debugClassName: "MicICtrl",
debugLog: { print("\($0)\(sid)") }
)
// Нижеследующее предстоит сгенерить.
m
.sink { v in Bus.send(Bus.keyId(K.MI, id), v) }
.store(in: &subscriptions)
pipeValue(
dbg: "activityD",
sub: nil,
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.activityDate, id), $0) }.map { (k: String, v: Date?) in v }.eraseToAnyPublisher(),
{
$0.activityDate.value = $1
$0.activityDate.isRecent = true
},
{ m, _ in m.activityDate.isRecent = false }
)
pipe(
dbg: "timeout",
sub: nil,
Bus.events.compactMap { Bus.convertKeyValue(Bus.keyId(K.timeout, id), $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(),
{ $0.timeout = true },
{ $0.timeout = false }
)
}
}
}