Михаил Капелько 11 months ago
parent
commit
1a731e2fad
3 changed files with 28 additions and 2 deletions
  1. +13
    -0
      Modules/MicX/MicItem/src/MicItem.Shoulds.swift
  2. +2
    -2
      Modules/MicX/MicItem/src/MicItem.V.swift
  3. +13
    -0
      Modules/MicX/MicItem/src/MicItem.WillBe.swift

+ 13
- 0
Modules/MicX/MicItem/src/MicItem.Shoulds.swift View File

@@ -0,0 +1,13 @@
public extension MicItem {
static func shouldResetActivity(_ c: MicItemContext) -> Bool? {
if
c.activityDate.isRecent,
let end = c.activityDate.value,
let now = Date()
{
return now < end
}

return nil
}
}

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

@@ -5,13 +5,13 @@ extension MicItem {
public struct V: View {
var id: String?
@StateObject var isActive = BusUI.Value(K.isActive, false)
let ctrl = MicItem.Controller()
let processors: [Any]
public init(_ id: String? = nil) {
self.id = id
self.processors = [
//Bus.Sync(shouldResetActivity, K.MI, K.isActive),
Bus.Sync(shouldResetActivity, K.MI, K.isActive),
MicItem.Controller()
]
}


+ 13
- 0
Modules/MicX/MicItem/src/MicItem.WillBe.swift View File

@@ -9,7 +9,9 @@ extension MicItem {
public struct Model: MicItemContext {
public var activityDate: MPAK.Recent<Date?> = .init(nil)
}
}

extension MicItem {
final class Controller: MPAK.Controller<MicItem.Model> {
init() {
/**/print("MicIC.init")
@@ -24,6 +26,17 @@ extension MicItem {
m
.sink { v in Bus.send(K.MI, v) }
.store(in: &subscriptions)

pipeValue(
dbg: "activityD",
sub: nil,
Bus.events.compactMap { Bus.convertKeyValue(K.activityDate, $0) }.map { (k: String, v: Date?) in v }.eraseToAnyPublisher(),
{
$0.activityDate.value = $1
$0.activityDate.isRecent = true
},
{ m, _ in m.activityDate.isRecent = false }
)
}
}
}

Loading…
Cancel
Save