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.

Pattern: Waiting for Stores?

See original GitHub issue

Hi,

Couldn’t find any documentation about this one, so I might be thinking of it completely wrong, but here’s my situation, would love to hear some thoughts about it:

My app has a login mechanism which eventually can send different actions (FB_LOGIN_SUCCESS, GOOGLE_LOGIN_SUCCESS, …) that are received by a reducer which stores a computed access-token.

I have a saga that needs to send a request with the access-token, so what I want to do in pseudo code in many of my different sagas is:

access-token = [select access token from store]
if [there isn't an access-token] then [wait for the store to have one]
[call api with access-token]

How can I do the [wait for store to have one]? What is the correct pattern here?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

10reactions
3LOKcommented, Apr 27, 2016

Thanks!

I don’t 100% love this idea (of going by action string, as it means my other sagas need to know about the actions of the login saga).

For the meanwhile, i simply have:

let accessToken = yield select(state => state.login.access);
while (accessToken === null) {
    yield take();
    let accessToken = yield select(state => state.login.access);
}

Not pretty at all, but works.

3reactions
yelouaficommented, Apr 27, 2016

Another way is to hold a reference to the task doing the login; and share it with the other Sagas needing to wait for a login for ex. by making it a param

function* saga(loginTask) {
  /*
      if loginTask has already completed this will resolve immediately
      otherwise it'll wait for the loginTask to start or complete (if it's already in progress)
  */
  yield join(loginTask)
  let accessToken = yield select(state => state.login.access);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

I am waiting for you in my store Kowshop - Pinterest
Technique: 2 drops brick stitch+fringe PDF file consists of: - Pattern (without bead color numbers). The colors used are indicated next to the...
Read more >
New Checkout Experience Seeks to Eliminate the Wait ...
All the cashiers in the store transitioned to a new type of job called 'Host.' It's the Host's job to make sure the...
Read more >
Is there a better waiting pattern for c#? - Stack Overflow
A much better way to implement this pattern is to have your Thing object expose an event on which the consumer can wait....
Read more >
Waiting pattern by Siew Clark - Ravelry
It is a one-piece, top-down, reversible, symmetrical, crescent shawl which you can make it bigger by using thicker yarn and bigger knitting ...
Read more >
How Shopping Habits Changed Due to COVID-19
Consumers shopping patterns have changed since the pandemic, with more emphasis on ... As shoppers grew accustomed to waiting in lines, online shopping...
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