-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
refactor: add async query for dom mutation scenario #1621
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
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 try to deprecate the concept of richText
. Therefore, I think asyncSetVRangeForVirgo
or asyncSetVRange
would be better.
See #1626
import type { ExtendedModel } from './types.js'; | ||
|
||
export function asyncSetVRange(model: BaseBlockModel, vRange: VRange) { | ||
asyncGetRichTextByModel(model) | ||
.then(richText => { |
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.
Can async/await
syntax be used here, I think the code format will be more uniform
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 didn't use the asyn function here is because I want to handle the promise error in the function and make sure when it is called, users won't need to handle it manually.
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 think it is equivalent to write like this:
async function asyncSetVRange(model: BaseBlockModel, vRange: VRange) {
try {
const richText = await asyncGetRichTextByModel(model)
richText?.vEditor?.setVRange(vRange);
} catch (e) {
throw e;
}
}
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.
This try/catch looks redundant.
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 think it is equivalent to write like this:
async function asyncSetVRange(model: BaseBlockModel, vRange: VRange) { try { const richText = await asyncGetRichTextByModel(model) richText?.vEditor?.setVRange(vRange); } catch (e) { throw e; } }
IMO they won't be equal. When you're using try catch in an async function, it will reject the error, and if the place where it called doesn't catch it, it will be a floating promise error. But, nevermind, it's not that important in this case.
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 work!
This PR adds async version of query functions to avoid the ambiguity
requestAnimationFrame
call when updating dom.