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.

Aside of `promiseFn`, also provide just a `promise` property, to be able to run with existing promise

See original GitHub issue

Hi. Thanks for this good work!

TL/DR: the requested feature would allow to simplify this

{searchResultPromise && (
          <Async promiseFn={() => searchResultPromise}>
            <Async.Loading>{<ProgressBar />}</Async.Loading>
            <Async.Resolved>
              {searchResult => (<ul>...</ul>)}
            </Async.Resolved>
          </Async>
        )}

Into this:

<Async promise={searchResultPromise}>
  <Async.Loading>{<ProgressBar />}</Async.Loading>
  <Async.Resolved>
    {searchResult => (<ul>...</ul>)}
  </Async.Resolved>
</Async>

Rationale: Using the promise-based UI patterns, a realm of a module like this one, I find myself quite often in need of having the code for controlling when to start the promise (the logic that would normally go to promiseFn) outside of the ‘present the loader or the results’ component. Sometimes it is enforced on me due to pre-existent decomposition of the code (separate component with the form for triggering the action).

I found that a good way to tackle this in a utility like this module, is to allow it to work with an existent promise. It would use ‘existence of the promise’ as an indicator that the run has started. ‘lack of a promise’, in turn, would be an indicator that the whole component shouldn’t show at all yet, because the user hasn’t started the action yet (NOTE: this second requirement is also a must for this feature to be useful for these frequent use cases).

Notably, I also found that a feature like that is already offered by many of the ‘promise pending/resolved/errored’ NPM modules, (including a popular one - the react-promise), so I do feel it is a proven common pattern.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
ghengeveldcommented, Mar 29, 2019

Okay, I decided to go along with it and renamed waiting to initial. Thanks for the feedback.

1reaction
ghengeveldcommented, Mar 3, 2019

Shipped in v5.0.0 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

RFC: First class support for promises and async/await #229
Introduces the use Hook. Like await , use unwraps the value of a promise, but it can be used inside normal components and...
Read more >
Primary Estoppel Explained, With Requirements & Example
Promissory estoppel is the legal principle defining that a promise is enforceable by law when a party who relies on that promise suffers...
Read more >
Strange infinite recursion behavior with Promises
The way I solved that problem was assigning the Promise factory to obj._validate instead of reassigning obj.validate and use _validate(ctx) ...
Read more >
The Enforcement of Oral Promises to Give Real Estate Security
Theodore A. Smedley, The Enforcement of Oral Promises to Give Real Estate Security, 2 Wash. &. Lee L. Rev. 210 (1940). Available at: ......
Read more >
The Guide to Promises in Computed Properties - Ember Igniter
The need to return a promise in a computed property very likely ... All services offered by a module should be available through...
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