Skip to content

Create assemblyscript library #269

@scorsi

Description

@scorsi

Hey guys,

I'm looking to create a React-like framework for AssemblyScript. How could I import my project into another assemblyscript project (the user one) ?

I was thinking about creating my library then compile it to wasm and to use/import it with the loader, bridge all methods to the other.

Example:

if ('WebAssembly' in window) {
    fetch('MY_REACT_LIKE_LIBRARY.wasm')
        .then(response => response.arrayBuffer())
        .then(buffer => WebAssembly.instantiate(buffer, {
            // AUTOMATIC JAVASCRIPT IMPORT
        }))
        .then(reactLikeLibrary => {
            fetch('USER_AS_PROJECT.wasm')
                .then(response => response.arrayBuffer())
                .then(buffer => WebAssembly.instantiate(buffer, {
                    // AUTOMATIC IMPORT OF 'MY_REACT_LIKE_LIBRARY.wasm' LIBRARY
                    // + USER IMPORT
                }))
                .then(userProject => {
                    const instance = userProject.instance;
                    // CALL MAIN FUNCTION
                    instance.exports.main()
                })
                .catch(console.error);
        })
        .catch(console.error);
} else {
    alert("Your browser doesn't support Web Assembly. You may need " +
        "to enable it in your browser's flags.");
}

(Of couse, this code will be bundled with the library and be more like the assemblyscript loader)

Is there a clever solution for doing this ? Import directly the code from the user AS code (like npm package : without carring sources in the directory) ?

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions