Is there a way to execute() only after save() resolves?
See original GitHub issueThis 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:
- Created 3 years ago
- Comments:8
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@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
snapshot- https://github.com/validated-changeset/validated-changeset/blob/e6823b089cf1edaf47fa2297aa9e372b225cbb70/src/index.ts#L553That 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
Changesetand 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!!
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
savefunction. I’d be open to an inherent solution to this library…https://github.com/poteto/ember-changeset#extending-the-base-ember-changeset-class