Support createAsyncCallback in play function
PeterChen1997 opened this issue · comments
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.
![image](https://private-user-images.githubusercontent.com/21072589/316412654-2e7c1ad6-401f-4847-876c-1ab892951286.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTcwNzMzMDUsIm5iZiI6MTcxNzA3MzAwNSwicGF0aCI6Ii8yMTA3MjU4OS8zMTY0MTI2NTQtMmU3YzFhZDYtNDAxZi00ODQ3LTg3NmMtMWFiODkyOTUxMjg2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTMwVDEyNDMyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQwODZlZWJlOTY5N2FkZDgzMTE2M2QyY2MyNzEyZDVhZDAzZDY0ZDEzNGIwOWIzNDEwM2YyOWI5YTExZDgyYjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.9akBArWrP2E-bFQQdnJmPgCSHRB9EZo16Lrbmki2T9Y)
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
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)
I see a difference here
const asyncCallback = createAsyncCallback();
// ...
finally {
asyncCallback();
}
I think you need another call after it has been created in your code snippet
Comparing to this snippet #359 (comment) I see a difference here
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!
![image](https://private-user-images.githubusercontent.com/21072589/317109787-9c1e92c1-97a1-4cc4-91fc-e1bc1b1fce31.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTcwNzMzMDYsIm5iZiI6MTcxNzA3MzAwNiwicGF0aCI6Ii8yMTA3MjU4OS8zMTcxMDk3ODctOWMxZTkyYzEtOTdhMS00Y2M0LTkxZmMtZTFiYzFiMWZjZTMxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTMwVDEyNDMyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZjM2Y4OGU4MTJlYmQxMmIxYjJlNTc1Njk1MTljZDA2MDI3MjA2YjdjNDY0YjhlNzEwMjhiZWFjZDUxZGU3ZDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.JvaSeLPMAJZRz8mSAxEqgdMN9Ra76XWmoJOsYc43Dnc)
![image](https://private-user-images.githubusercontent.com/21072589/317109810-12b17c92-4871-490b-823d-c15e32ecae12.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTcwNzMzMDYsIm5iZiI6MTcxNzA3MzAwNiwicGF0aCI6Ii8yMTA3MjU4OS8zMTcxMDk4MTAtMTJiMTdjOTItNDg3MS00OTBiLTgyM2QtYzE1ZTMyZWNhZTEyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTMwVDEyNDMyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVkODFmYWIxMTgwYzJmZTI2ZTJiMWM5OTIxYmRiMWI5ZDkxZjdmNjVjMzA0NzMxZTU3YWViNGY1NmQ2MWY0YTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.FmWEkV_X15fiCXjKyTqGxO7mT1sJ8RdCAtzLMrMz6I0)
@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..
await userEvent.hover(group);
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 await canvas.findByText(...)
and await userEvent.hover(...)
like you are trying
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
await canvas.findByText(...)
andawait userEvent.hover(...)
like you are trying
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);
}),