Swiftgram/submodules/Postbox/Postbox/PostboxView.swift
Peter 4459dc5b47 Add 'submodules/Postbox/' from commit '534443c710e63ff4ea595b5dc7be94550c467734'
git-subtree-dir: submodules/Postbox
git-subtree-mainline: 373769682ef152a8d5ef41ccb064a8387b2ca6f0
git-subtree-split: 534443c710e63ff4ea595b5dc7be94550c467734
2019-06-11 18:56:39 +01:00

44 lines
1.1 KiB
Swift

import Foundation
public protocol PostboxView {
}
protocol MutablePostboxView {
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool
func immutableView() -> PostboxView
}
final class CombinedMutableView {
private let views: [PostboxViewKey: MutablePostboxView]
init(views: [PostboxViewKey: MutablePostboxView]) {
self.views = views
}
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
var updated = false
for (_, view) in self.views {
if view.replay(postbox: postbox, transaction: transaction) {
updated = true
}
}
return updated
}
func immutableView() -> CombinedView {
var result: [PostboxViewKey: PostboxView] = [:]
for (key, view) in self.views {
result[key] = view.immutableView()
}
return CombinedView(views: result)
}
}
public final class CombinedView {
public let views: [PostboxViewKey: PostboxView]
init(views: [PostboxViewKey: PostboxView]) {
self.views = views
}
}