d
This commit is contained in:
13
Modules/MicX/MicItem/src/MicItem.Shoulds.swift
Normal file
13
Modules/MicX/MicItem/src/MicItem.Shoulds.swift
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user