Михаил Капелько 10 months ago
parent
commit
1c864231ec
5 changed files with 51 additions and 3 deletions
  1. +4
    -1
      Modules/MicX/Mic/Mic.yml
  2. +21
    -1
      Modules/MicX/Mic/src/Mic.Generated.swift
  3. +1
    -0
      Modules/MicX/Mic/src/Mic.K.swift
  4. +24
    -1
      Modules/MicX/Mic/src/Mic.Shoulds.swift
  5. +1
    -0
      Modules/MicX/MicItem/src/MicItem.V.swift

+ 4
- 1
Modules/MicX/Mic/Mic.yml View File

@@ -3,12 +3,15 @@ version: 2
model:
activeIds: [[String], []]
activityDates: [[String:Date], [:]]
requestActivityDate: [String?, nil]

service:
actions:
shouldResetActivityDates: Bus.send(K.activityDates, v);Bus.deliver(K.activityDate, v)
shouldDeliverActivityDates: Bus.deliver(K.activityDate, v)
shouldResetActivityDates: Bus.send(K.activityDates, v)
pipes:
activeIds: [recent, K.activeIds]
activityDates: [recent, K.activityDates]
requestActivityDate: [toggleNil, K.requestActivityDate]

world:

+ 21
- 1
Modules/MicX/Mic/src/Mic.Generated.swift View File

@@ -13,6 +13,7 @@ import UIKit
public protocol MicContext {
var activeIds: MPAK.Recent<[String]> { get }
var activityDates: MPAK.Recent<[String:Date]> { get }
var requestActivityDate: String? { get }
}

// MARK: - Controller
@@ -35,6 +36,7 @@ extension Mic {
public struct Model: MicContext {
public var activeIds: MPAK.Recent<[String]> = .init([])
public var activityDates: MPAK.Recent<[String:Date]> = .init([:])
public var requestActivityDate: String? = nil
}

// MARK: - Service
@@ -78,10 +80,15 @@ extension Mic {
) {
// MARK: - SectionGenerated Service Actions

ctrl.m
.compactMap { shouldDeliverActivityDates($0) }
.receive(on: DispatchQueue.main)
.sink { v in Bus.deliver(K.activityDate, v) }
.store(in: &service.subscriptions)
ctrl.m
.compactMap { shouldResetActivityDates($0) }
.receive(on: DispatchQueue.main)
.sink { v in Bus.send(K.activityDates, v);Bus.deliver(K.activityDate, v) }
.sink { v in Bus.send(K.activityDates, v) }
.store(in: &service.subscriptions)


@@ -113,6 +120,19 @@ extension Mic {



ctrl.pipeValue(
dbg: "requestAD",
sub: nil,
Bus.events.compactMap { Bus.convertKeyValue(K.requestActivityDate, $0) }.map { (k: String, v: String?) in v }.eraseToAnyPublisher(),
{ $0.requestActivityDate = $1 },
{ m, _ in m.requestActivityDate = nil }
)







}



+ 1
- 0
Modules/MicX/Mic/src/Mic.K.swift View File

@@ -5,6 +5,7 @@ public extension Mic {
public static let activityDates = "Mic.activityDates"
public static let isActive = "Mic.isActive"
public static let MI = "Mic.Model.Item"
public static let requestActivityDate = "Mic.requestActivityDate"
public static let timeout = "Mic.timeout"
}
}

+ 24
- 1
Modules/MicX/Mic/src/Mic.Shoulds.swift View File

@@ -1,8 +1,31 @@
public extension Mic {
/// Следует доставить состояния звуковой активности элементам
///
/// Условия:
/// 1. Изменились даты активности
/// 2. Элемент запросил свою дату активности
///
/// - Returns: Словарь состояний
static func shouldDeliverActivityDates(_ c: MicContext) -> [String: Date]? {
if let ad = shouldResetActivityDates(c) {
return ad
}

if
let id = c.requestActivityDate,
let timeout = c.activityDates.value[id],
timeout > Date()
{
return [id: timeout]
}

return nil
}

/// Следует обновить словарь состояний звуковой активности
///
/// Условия:
/// 1. ???
/// 1. Пришли id активных участников
///
/// - Returns: Словарь активных состояний
static func shouldResetActivityDates(_ c: MicContext) -> [String: Date]? {


+ 1
- 0
Modules/MicX/MicItem/src/MicItem.V.swift View File

@@ -27,6 +27,7 @@ extension MicItem {
.animation(.easeInOut(duration: 0.3))
.onAppear {
isActive.id = id
Bus.send(K.requestActivityDate, id)
}
.onChange(of: id) { newValue in
isActive.id = newValue


Loading…
Cancel
Save