d
This commit is contained in:
@@ -14,13 +14,13 @@ extension Bus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Обрабатываем.
|
/// Обрабатываем.
|
||||||
static func processKeyValue<Src, Dst>(
|
static func processKeysValue<Src, Dst>(
|
||||||
_ v: (key: String, value: Any),
|
_ v: (key: String, value: Any),
|
||||||
_ keyIn: String,
|
_ keysIn: Set<String>,
|
||||||
_ handler: @escaping ((Src) -> Dst?)
|
_ handler: @escaping ((Src) -> Dst?)
|
||||||
) -> Dst? {
|
) -> Dst? {
|
||||||
guard
|
guard
|
||||||
v.key == keyIn,
|
keysIn.contains(v.key),
|
||||||
let vIn = v.value as? Src
|
let vIn = v.value as? Src
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -10,7 +10,16 @@ public extension Bus {
|
|||||||
_ handler: @escaping ((Src) -> Dst?),
|
_ handler: @escaping ((Src) -> Dst?),
|
||||||
opt: [Option] = []
|
opt: [Option] = []
|
||||||
) {
|
) {
|
||||||
Bus.process(keyIn, keyOut, handler, opt: opt, sub: &subscriptions)
|
Bus.process([keyIn], keyOut, handler, opt: opt, sub: &subscriptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(
|
||||||
|
_ keysIn: Set<String>,
|
||||||
|
_ keyOut: String,
|
||||||
|
_ handler: @escaping ((Src) -> Dst?),
|
||||||
|
opt: [Option] = []
|
||||||
|
) {
|
||||||
|
Bus.process(keysIn, keyOut, handler, opt: opt, sub: &subscriptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public extension Bus {
|
|||||||
|
|
||||||
public extension Bus {
|
public extension Bus {
|
||||||
static func process<Src, Dst>(
|
static func process<Src, Dst>(
|
||||||
_ keyIn: String,
|
_ keysIn: Set<String>,
|
||||||
_ keyOut: String,
|
_ keyOut: String,
|
||||||
_ handler: @escaping ((Src) -> Dst?),
|
_ handler: @escaping ((Src) -> Dst?),
|
||||||
opt: [Option] = [],
|
opt: [Option] = [],
|
||||||
@@ -108,7 +108,7 @@ public extension Bus {
|
|||||||
// Async.
|
// Async.
|
||||||
if isAsync {
|
if isAsync {
|
||||||
subscription = Service.singleton.events
|
subscription = Service.singleton.events
|
||||||
.compactMap { processKeyValue($0, keyIn, handler) }
|
.compactMap { processKeysValue($0, keysIn, handler) }
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { vOut in Service.singleton.send(keyOut, vOut) }
|
.sink { vOut in Service.singleton.send(keyOut, vOut) }
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ public extension Bus {
|
|||||||
// Sync.
|
// Sync.
|
||||||
if !isAsync {
|
if !isAsync {
|
||||||
subscription = Service.singleton.events
|
subscription = Service.singleton.events
|
||||||
.compactMap { processKeyValue($0, keyIn, handler) }
|
.compactMap { processKeysValue($0, keysIn, handler) }
|
||||||
.sink { vOut in Service.singleton.send(keyOut, vOut) }
|
.sink { vOut in Service.singleton.send(keyOut, vOut) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user