-
-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sessions table view model refactoring (#703)
* Sessions table view model refactoring * Fix search coordinator delegate issue, videos tab working well, experimenting with schedule tab solution * Split filtering config for each tab, critical functionality working * Make filters react to storage changes * Simply filter setup code by being smart * Continuing to put things back together * Additional work on filtering observation * Do schedules live filtering too * Minor cleanup * Incorporate now playing into filtering to prevent UX confusion * Clean up AppCoordinator and have a look at performance * A few more optimizations * Realm updates are very fast now * Add schema migration * Wrap up the final fixes I think * Clean up and final improvements
- Loading branch information
1 parent
08b8ad1
commit f816d00
Showing
41 changed files
with
1,468 additions
and
1,015 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Packages/ConfCore/ConfCore/RealmCollection+ShallowChangesetPublisher.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Created by Allen Humphreys on 7/3/23. | ||
// | ||
|
||
import Combine | ||
import RealmSwift | ||
|
||
/// This is required to preserve the `subscribe(on:)` capabilities of `changesetPublisher` while filtering out | ||
/// elements that don't contain insertions or removals | ||
public struct ShallowCollectionChangsetPublisher<Collection: RealmCollection>: Publisher { | ||
public typealias Output = Collection | ||
/// This publisher reports error via the `.error` case of RealmCollectionChange. | ||
public typealias Failure = Error | ||
|
||
let upstream: RealmPublishers.CollectionChangeset<Collection> | ||
|
||
init(collectionChangesetPublisher: RealmPublishers.CollectionChangeset<Collection>) { | ||
self.upstream = collectionChangesetPublisher | ||
} | ||
|
||
public func receive<S>(subscriber: S) where S: Subscriber, Collection == S.Input, S.Failure == Error { | ||
upstream | ||
.tryCompactMap { changeset in | ||
switch changeset { | ||
case .initial(let latestValue): | ||
return latestValue | ||
case .update(let latestValue, let deletions, let insertions, _) where !deletions.isEmpty || !insertions.isEmpty: | ||
return latestValue | ||
case .update: | ||
return nil | ||
case .error(let error): | ||
throw error | ||
} | ||
} | ||
.receive(subscriber: subscriber) | ||
} | ||
|
||
public func subscribe<S: Scheduler>(on scheduler: S) -> some Publisher<Collection, Error> { | ||
ShallowCollectionChangsetPublisher(collectionChangesetPublisher: upstream.subscribe(on: scheduler)) | ||
} | ||
} | ||
|
||
public extension RealmCollection where Self: RealmSubscribable { | ||
/// Similar to `changesetPublisher` but only emits a new value when the collection has additions or removals and ignores all upstream | ||
/// values caused by objects being modified | ||
var changesetPublisherShallow: ShallowCollectionChangsetPublisher<Self> { | ||
ShallowCollectionChangsetPublisher(collectionChangesetPublisher: changesetPublisher) | ||
} | ||
|
||
/// Similar to `changesetPublisher(keyPaths:)` but only emits a new value when the collection has additions or removals and ignores all upstream | ||
/// values caused by objects being modified | ||
func changesetPublisherShallow(keyPaths: [String]) -> ShallowCollectionChangsetPublisher<Self> { | ||
ShallowCollectionChangsetPublisher(collectionChangesetPublisher: changesetPublisher(keyPaths: keyPaths)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.