Skip to content

Docs in subscribed queries are always considered to be subscribed #468

Open
@alecgibson

Description

@alecgibson

At the moment, when you create a subscribe query, the query will automatically pass all ops back to the client, regardless of whether it wants to be subscribed or not. This can be quite confusing:

  • a Doc that matches a subscribe query will receive 'op' events, even though doc.subscribed === false
  • calling doc.unsubscribe() will not actually stop the doc receiving 'op' events

It's possible to make this behaviour a bit more consistent in a few ways:

  • check at the server if the client doc is subscribed, and only send ops back in that case
  • make connection.get() return new instances of docs rather than cached instances (which I've personally always expected) — this would allow individual Doc instances to be unsubscribed, while query.results stay subscribed

At the very least it might be nice to error in doc.unsubscribe() if the doc matches a query (and therefore cannot be unsubscribed). It may also be nice to change doc.subscribed into a method/getter which checks if it's part of a query, to reflect its "true" state

All of the above changes would technically be breaking.

One nice, non-breaking thing we could potentially do is to just logger.warn() if unsubscribing a doc that matches a query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeBreaking change that we may want to pull into a future major versiondocumentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions