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.

Is there a way to execute() only after save() resolves?

See original GitHub issue

This feels like a common use case so I’m wondering if this is already possible within this library.

I’d like it so that the underlying model is not changed until the Promise returned from save() resolves. Currently, the data will propagate right away throughout the template as soon as save() is executed even though the Promise is still in progress. This is a nitpick with user experience. For example, a modal is open and it’s waiting to be closed as soon as the Promise resolves but the data has already propagated to the model which creates a disconnect in the UX.

Any suggestions or workarounds?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
snewcomercommented, Apr 25, 2020

@axsuul You are right. This is a tough issue. I forgot we need to apply the underlying changes before saving the underlying content.

Note we do have

That might be of use to you. Although I’m not exactly sure how.

Cloning on our end would be tough because of the various end user shapes of objects.

I guess what I would suggest is you clone your model, pass the clone to Changeset and when the save promise is done, set the old model to the new model.

If you happen to come up with a solution we can integrate into the library, I’m all ears!!

0reactions
snewcomercommented, Sep 4, 2020

Given the request layer for any given object can be just a plain function that accepts a hash of data; or an ember-data model that relies on associated internal state of the model to make the request, it seems the only way to make this reliably work is to allow you to extend the Changeset and implement your own save function. I’d be open to an inherent solution to this library…

https://github.com/poteto/ember-changeset#extending-the-base-ember-changeset-class

Read more comments on GitHub >

github_iconTop Results From Across the Web

Execute function statement only after promise is resolved
You are doing something strange. getData should not return any value at all if you are using mobx. It should set store observable...
Read more >
Promises chaining - The Modern JavaScript Tutorial
text() : it returns a promise that resolves when the full text is downloaded from the remote server, with that text as a...
Read more >
How To Handle Async Data Loading, Lazy Loading, and Code ...
After the asynchronous function resolves, update an unordered list with the new information. Save and close the file. When you do the browser ......
Read more >
Best Practices for Spies, Stubs and Mocks in Sinon.js
Learn about differences between spies, stubs and mocks, when and how to use them, and get a set of best practices to help...
Read more >
Async and Await in JavaScript, the extension to a promise.
Here is an example with a promise that resolves in 2 seconds. ... When you do, the execution of the async function is...
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