From b9ca315dadc510d7d0a19d08f4ecb2198c79365e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Fri, 26 Jan 2024 18:41:05 +0300 Subject: [PATCH] d --- Modules/MicX/Mic/Mic.yml | 4 ++++ Modules/MicX/Mic/src/Mic.Generated.swift | 20 +++++++++++++++++ Modules/MicX/Mic/src/Mic.K.swift | 1 + Modules/MicX/Mic/src/Mic.Shoulds.swift | 12 ++++++++++ src/App.swift | 28 +++++++++--------------- 5 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 Modules/MicX/Mic/src/Mic.Shoulds.swift diff --git a/Modules/MicX/Mic/Mic.yml b/Modules/MicX/Mic/Mic.yml index 054adcc..eae0bd4 100644 --- a/Modules/MicX/Mic/Mic.yml +++ b/Modules/MicX/Mic/Mic.yml @@ -1,10 +1,14 @@ version: 2 model: + activeIds: [[String], []] activityDates: [[String:Date], [:]] service: + actions: + shouldResetActivityDates: Bus.send(K.activityDates, v) pipes: + activeIds: [recent, K.activeIds] activityDates: [recent, K.activityDates] world: diff --git a/Modules/MicX/Mic/src/Mic.Generated.swift b/Modules/MicX/Mic/src/Mic.Generated.swift index cddc486..7d0edcf 100644 --- a/Modules/MicX/Mic/src/Mic.Generated.swift +++ b/Modules/MicX/Mic/src/Mic.Generated.swift @@ -11,6 +11,7 @@ import UIKit // MARK: - Context public protocol MicContext { + var activeIds: MPAK.Recent<[String]> { get } var activityDates: MPAK.Recent<[String:Date]> { get } } @@ -32,6 +33,7 @@ extension Mic { // MARK: - Model public struct Model: MicContext { + public var activeIds: MPAK.Recent<[String]> = .init([]) public var activityDates: MPAK.Recent<[String:Date]> = .init([:]) } @@ -76,10 +78,28 @@ extension Mic { ) { // MARK: - SectionGenerated Service Actions + ctrl.m + .compactMap { shouldResetActivityDates($0) } + .receive(on: DispatchQueue.main) + .sink { v in Bus.send(K.activityDates, v) } + .store(in: &service.subscriptions) // MARK: - SectionGenerated Service Pipes + 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, diff --git a/Modules/MicX/Mic/src/Mic.K.swift b/Modules/MicX/Mic/src/Mic.K.swift index 869eb58..16c90a9 100644 --- a/Modules/MicX/Mic/src/Mic.K.swift +++ b/Modules/MicX/Mic/src/Mic.K.swift @@ -1,5 +1,6 @@ public extension Mic { enum K { + public static let activeIds = "Mic.activeIds" public static let activityDate = "Mic.activityDate" public static let activityDates = "Mic.activityDates" public static let isActive = "Mic.isActive" diff --git a/Modules/MicX/Mic/src/Mic.Shoulds.swift b/Modules/MicX/Mic/src/Mic.Shoulds.swift new file mode 100644 index 0000000..423d533 --- /dev/null +++ b/Modules/MicX/Mic/src/Mic.Shoulds.swift @@ -0,0 +1,12 @@ +public extension Mic { + /// Следует обновить словарь состояний звуковой активности + /// + /// Условия: + /// 1. ??? + /// + /// - Returns: Словарь активных состояний + static func shouldResetActivityDates(_ c: MicContext) -> [String: Date]? { + + return nil + } +} diff --git a/src/App.swift b/src/App.swift index 97e8df1..8e034a2 100644 --- a/src/App.swift +++ b/src/App.swift @@ -111,25 +111,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate } func testMic4() { - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - Bus.send( - Mic.K.activityDates, - [ - "1": Date().addingTimeInterval(3), - "2": Date().addingTimeInterval(5), - ] - ) - } + delayedSend(2, Mic.K.activeIds, ["1"]) + delayedSend(4, Mic.K.activeIds, ["1", "4"]) + } - DispatchQueue.main.asyncAfter(deadline: .now() + 4) { - Bus.send( - Mic.K.activityDates, - [ - "1": Date().addingTimeInterval(2), - "4": Date().addingTimeInterval(5), - ] - ) + func delayedSend( + _ delay: TimeInterval, + _ key: String, + _ value: Any + ) { + DispatchQueue.main.asyncAfter(deadline: .now() + delay) { + Bus.send(key, value) } - } }