-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Support async CSF stories with createAsyncCallback #258
Conversation
@@ -34,6 +35,9 @@ storiesOf('Asynchronous render', module) | |||
.add('Logo with 1s delay', () => <Logo delay={1000} />) | |||
.lokiAsync('lokiAsync() with 1s delay', ({ done }) => ( | |||
<DelayedComponent delay={1000} onDone={done} /> | |||
)) | |||
.add('createAsyncCallback() with 1s delay', () => ( | |||
<DelayedComponent delay={1000} onDone={createAsyncCallback()} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this line mean that createAsyncCalkback
can be used with both Component Story Format (CSF) and storiesOf
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! 🚀
module.exports = function createAsyncCallback(win = window) { | ||
const registerPendingPromise = win.loki && win.loki.registerPendingPromise; | ||
let resolveAsyncStory; | ||
if (registerPendingPromise) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it throw an error when registerPendingPromise
is not available? 🤔
Don't really see this happening often but I still can imagine that some misconfiguration can lead to missing properties in the window object for example.
I guess such case calling createAsyncCallback
will return a function that returns undefined
and resolves nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a console warning in those cases now, don't think it warrants throwing an error. And yes you're right, I figured returning a no-op would be the best thing to do as components might expect this being sent in as props, so wanted to be as graceful as possible.
How can i use |
@pedrohmorais Just like normal, |
Usage
Fixes #254 and #195
Not sure if the name is the best, but struggling to find a better alternative.