-
-
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 createAsyncCallback in play function #508
Comments
Related to #133 |
I thinks this is not relative.. The logic is js controlled. So the pesudo plugin will not work it just work in css level |
Comparing to this snippet #359 (comment) const asyncCallback = createAsyncCallback();
// ...
finally {
asyncCallback();
} I think you need another call after it has been created in your code snippet |
ohhhh thx for your help. I will have a try tomorrow! |
@leobastiani thx bro, but I tried to call asyncCallback function like the snippet. I got this error, it seems the promise is not be solved properly.. |
I think the loki currently not support the await test function. It back to work after I remove this line |
@oblador Hello boss, could you please have I look 👀 |
I hope I give you a clue saying that I managed to make it work after applying this comment #359 (comment) I'm also using |
ohhh thx, I got the meaning. I'll have a try tommorow! |
Try to create and share here a demo repo reproducing this issue if you wish ❤️ |
That's my implementation, if it helps: import createAsyncCallback from '@loki/create-async-callback';
import isLokiRunning from '@loki/is-loki-running';
const waitForDocumentLoaded = () => {
if (document.readyState === 'loading') {
return new Promise<void>((resolve) => {
document.addEventListener('DOMContentLoaded', () => resolve());
});
}
return Promise.resolve();
};
const enablePointerEvents = () => {
const styleElement = document.createElement('style');
document.documentElement.appendChild(styleElement);
styleElement.sheet?.insertRule('* {pointer-events: auto !important}');
};
type Params = {
canvasElement: HTMLElement;
};
export const decoratePlayFunctionForLoki =
<T extends (params: Params) => Promise<void>>(target: T) =>
async (context: Params) => {
const lokiRunning = isLokiRunning();
const asyncCallback = createAsyncCallback();
if (lokiRunning) {
await waitForDocumentLoaded();
enablePointerEvents();
}
try {
await target(context);
} finally {
asyncCallback();
}
}; and use it like this in stories.tsx play: decoratePlayFunctionForLoki(async ({ canvasElement }) => {
const canvas = within(canvasElement);
const group = canvas.getByText('G');
await userEvent.hover(group);
}), |
Hello bros, thanks for creating this great repo.
I met a problem that I want to run the loki after the play function. To show the target tooltip.
I think it's nice if we support this function in play funciton.
the createAsyncCallback can only be called in component itself. It's a bit invasive method
The text was updated successfully, but these errors were encountered: