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.

Possible to respond on a Promise?

See original GitHub issue

Hi,

I’m trying to dispatch a POST and once data is retrieved, then change the page to either a success or a failure page (has to be a different page and not just a toastr message that pops up)

The following, obviously, won’t work (in my form component):

this.props
        .dispatch('requestquote', this.state)
        .then(console.log('submit'));

How would I be able to tell if the POST was successful (or failed for any reason) and then continue to load a different route?

Or would you suggest abandoning the idea of a central store and just post within the component itself?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
aicommented, May 31, 2019

I still stink that you should move

function login() {
  let id = nanoid()
  setId(id)
  dispatch('login', { id, data ]))
}

let loginProcess = requests[id]
if (loginProcess === 'done') {
  redirect('/app)
}

to store module and not keeping it in a component.

In Storeon we splitting the app into “logic” and “UI”. It was a core idea of creating the Storeon (for instance, routing is a store module, not a component as in React Router).

If we want to split into “domain” and “local” logic, we will have completely different API (Effector is much closer to it).

1reaction
igorkamyshevcommented, May 29, 2019

Hello!

I have use-case for this issue.

I want do something in store (e.g. login user) and after it close login modal or redirect user to another page. This actions (modals, redirects) not “domain” actions. It is UI actions. But now, I must write many boilerplate code for this case.

Now:

let { requests, dispatch } = useStoreon('requests')
let { id, setId } = useState()
function login() {
  let id = nanoid()
  setId(id)
  dispatch('login', { id, data ]))
}

let loginProcess = requests[id]
if (loginProcess === 'done') {
  redirect('/app)
}

With returning Promise:

let { requests, dispatch } = useStoreon('requests')
function login() {
  dispatch('login', { data ]))
    .then(() => redirect('/app'))
}

Also, this API change reduce boilerplate in store definition.

@ai what do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What do you do when someone promises something ... - Quora
Ask them how long they have been doing what they do. Ask if they always let things go slack and not professionally dealt...
Read more >
reply to new on promises - by pall s. ardal - JSTOR
New is too generous to me in allowing that I could have concluded that "some promises are statements and others are not "....
Read more >
Here's How To Retract A Promise And Still Appear Professional
The first thing you need to do is figure out how this promise came to be. Go back through old emails or talk...
Read more >
8 Ways to Actually Deliver on Your Promises - Lifehack
5. Be communicative ... When you make your promise, be as concise as possible. If the description of your promise is vague, then...
Read more >
10 Ways to Say 'I Will Get Back to You as Soon as Possible'
I've passed this question to our team. They should have an answer by , but I'll be sure to update you as soon...
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