@@ -1,13 +1,16 @@ | |||||
version: 2 | version: 2 | ||||
model: | model: | ||||
isLoading: [Bool, false] | |||||
join: [Bool, false] | join: [Bool, false] | ||||
textUI: [String, ""] | textUI: [String, ""] | ||||
service: | service: | ||||
actions: | actions: | ||||
busModel | busModel | ||||
🚀shouldResetLoading: Bus.send(K.isLoading, v) | |||||
pipes: | pipes: | ||||
isLoading: [recent, K.isLoading] | |||||
join: [toggle, K.join] | join: [toggle, K.join] | ||||
textUI: [recent, K.textUI] | textUI: [recent, K.textUI] | ||||
@@ -12,6 +12,7 @@ import UIKit | |||||
// MARK: - Context | // MARK: - Context | ||||
public protocol MeetupIdContext { | public protocol MeetupIdContext { | ||||
var isLoading: MPAK.Recent<Bool> { get } | |||||
var join: Bool { get } | var join: Bool { get } | ||||
var textUI: MPAK.Recent<String> { get } | var textUI: MPAK.Recent<String> { get } | ||||
} | } | ||||
@@ -34,6 +35,7 @@ extension MeetupId { | |||||
// MARK: - Model | // MARK: - Model | ||||
public struct Model: MeetupIdContext { | public struct Model: MeetupIdContext { | ||||
public var isLoading: MPAK.Recent<Bool> = .init(false) | |||||
public var join: Bool = false | public var join: Bool = false | ||||
public var textUI: MPAK.Recent<String> = .init("") | public var textUI: MPAK.Recent<String> = .init("") | ||||
} | } | ||||
@@ -83,10 +85,27 @@ extension MeetupId { | |||||
ctrl.m | ctrl.m | ||||
.sink { v in Bus.send("MeetupId", v) } | .sink { v in Bus.send("MeetupId", v) } | ||||
.store(in: &service.subscriptions) | .store(in: &service.subscriptions) | ||||
ctrl.m | |||||
.compactMap { shouldResetLoading($0) } | |||||
.sink { v in Bus.send(K.isLoading, v) } | |||||
.store(in: &service.subscriptions) | |||||
// MARK: - SectionGenerated Service Pipes | // MARK: - SectionGenerated Service Pipes | ||||
ctrl.pipeValue( | |||||
dbg: "isL", | |||||
sub: nil, | |||||
Bus.events.compactMap { Bus.convertKeyValue(K.isLoading, $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(), | |||||
{ | |||||
$0.isLoading.value = $1 | |||||
$0.isLoading.isRecent = true | |||||
}, | |||||
{ m, _ in m.isLoading.isRecent = false } | |||||
) | |||||
ctrl.pipe( | ctrl.pipe( | ||||
dbg: "join", | dbg: "join", | ||||
sub: nil, | sub: nil, | ||||
@@ -1,6 +1,7 @@ | |||||
public extension MeetupId { | public extension MeetupId { | ||||
enum K { | enum K { | ||||
static let isJoinAvailable = "MeetupId.isJoinAvailable" | static let isJoinAvailable = "MeetupId.isJoinAvailable" | ||||
static let isLoading = "MeetupId.isLoading" | |||||
static let join = "MeetupId.join" | static let join = "MeetupId.join" | ||||
static let M = "MeetupId" | static let M = "MeetupId" | ||||
static let textApp = "MeetupId.textApp" | static let textApp = "MeetupId.textApp" | ||||
@@ -15,4 +15,16 @@ public extension MeetupId { | |||||
return nil | return nil | ||||
} | } | ||||
static func shouldResetLoading(_ c: MeetupIdContext) -> Bool? { | |||||
if | |||||
c.join, | |||||
!c.isLoading.value | |||||
{ | |||||
return true | |||||
} | |||||
return nil | |||||
} | |||||
} | } |
@@ -6,24 +6,25 @@ extension MeetupId { | |||||
public struct V: View { | public struct V: View { | ||||
@StateObject var fmt = MeetupId.Formatter(K.textUI, K.textApp) | @StateObject var fmt = MeetupId.Formatter(K.textUI, K.textApp) | ||||
@StateObject var isJA = Cord.Receive(K.isJoinAvailable, false) | @StateObject var isJA = Cord.Receive(K.isJoinAvailable, false) | ||||
@StateObject var isL = Cord.Receive(K.isLoading, false) | |||||
@StateObject var join = Cord.Button(K.join) | @StateObject var join = Cord.Button(K.join) | ||||
@StateObject var txtF = Cord.TextField(K.textApp, K.textUI) | @StateObject var txtF = Cord.TextField(K.textApp, K.textUI) | ||||
let joinA = Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable) | |||||
let pSEJ = Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable) | |||||
let pSRL = Bus.Processor(shouldResetLoading, K.M, K.isLoading) | |||||
public init() { } | public init() { } | ||||
public var body: some View { | public var body: some View { | ||||
VStack { | VStack { | ||||
HStack { | HStack { | ||||
Text("Check text field:") | |||||
Text("'\(txtF.value)'") | |||||
.fontWeight(.bold) | |||||
TextField("Binding-3", value: $txtF.value, formatter: Cord.TextFieldValueOwner()) | |||||
.padding(8) | |||||
.border(Color.blue, width: 2) | |||||
if isL.value { | |||||
ProgressView() | |||||
} | |||||
} | } | ||||
TextField("Binding-3", value: $txtF.value, formatter: Cord.TextFieldValueOwner()) | |||||
.padding(8) | |||||
.border(Color.blue, width: 2) | |||||
Button(action: join.press.send) { | Button(action: join.press.send) { | ||||
Text("Join") | Text("Join") | ||||
.padding(8) | .padding(8) | ||||