question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Updating an element in a observable list

See original GitHub issue

Thank you for this awesome library.

Reviewing your example https://react-rxjs.org/docs/tutorial/github-issues I can see that there’s a good example of requesting a list of items form https://api.github.com/repos/${org}/${repo}/issues?per_page=25&page=${page}.

currentRepoAndPage$ is a merge of 2 source observables currentRepo$ and pageSelected$. When any of these source Subjects emit a new value

 currentRepoAndPage$.pipe(
    switchMap(({ page, repo, org }) =>
      getIssues(org, repo, page).pipe(startWith(SUSPENSE))
    )
  )

will re-execute.

The question; if I had an observable with a list of issues and I wanted to update one of the issues in the list, what would this look like? Would I update the item in the list from the component and call a function to push the new list into the Subject?

I also wondered if we could use BehaviorSubject instead of Subject?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
josepotcommented, Jan 17, 2021

However worth noting I believe it introduces a higher level of complexity than using BehaviorSubjects. But maybe it’s just another way of approaching the problem that I’m less familiar with

This library wants to promote a mental model where we avoid mutating state directly, because the we want to be able to define the dynamic behavior of the state at the time of its declaration. Therefore, if we adhere to this mental model, then we should try to use Subjects only for capturing external events, not as a means for mutating the state. This is indeed a quite radical mental-shift, but based in our experience, this mental model ends-up generating code that’s less complex and easier to maintain.

I’m going to close this issue, because as you said, I have already answered your question. However, feel free to keep commenting on it after it’s closed. Thanks!

0reactions
sbitprozcommented, Jan 1, 2021

Hi @josepot

Totally grateful for message, on new years day no less…

I like the way you’ve approached the solution with streams. I’ve applied your todo example with my state solution - but now I think I might adapt a little more to my use case. However worth noting I believe it introduces a higher level of complexity than using BehaviorSubjects. But maybe it’s just another way of approaching the problem that I’m less familiar with.

Although I understand that BehaviorSubject cache’s the last emitted value, I’m not sure that will produce a leak. In reality it’s just single BehaviorSubject instance representing the state with a cache which will be overwritten.

I freely admit, it maybe be down to my lack of understanding of what’s going on under the hood.

You have answered my question and I’ve read most of the library documentation, just wanted to soundboard the idea (BehaviorSubject). Really appreciate your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaFX: Update of ListView if an element of ObservableList ...
I created the ListView and added the list of persons as an ObservableList. Everything works fine if I delete or add a new...
Read more >
How we can update existing item in ObservableList. · Issue #312
Hi Team, Facing issue with ObservableList, How we can update existing item in ObservableList. I try to set using operator []=(int index, ...
Read more >
ListChangeListener.Change (JavaFX 17)
Represents a report of changes done to an ObservableList . The change may consist ... All elements between from (inclusive) and to (exclusive)...
Read more >
JavaFX: Update of ListView if an element of ... - iTecNote
The correct way of doing this is to supply your observable list with an "extractor" Callback. This will signal the list (and ListView)...
Read more >
Refresh view on change to observable list. — oracle-tech
I am trying to update the new value in observable list for that specific cell, but it doesn't refresh my view. Only when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found