|
-
-
-
- import AELog
- import BusX
- import Combine
- import Foundation
- import MPAKX
- import UIKit
-
-
-
- public protocol MicContext {
- var activeIds: MPAK.Recent<[String]> { get }
- var activityDates: MPAK.Recent<[String:Date]> { get }
- }
-
-
-
- extension Mic {
- final class Controller: MPAK.Controller<Mic.Model> {
- init() {
- super.init(
- Mic.Model(),
- debugClassName: "MicCtrl",
- debugLog: { aelog($0) }
- )
- }
- }
-
-
-
-
-
- public struct Model: MicContext {
- public var activeIds: MPAK.Recent<[String]> = .init([])
- public var activityDates: MPAK.Recent<[String:Date]> = .init([:])
- }
-
-
-
- public final class Service {
- let ctrl = Controller()
- let world: World
-
- var subscriptions = [AnyCancellable]()
- static private(set) weak var singleton: Service?
-
- public init(_ world: World) {
- self.world = world
- Self.singleton = self
- SectionGenerated.setupPlatform(ctrl, self, world)
- }
- }
-
-
-
- public struct World {
-
-
- public init(
-
- ) {
-
- }
- }
-
- enum SectionGenerated {
-
-
-
-
-
- static func setupPlatform(
- _ ctrl: Controller,
- _ service: Service,
- _ world: World
- ) {
-
-
- ctrl.m
- .compactMap { shouldResetActivityDates($0) }
- .receive(on: DispatchQueue.main)
- .sink { v in Bus.send(K.activityDates, v) }
- .store(in: &service.subscriptions)
-
-
-
-
- ctrl.pipeValue(
- dbg: "activeI",
- sub: nil,
- Bus.events.compactMap { Bus.convertKeyValue(K.activeIds, $0) }.map { (k: String, v: [String]) in v }.eraseToAnyPublisher(),
- {
- $0.activeIds.value = $1
- $0.activeIds.isRecent = true
- },
- { m, _ in m.activeIds.isRecent = false }
- )
-
-
-
- ctrl.pipeValue(
- dbg: "activityD",
- sub: nil,
- Bus.events.compactMap { Bus.convertKeyValue(K.activityDates, $0) }.map { (k: String, v: [String:Date]) in v }.eraseToAnyPublisher(),
- {
- $0.activityDates.value = $1
- $0.activityDates.isRecent = true
- },
- { m, _ in m.activityDates.isRecent = false }
- )
-
-
-
-
- }
-
- }
- }
|