Updating an element in a observable list
See original GitHub issueThank 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:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
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 usingBehaviorSubject
s. 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 singleBehaviorSubject
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.