Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Combine #549

Merged
merged 8 commits into from
Jun 13, 2019
Merged

Support for Combine #549

merged 8 commits into from
Jun 13, 2019

Conversation

groue
Copy link
Owner

@groue groue commented Jun 12, 2019

This PR provides the necessary tooling for the new companion library GRDBCombine, which extends GRDB with tools dedicated to the Combine framework.

  • The ValueObservation.trackingCount/All/One methods are deprecated. Now please use instead the observationForCount/All/First request methods:

    -let observation1 = ValueObservation.trackingAll(Player.all())
    -let observation2 = ValueObservation.trackingOne(Player.filter(key: 42))
    +let observation1 = Player.observationForAll()
    +let observation2 = Player.filter(key: 42).observationForFirst()
  • The ValueObservation.start(in:onError:onChange:) method used to always access the database synchronously - despite some documentation claims. It now no longer does, when the observation is configured for asynchronous dispatching. This makes sure that starting an observation does not block your current thread if a long-running write transaction is running in a background thread:

    // Current queue is the main queue.
    //
    // Unchanged: an observation configured for synchronous notification
    // of its initial value is accessing the database right on start.
    let observation1 = Player.observationForAll()
    observation1.start(
        in: dbQueue,
        onError: { ... },
        onChange: { (players: [Player]) in print("fresh players: \(players)") })
    // Unchanged: here "fresh players" is guaranteed to be printed.
    
    // NEW: An observation configured for asynchronous dispatch
    // of its initial value is no longer accessing the database right on start:
    var observation2 = Player.observationForAll()
    observation2.scheduling = .async(onQueue: .main, startImmediately: true)
    observation2.start(
        in: dbQueue,
        onError: { ... },
        onChange: { (players: [Player]) in print("fresh players: \(players)") })
    // Unchanged: here "fresh players" is not printed. It will, eventually.
  • The ValueObservation.start(in:onError:onChange:) method is no longer throwing when you provide an error callback. All database errors are then guaranteed to be sent to this callback, even synchronous startup errors.

  • The ValueObservation.combine method has been enhanced:

    // NEW: up to eight observations
    let observation = ValueObservation.combine(obs1, obs2, ..., obs8)
    // NEW: combine instance method:
    let observation = obs1.combine(obs2) { value1, value2 in ... }
  • The ValueObservation.distinctUntilChanged() method has been deprecated in favor of removeDuplicates(). Yes, yes, GRDB will follow the naming conventions of Combine when they do not match ReactiveX.

@groue groue added this to the GRDB 4.1.0 milestone Jun 12, 2019
@groue groue merged commit 47b8130 into development Jun 13, 2019
@groue groue mentioned this pull request Jun 14, 2019
10 tasks
@groue groue deleted the dev/CombineSupport branch June 22, 2019 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant