Skip to content
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

example not works: WebUI not exported #7

Open
7flash opened this issue Aug 5, 2023 · 8 comments
Open

example not works: WebUI not exported #7

7flash opened this issue Aug 5, 2023 · 8 comments

Comments

@7flash
Copy link
Contributor

7flash commented Aug 5, 2023

  1. create main.ts
import { WebUI } from "https://deno.land/x/webui/mod.ts";

const myWindow = new WebUI();
myWindow .show("<html>Hello World</html>");
await WebUI.wait();
  1. run
deno run --allow-all main.ts
  1. shows an error
error: Uncaught SyntaxError: The requested module 'https://deno.land/x/webui/mod.ts' does not provide an export named 'WebUI'
import { WebUI } from "https://deno.land/x/webui/mod.ts";
@7flash
Copy link
Contributor Author

7flash commented Aug 6, 2023

Solution:

> git clone git@github.com:webui-dev/deno-webui.git
import { WebUI } from "./deno-webui/mod.ts";

const myWindow = new WebUI();
myWindow .show("<html>Hello World</html>");
await WebUI.wait();
deno run --unstable --allow-all main.ts

@AlbertShown
Copy link
Contributor

Thank you @7flash, That's right, in the meanwhile @JOTSR is working on this to be fixed in the main repo.

@JOTSR
Copy link
Contributor

JOTSR commented Aug 10, 2023

Since the current doc is tracking the next comming release there are breaking changes on the exports. For production use keep using the stable latest tag on deno.land. If you want to test the new comming features and API import directly from the main branch of the repo (pin a commit to reduce breaking changes).

@AlbertShown
Copy link
Contributor

The new stable version will be available soon after we voted to remove the webui.js from the source.

@7flash
Copy link
Contributor Author

7flash commented Aug 11, 2023

The new stable version will be available soon after we voted to remove the webui.js from the source.

Not sure what it means, but I have a relevant question,

Is it recommended to implement backend with bind/call between frontend in terms of performance or rather perhaps better spawn my own http server in same process?

@AlbertShown
Copy link
Contributor

Sorry, I meant that the current repo has an unfinished implementation. You can use the latest stable version here. Or clone the current branch, and apply the patch mentioned by @JOTSR.

About the HTTP Server, usually, webui will take care of it for you. You will receive events (clicks, calls) quickly. Many people have already used webui 2.0.3 in a production environment, and it's working fine, with no performance issues.

@7flash
Copy link
Contributor Author

7flash commented Aug 11, 2023

Sorry, I meant that the current repo has an unfinished implementation. You can use the latest stable version here. Or clone the current branch, and apply the patch mentioned by @JOTSR.

About the HTTP Server, usually, webui will take care of it for you. You will receive events (clicks, calls) quickly. Many people have already used webui 2.0.3 in a production environment, and it's working fine, with no performance issues.

Another issue, I'm not sure if it's supposed to support async handlers of events, and in that case I should open another issue with more detailed description, but what happens that it works with one or two invocations, and then throws a fatal error:

malloc(): unaligned fastbin chunk detected

I don't know if it can be easily fixed to support async handlers and in meantime I will have to stick with following approach, where I have to manually register callback on frontend, then call backend function which will run callback passing result.

// frontend
window.cb = (result) => {}
window.webui.call('first_function', {});

// backend
myWindow.bind('first_function', async event => {
  const result = await secondFunction();
  myWindow.run(`window.cb(${result})`);
})

@AlbertShown
Copy link
Contributor

Do you mean this is causes issues:

webui_fn('first_function').then((response) => {
     window.cb(response);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants