Skip to content

Conversation

@Aschen
Copy link
Contributor

@Aschen Aschen commented Nov 29, 2021

What does this PR do ?

Depends on #672

Add an Observer class to manipulate RealtimeDocument.

Those documents have the same structure as the Document object from the Document Controller except that they are connected to the realtime engine and their content will mutate when a realtime notification about changes is received.

const observer = new Observer(sdk);

// SearchResult containing realtime documents
let realtimeResult = await observer.search('nyc-open-data', 'yellow-taxi', { query }, options);

// Dispose ressources (realtime connection + memory)
observer.stop('nyc-open-data', 'yellow-taxi');

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Nov 29, 2021

This pull request introduces 1 alert when merging 8c5c0fc into 7cf06a5 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

/**
* Unsubscribe from every collections and clear all the realtime documents.
*/
dispose () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is a stop method, i would call it stopAll () instead wdyt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was thinking about having only one method that can take index & collection, index & collection & documents or nothing to stop subscriptions.
I will update and you can tell me

Copy link
Member

@rolljee rolljee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a nit on naming convention

and also linting is surely necessary :)

@Aschen Aschen changed the base branch from master to 7-dev November 30, 2021 13:17
@Aschen Aschen marked this pull request as draft November 30, 2021 13:17
@Aschen Aschen requested a review from rolljee November 30, 2021 13:17
@Aschen Aschen marked this pull request as ready for review December 3, 2021 08:40
@codecov
Copy link

codecov bot commented Dec 3, 2021

Codecov Report

Merging #671 (f1f40c1) into 7-dev (948a042) will increase coverage by 0.32%.
The diff coverage is 88.39%.

❗ Current head f1f40c1 differs from pull request most recent head ffeca3c. Consider uploading reports for the commit ffeca3c to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##            7-dev     #671      +/-   ##
==========================================
+ Coverage   83.45%   83.78%   +0.32%     
==========================================
  Files          36       39       +3     
  Lines        1771     1881     +110     
  Branches      325      342      +17     
==========================================
+ Hits         1478     1576      +98     
- Misses        227      237      +10     
- Partials       66       68       +2     
Impacted Files Coverage Δ
src/controllers/Document.ts 69.00% <50.00%> (ø)
src/core/searchResult/RealtimeDocument.ts 76.47% <76.47%> (ø)
src/core/Observer.ts 91.01% <91.01%> (ø)
src/core/RealtimeDocument.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 948a042...ffeca3c. Read the comment docs.

Copy link
Contributor

@xbill82 xbill82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP Review

Aschen and others added 4 commits December 5, 2021 13:52
Co-authored-by: Luca Marchesini <xbill82@gmail.com>
…leio/sdk-javascript into add-observer-and-realtime-documents
Aschen and others added 11 commits December 6, 2021 14:54
Co-authored-by: Luca Marchesini <xbill82@gmail.com>
Co-authored-by: Luca Marchesini <xbill82@gmail.com>
Co-authored-by: Luca Marchesini <xbill82@gmail.com>
…leio/sdk-javascript into add-observer-and-realtime-documents
@Aschen Aschen merged commit da78305 into 7-dev Dec 6, 2021
@Aschen Aschen deleted the add-observer-and-realtime-documents branch December 6, 2021 16:52
@Aschen Aschen added this to the 7.8.0 milestone Dec 6, 2021
@xbill82 xbill82 mentioned this pull request Dec 20, 2021
Aschen added a commit that referenced this pull request Jan 3, 2022
# [7.8.0](https://github.com/kuzzleio/sdk-javascript/releases/tag/7.8.0) (2021-12-20)


#### New features

- [ [#671](#671) ] Add Observer class   ([Aschen](https://github.com/Aschen))

#### Enhancements

- [ [#668](#668) ] Propagates every arguments to Kuzzle   ([Aschen](https://github.com/Aschen))
---
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.

4 participants