-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Change dynamic field interfaces #74
Comments
Please let me know if this should be a separate issue, but with the proposed changes: could the factories (maybe optionally) become synchronous? Looking at one example, since there's nothing async involved in const AuthorFactory = defineAuthorFactory({
defaultFields: (({ seq }) => {
const name = 'mikamikomata';
return {
name,
email: `${name}@yuyushiki.net`,
};
}),
}); That might make it easier to reuse the factories in more places, e.g.: Storybook Stories where the |
@YellowKirby Thanks for your interest in this issue.
What does |
Sorry, I meant the |
OK. However, making the build method synchronous is outside the scope of this issue. In this issue, the build method is asynchronous. I understand the need for a synchronous build method in an environment where top-level await is not available. I have considered implementing that functionality in the past. But I gave up. I did not want to complicate the internal code. Therefore, I recommend migrating to an ESM that allows for top-level await. Recently many tools support it these days. Storybook also support it (storybookjs/storybook#15129). |
Okie dokie! That sounds reasonable, thank you! I think the top-level await will cover what I'm going for in Storybook, thanks for the link :) |
Motivation
get
function does not return a usable type.get('author')
isPromise<OptionalAuthor | undefined>
.OptionalAuthor
means{ id?: string | undefined, name?: string | undefined, email?: string | undefined }
.author
may beundefined
. This is inconvenient for the user.get
function is not very useful.get(...)
:get('name')
await
keyword beforeget(...)
:await get('name')
(await get('name')) ?? 'defaultName'
`${(await get('name')) ?? 'defaultName'}@yuyushiki.net`
dynamic
function:dynamic(async ({ get }) => `${(await get('name')) ?? 'defaultName'}@yuyushiki.net`)
Proposal
Change the interface as follows:
Case. 1: Use
seq
indefaultFields
and.build()
functionBefore
After
Case. 2: Use
get
for Dependent FieldsBefore
After
Case. 3: Use
get
for Transient Fields (depend: #73)Before
After
Breaking Changes
get
functiondynamic
utilityThe text was updated successfully, but these errors were encountered: