-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async morphism #106
Comments
@SamuelColacchia Thank you for using My first thought was to have an const customerSchema = {
firstname: "firstname",
lastname: "lastname",
email: "email",
group: {
path: "group",
fn: async value => {
const res = await callSomeService(value);
return res.data;
}
}
};
const result = await morphism.async(customerSchema, input)
// ==>
// {
// "firstname": "somefirstname",
// "lastname": "somelastname",
// "email": "[email protected]",
// "group": "somegroup"
// } Mostly to keep the backward compatibility on the synchronous interface and provide the appropriate typing with TypeScript. What do you think about this implementation ? |
@emyann That seems like it would be a good solution to the problem. Thinking it over in my head it would require the caller of morphism to explicitly want to wait for a async request, which I think is a good approach. |
@SamuelColacchia Awesome! Thank you for your feedback, I'm going to schedule this feature on the |
@emyann Sounds good to me. |
@emyann Hi, thanks for the library, it's nice and compact! How does the feature live? :) |
@kirsar Thank you for the feedback! I'm actively working on a big chunk of the library which is Working on that make me realize that I needed to support async validations also, so I'm ideating this async part of I'll likely come up by the end of this month with a design on how I envision this in |
Thanks for reply.
|
Is your feature request related to a problem? Please describe.
Morphism is unable to resolve promises in ActionFunction and ActionSelector and Type Promise is not allowed.
Describe the solution you'd like
Allow ActionFunction and ActionSelector to return a Promise that would later be resolvable by say a morphismasync method.
Example Schema
Describe alternatives you've considered
Alternative solutions would be to map the data available with one morphism call then make any async requests desired then remap the data returned from those async requests.
Another solution would be to add a helper function like so.
Additional context
Ideal implementation
Current result, with unresolved promise
Ideal result, with resolved promise
The text was updated successfully, but these errors were encountered: