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

RxDB observers emit data when results are not affected #31

Closed
thani-sh opened this issue Jan 20, 2017 · 5 comments
Closed

RxDB observers emit data when results are not affected #31

thani-sh opened this issue Jan 20, 2017 · 5 comments

Comments

@thani-sh
Copy link
Contributor

I tried RxDB with the localstorage adapter. If I create an observer for a query and subscribe and then edit a document which do not come under the query's result. The observer will emit the result data again. Is this something RxDB wishes to solve? If interested, I can start a pull-request for this.

@pubkey
Copy link
Owner

pubkey commented Jan 20, 2017

@mnmtanish just to make sure I fully understood what you mean:

Current behaviour: When a RxQuery is observed and the collection changes data, the full result of the query is emited again, even when it is not affected by the data-change.

Your goal: When a RxQuery is observed and the collection changes data, the full result of the query is emited only if the query-result is affected by the data-change.

Did I get this right?

@thani-sh
Copy link
Contributor Author

Yeah, although I'm not sure how to do it without slowing down RxDB. I thought of 2 ways to do this. I'm not sure which one will be faster or even whether RxDB needs this feature built into it.

1. Wrap the result observer
Wrap the result observer, and when it emits, compare the result with the previous result and emit only if it changes.

function wrap(input: Observer<any>): Observer<any> {
  let prev = null
  return input.filter(data => {
    if(deepEqual(data, prev)) {
      return false
    }
    prev = data
    return true
  })
}

2. Re-run queries on changes
The documents should have an id to identify them. When updating a collection, take the updated document ids updatedIds. Re-run all queries in the collection and get result document ids. If updated ids are there in result ids, emit results for tat query.


I'm planning to use RxDB result observers with Angular2. I'm looking for a way to avoid unnecessary UI renders. I did hear that Angular2 is smart about tracking changes so maybe It'll be faster if Angular2 did this itself. I'll start the PR if you thinks it'll be good for RxDB.

@pubkey
Copy link
Owner

pubkey commented Jan 21, 2017

@mnmtanish could you confirm or deny that the test in b83da08 describes what you want?
The code there basically does what you want, but I will refactor the RxQuery-observables in the near future, so please check the test.

EDIT: Also check 39fbf5b

@thani-sh
Copy link
Contributor Author

thani-sh commented Jan 21, 2017

Yes, 39fbf5b describes it

@pubkey pubkey closed this as completed in b83da08 Jan 23, 2017
@pubkey pubkey reopened this Jan 23, 2017
@pubkey
Copy link
Owner

pubkey commented Jan 23, 2017

@mnmtanish I released the version 2.0.0 which covers the test.
See CHANGELOG

Please check it out and tell me if all is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants