Skip to content

WebAssemblyRuntime.InvokeJS get value from callback? #65

Closed

Description

@Ali-YousefiTelori

Hi,
How can I get callback result from Uno.Foundation.WebAssemblyRuntime.InvokeJS ?
for example like Promise in javascript etc...

Activity

  1. carldebilly commented on Jun 24, 2018

    @carldebilly
    Member

    You need to call back your code from js/ts. We're already doing that for the wasm http handler if you want an example.

    https://github.com/nventive/Uno/blob/master/src/Uno.UI.Wasm/ts/HttpClient.ts

  2. added
    question
    on Jun 26, 2018
  3. Ali-YousefiTelori commented on Jun 26, 2018

    @Ali-YousefiTelori
    Author

    Thank you, I don't know ts, but i make this example:
    C#

                var data = Uno.Foundation.WebAssemblyRuntime.InvokeJS("openFileDialog();");
                Console.WriteLine("result: " + data);

    and js:

    async function openFileDialog() {
        function resolveAfter2Seconds(x) {
            return new Promise(resolve => {
                setTimeout(() => {
                    resolve(x);
                }, 2000);
            });
        }
    
        var x = await resolveAfter2Seconds(10);
        return x;
    }
    

    this always show me result "result: [object Promise]" not real data.

  4. jeromelaban commented on Jun 26, 2018

    @jeromelaban
    Member

    Async functions are not supported by InvokeJS, which is synchronous. You need to call a C# method manually at the end like this.

  5. added
    platform/wasm 🌐
    on Oct 2, 2018
  6. self-assigned this
    on May 19, 2020
  7. carldebilly commented on May 19, 2020

    @carldebilly
    Member

    @Ali-YousefiTelori @MatFillion
    This feature has been merged into master and available as version 3.0.0-dev.25 on nuget.

  8. added a commit that references this issue on Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

platform/wasm 🌐question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions