EasyUI Forum

General Category => EasyUI for React => Topic started by: chrwei on September 16, 2022, 09:35:39 AM



Title: Feature request: Messager async/await return
Post by: chrwei on September 16, 2022, 09:35:39 AM
I'm currently doing this to async/await Messager dialogs calls.  (this is in a functional component with useRef() )

Code:
let res = await new Promise(resolve => {
  messager.current.confirm({
    title: "Question",
    msg: "Do you like async/await?",
    buttons: [
      { text: "yes", value: true },
      { text: "no", value: false },
    ],
    result: r => {
      resolve(r);
    }
  });
});

Would it be possible to add an async/await pattern when the "result" callback isn't provided?  Examples for how that would be called:

Code:
let res = await messager.current.confirm({
  title: "Question",
  msg: "Do you like async/await?",
  buttons: [
    { text: "yes", value: true },
    { text: "no", value: false },
  ],
});

or

Code:
let answer = await messager.current.confirm({
  title: "Question",
  msg: "Do you like async/await?",
  buttons: [
    { text: "yes", value: true },
    { text: "no", value: false },
  ],
}).then(r=> {
  return r ? "I like it" : "I can do without"
});