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.

Keep the previous value when creating a new instance?

See original GitHub issue

I am fetching and refetching new articles using the same function, which looks like:

@action.bound
fetchArticles() {
    this.articles = fromPromise(fetch("http://someurl"))
}

…and I am switching over store.articles.state to render a loading state, error state, and fulfilled state.

However, when re-fetching by calling this function again, it causes my view to go back into the loading state (which says “loading”). I am not really a fan of this approach, since what I would like to do here is to display the old state, which is the old list of articles, until the fetch has resolved. Otherwise my view will flash into a loading state and back which is a bit too… noisy? There is too much going on.

Perhaps when re-fetching I would like to option to freeze articles.value so it doesn’t go into undefined, and when articles.state is pending and I have data inside articles.value I can still display this old value. I would imagine I would render the old values but at 0.5 opacity or something similar. Maybe something like:

switch(articles.state) {
     case ("pending" && articles.value): return results({ opacity: 0.5, pointerEvents: none })
     case "pending" : return preloading()
     case "rejected": return error()
     case "fulfilled": return results()
  }

Is this a use case that has been covered before? As I have been looking for a solution!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mweststratecommented, Oct 23, 2018

Idea, allow fromPromise to be passed in a previous PromiseBased observable to reflect the state of the old one, until the new one has resolved?

0reactions
mweststratecommented, Nov 19, 2018

Released as 5.1.0. Thanks @ItamarShDev!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python object keeping data from previous? - Stack Overflow
You are appending cards each time you instantiate, but you are appending them to the class variable. Thus you end up with twice...
Read more >
How can I maintain previous values for property in C# ...
I can do this by maintaining two object of test class(original and latest) but there might be lot of properties in a class...
Read more >
Object.assign() - JavaScript - MDN Web Docs
The Object.assign() method copies all enumerable own properties from one or more source objects to a target object.
Read more >
Python Class Constructors: Control Your Object Instantiation
Calling the Point() class constructor creates, initializes, and returns a new instance of the class. This instance is then assigned to the point ......
Read more >
Understanding Class Members (The Java™ Tutorials ...
In this section, we discuss the use of the static keyword to create fields and methods that belong to the class, rather than...
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